359
360
public acceptChunk(data: VSBuffer | null): void {
361
>
if (!data || data.byteLength === 0) {
ipc.net.ts
362
return;
363
}
365
>
this.lastReadTime = Date.now();
366
>
367
>
this._incomingData.acceptChunk(data);
368
>
369
>
while (this._incomingData.byteLength >= this._state.readLen) {
370
>
371
>
const buff = this._incomingData.read(this._state.readLen);
372
>
373
>
if (this._state.readHead) {
374
>
// buff is the header
375
>
376
>
// save new state => next time will read the body
377
>
this._state.readHead = false;
378
>
this._state.readLen = buff.readUInt32BE(9);
379
>
this._state.messageType = buff.readUInt8(0);
380
>
this._state.id = buff.readUInt32BE(1);
381
>
this._state.ack = buff.readUInt32BE(5);
382
>
383
>
this._socket.traceSocketEvent(SocketDiagnosticsEventType.ProtocolHeaderRead, { messageType: protocolMessageTypeToString(this._state.messageType), id: this._state.id, ack: this._state.ack, messageSize: this._state.readLen });
384
>
385
>
} else {
386
>
// buff is the body
387
>
const messageType = this._state.messageType;
388
>
const id = this._state.id;
389
>
const ack = this._state.ack;
390
>
391
>
// save new state => next time will read the header
392
>
this._state.readHead = true;
393
>
this._state.readLen = ProtocolConstants.HeaderLength;
394
>
this._state.messageType = ProtocolMessageType.None;
395
>
this._state.id = 0;
396
>
this._state.ack = 0;
397
>
398
>
this._socket.traceSocketEvent(SocketDiagnosticsEventType.ProtocolMessageRead, buff);
399
>
400
>
this._onMessage.fire(new ProtocolMessage(messageType, id, ack, buff));
401
>
402
>
if (this._isDisposed) {
403
// check if an event listener lead to our disposal
404
break;
405
}
407
>
}
408
>
}
409
410
public readEntireBuffer(): VSBuffer {