ipc.net.ts ×45

Frontier kind: Code frontier

unlabeled · c_e0982cfdec8f

7 tests · 10281 LOC · 54 files · introduces 0 tests · 145 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
45 ranges145 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1502 ranges10281 lines · 54 files · Browse complete extent
All tests (intent)
7 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 145 introduced LOC across 45 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/base/parts/ipc/common/ipc.net.ts 145 introduced LOC · 45 ranges

Open complete file

624
625 constructor() {
626 > this._emitter = new Emitter<T>({ ipc.net.ts
627 > onWillAddFirstListener: () => {
628 > this._hasListeners = true;
629 > // it is important to deliver these messages after this call, but before
630 > // other messages have a chance to be received (to guarantee in order delivery)
631 > // that's why we're using here queueMicrotask and not other types of timeouts
632 > queueMicrotask(() => this._deliverMessages());
633 > },
634 > onDidRemoveLastListener: () => {
635 > this._hasListeners = false;
636 > }
637 > });
638 >
639 > this.event = this._emitter.event;
640 > }
641
642 private _deliverMessages(): void {
643 > if (this._isDeliveringMessages) { ipc.net.ts
644 return;
645 }
646 > this._isDeliveringMessages = true; ipc.net.ts
647 > while (this._hasListeners && this._bufferedMessages.length > 0) {
648 this._emitter.fire(this._bufferedMessages.shift()!);
649 }
650 > this._isDeliveringMessages = false; ipc.net.ts
651 > }
652
653 public fire(event: T): void {
654 > if (this._hasListeners) { ipc.net.ts
655 > if (this._bufferedMessages.length > 0) {
656 this._bufferedMessages.push(event);
657 > } else { ipc.net.ts
658 > this._emitter.fire(event);
659 > }
660 > } else {
661 this._bufferedMessages.push(event);
662 }
663 > } ipc.net.ts
664
665 public flushBuffer(): void {
673
674 constructor(data: T) {
675 > this.data = data; ipc.net.ts
676 > this.next = null;
677 > }
678 }
679
684
685 constructor() {
686 > this._first = null; ipc.net.ts
687 > this._last = null;
688 > }
689
690 public length(): number {
699
700 public peek(): T | null {
701 > if (!this._first) { ipc.net.ts
702 return null;
703 }
704 > return this._first.data; ipc.net.ts
705 > }
706
707 public toArray(): T[] {
729
730 public push(item: T): void {
731 > const element = new QueueElement(item); ipc.net.ts
732 > if (!this._first) {
733 > this._first = element;
734 > this._last = element;
735 > return;
736 > }
737 this._last!.next = element;
738 this._last = element;
739 > } ipc.net.ts
740 }
741
863
864 constructor(opts: PersistentProtocolOptions) {
865 > this._loadEstimator = opts.loadEstimator ?? LoadEstimator.getInstance(); ipc.net.ts
866 > this._shouldSendKeepAlive = opts.sendKeepAlive ?? true;
867 > this._isReconnecting = false;
868 > this._outgoingUnackMsg = new Queue<ProtocolMessage>();
869 > this._outgoingMsgId = 0;
870 > this._outgoingAckId = 0;
871 > this._outgoingAckTimeout = null;
872 >
873 > this._incomingMsgId = 0;
874 > this._incomingAckId = 0;
875 > this._incomingMsgLastTime = 0;
876 > this._incomingAckTimeout = null;
877 >
878 > this._lastReplayRequestTime = 0;
879 > this._lastSocketTimeoutTime = Date.now();
880 >
881 > this._socketDisposables = new DisposableStore();
882 > this._socket = opts.socket;
883 > this._socketWriter = this._socketDisposables.add(new ProtocolWriter(this._socket));
884 > this._socketReader = this._socketDisposables.add(new ProtocolReader(this._socket));
885 > this._socketDisposables.add(this._socketReader.onMessage(msg => this._receiveMessage(msg)));
886 > this._socketDisposables.add(this._socket.onClose(e => this._onSocketClose.fire(e)));
887 >
888 > if (opts.initialChunk) {
889 this._socketReader.acceptChunk(opts.initialChunk);
890 }
891 > ipc.net.ts
892 > if (this._shouldSendKeepAlive) {
893 this._keepAliveInterval = setInterval(() => {
894 this._sendKeepAlive();
895 }, ProtocolConstants.KeepAliveSendTime);
896 > } else { ipc.net.ts
897 this._keepAliveInterval = null;
898 }
899 > } ipc.net.ts
900
901 dispose(): void {
902 > if (this._outgoingAckTimeout) { ipc.net.ts
903 clearTimeout(this._outgoingAckTimeout);
904 this._outgoingAckTimeout = null;
905 }
906 > if (this._incomingAckTimeout) { ipc.net.ts
907 clearTimeout(this._incomingAckTimeout);
908 this._incomingAckTimeout = null;
909 }
910 > if (this._keepAliveInterval) { ipc.net.ts
911 clearInterval(this._keepAliveInterval);
912 this._keepAliveInterval = null;
913 }
914 > this._socketDisposables.dispose(); ipc.net.ts
915 > }
916
917 drain(): Promise<void> {
994
995 private _receiveMessage(msg: ProtocolMessage): void {
996 > if (msg.ack > this._outgoingAckId) { ipc.net.ts
997 this._outgoingAckId = msg.ack;
998 do {
1006 } while (true);
1007 }
1008 > ipc.net.ts
1009 > switch (msg.type) {
1010 > case ProtocolMessageType.None: {
1011 // N/A
1012 break;
1013 }
1014 > case ProtocolMessageType.Regular: { ipc.net.ts
1015 > if (msg.id > this._incomingMsgId) {
1016 > if (msg.id !== this._incomingMsgId + 1) {
1017 // in case we missed some messages we ask the other party to resend them
1018 const now = Date.now();
1022 this._socketWriter.write(new ProtocolMessage(ProtocolMessageType.ReplayRequest, 0, 0, getEmptyBuffer()));
1023 }
1024 > } else { ipc.net.ts
1025 > this._incomingMsgId = msg.id;
1026 > this._incomingMsgLastTime = Date.now();
1027 > this._sendAckCheck();
1028 > this._onMessage.fire(msg.data);
1029 > }
1030 > }
1031 > break;
1032 > }
1033 > case ProtocolMessageType.Control: {
1034 this._onControlMessage.fire(msg.data);
1035 break;
1036 }
1037 > case ProtocolMessageType.Ack: { ipc.net.ts
1038 // nothing to do, .ack is handled above already
1039 break;
1040 }
1041 > case ProtocolMessageType.Disconnect: { ipc.net.ts
1042 this._onDidDispose.fire();
1043 break;
1044 }
1045 > case ProtocolMessageType.ReplayRequest: { ipc.net.ts
1046 // Send again all unacknowledged messages
1047 const toSend = this._outgoingUnackMsg.toArray();
1052 break;
1053 }
1054 > case ProtocolMessageType.Pause: { ipc.net.ts
1055 this._socketWriter.pause();
1056 break;
1057 }
1058 > case ProtocolMessageType.Resume: { ipc.net.ts
1059 this._socketWriter.resume();
1060 break;
1061 }
1062 > case ProtocolMessageType.KeepAlive: { ipc.net.ts
1063 // nothing to do
1064 break;
1065 }
1066 > } ipc.net.ts
1067 > }
1068
1069 readEntireBuffer(): VSBuffer {
1076
1077 send(buffer: VSBuffer): void {
1078 > const myId = ++this._outgoingMsgId; ipc.net.ts
1079 > this._incomingAckId = this._incomingMsgId;
1080 > const msg = new ProtocolMessage(ProtocolMessageType.Regular, myId, this._incomingAckId, buffer);
1081 > this._outgoingUnackMsg.push(msg);
1082 > if (!this._isReconnecting) {
1083 > this._socketWriter.write(msg);
1084 > this._recvAckCheck();
1085 > }
1086 > }
1087
1088 /**
1096
1097 private _sendAckCheck(): void {
1098 > if (this._incomingMsgId <= this._incomingAckId) { ipc.net.ts
1099 // nothink to acknowledge
1100 return;
1101 }
1102 > ipc.net.ts
1103 > if (this._incomingAckTimeout) {
1104 // there will be a check in the near future
1105 return;
1106 }
1107 > ipc.net.ts
1108 > const timeSinceLastIncomingMsg = Date.now() - this._incomingMsgLastTime;
1109 > if (timeSinceLastIncomingMsg >= ProtocolConstants.AcknowledgeTime) {
1110 // sufficient time has passed since this message has been received,
1111 // and no message from our side needed to be sent in the meantime,
1114 return;
1115 }
1116 > ipc.net.ts
1117 > this._incomingAckTimeout = setTimeout(() => {
1118 this._incomingAckTimeout = null;
1119 this._sendAckCheck();
1120 > }, ProtocolConstants.AcknowledgeTime - timeSinceLastIncomingMsg + 5); ipc.net.ts
1121 > }
1122
1123 private _recvAckCheck(): void {
1124 > if (this._outgoingMsgId <= this._outgoingAckId) { ipc.net.ts
1125 // everything has been acknowledged
1126 return;
1127 }
1128 > ipc.net.ts
1129 > if (this._outgoingAckTimeout) {
1130 // there will be a check in the near future
1131 return;
1132 }
1133 > ipc.net.ts
1134 > if (this._isReconnecting) {
1135 // do not cause a timeout during reconnection,
1136 // because messages will not be actually written until `endAcceptReconnection`
1137 return;
1138 }
1139 > ipc.net.ts
1140 > const oldestUnacknowledgedMsg = this._outgoingUnackMsg.peek()!;
1141 > const timeSinceOldestUnacknowledgedMsg = Date.now() - oldestUnacknowledgedMsg.writtenTime;
1142 > const timeSinceLastReceivedSomeData = Date.now() - this._socketReader.lastReadTime;
1143 > const timeSinceLastTimeout = Date.now() - this._lastSocketTimeoutTime;
1144 >
1145 > if (
1146 > timeSinceOldestUnacknowledgedMsg >= ProtocolConstants.TimeoutTime
1147 && timeSinceLastReceivedSomeData >= ProtocolConstants.TimeoutTime
1148 && timeSinceLastTimeout >= ProtocolConstants.TimeoutTime
1149 > ) { ipc.net.ts
1150 // It's been a long time since our sent message was acknowledged
1151 // and a long time since we received some data
1164 }
1165 }
1166 > ipc.net.ts
1167 > const minimumTimeUntilTimeout = Math.max(
1168 > ProtocolConstants.TimeoutTime - timeSinceOldestUnacknowledgedMsg,
1169 > ProtocolConstants.TimeoutTime - timeSinceLastReceivedSomeData,
1170 > ProtocolConstants.TimeoutTime - timeSinceLastTimeout,
1171 > 500
1172 > );
1173 >
1174 > this._outgoingAckTimeout = setTimeout(() => {
1175 this._outgoingAckTimeout = null;
1176 this._recvAckCheck();
1177 > }, minimumTimeUntilTimeout); ipc.net.ts
1178 > }
1179
1180 /**