Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _send_chunk(requestId: number, chunk: Buffer | null) {
const requestData = this._requests[requestId];
if (chunk) {
/**
* notify the observer that a message chunk is about to be sent to the server
* @event send_chunk
* @param message_chunk {Object} the message chunk
*/
this.emit("send_chunk", chunk);
/* istanbul ignore next */
if (doDebug && checkChunks) {
verify_message_chunk(chunk);
debugLog(chalk.yellow("CLIENT SEND chunk "));
debugLog(chalk.yellow(messageHeaderToString(chunk)));
debugLog(chalk.red(hexDump(chunk)));
}
assert(this._transport);
this._transport.write(chunk);
requestData.chunk_count += 1;
} else {
// last chunk ....
/* istanbul ignore next */
if (doDebug && checkChunks) {
debugLog(chalk.yellow("CLIENT SEND done."));
}
if (requestData) {
const self = this;
const request_data = self._request_data[requestId];
if (messageChunk) {
/**
* notify the observer that a message chunk is about to be sent to the server
* @event send_chunk
* @param message_chunk {Object} the message chunk
*/
self.emit("send_chunk", messageChunk);
/* istanbul ignore next */
if (doDebug && false) {
verify_message_chunk(messageChunk);
debugLog("CLIENT SEND chunk ".yellow);
debugLog(messageHeaderToString(messageChunk).yellow);
debugLog(hexDump(messageChunk).red);
}
assert(self._transport);
self._transport.write(messageChunk);
request_data.chunk_count += 1;
} else {
// last chunk ....
/* istanbul ignore next */
if (doDebug) {
debugLog("CLIENT SEND done.".yellow.bold);
}
if (request_data) {
maxChunkCount: self.maxChunkCount
});
//xx acknowledgeMessage.receiveBufferSize = 8192;
//xx acknowledgeMessage.sendBufferSize = 8192;
//xx console.log("xxx receiveBufferSize = ",acknowledgeMessage.receiveBufferSize , helloMessage.receiveBufferSize) ;
//xx console.log("xxx sendBufferSize = ",acknowledgeMessage.sendBufferSize , helloMessage.sendBufferSize);
//xx console.log("xxx maxMessageSize = ",acknowledgeMessage.maxMessageSize , helloMessage.maxMessageSize);
//xx console.log("xxx maxChunkCount = ",acknowledgeMessage.maxChunkCount , helloMessage.maxChunkCount);
const messageChunk = packTcpMessage("ACK", acknowledgeMessage);
/* istanbul ignore next*/
if (doDebug) {
verify_message_chunk(messageChunk);
debugLog("server send: " + "ACK".yellow);
debugLog("server send: " + hexDump(messageChunk));
debugLog("acknowledgeMessage=", acknowledgeMessage);
}
// send the ACK reply
self.write(messageChunk);
};
this.sendBufferSize = clamp_value(helloMessage.sendBufferSize, 8192, 512 * 1024);
this.maxMessageSize = clamp_value(helloMessage.maxMessageSize, 100000, 16 * 1024 * 1024);
this.maxChunkCount = clamp_value(helloMessage.maxChunkCount, 0, 65535);
const acknowledgeMessage = new AcknowledgeMessage({
maxChunkCount: this.maxChunkCount,
maxMessageSize: this.maxMessageSize,
protocolVersion: this.protocolVersion,
receiveBufferSize: this.receiveBufferSize,
sendBufferSize: this.sendBufferSize
});
const messageChunk = packTcpMessage("ACK", acknowledgeMessage);
/* istanbul ignore next*/
if (doDebug) {
verify_message_chunk(messageChunk);
debugLog("server send: " + chalk.yellow("ACK"));
debugLog("server send: " + hexDump(messageChunk));
debugLog("acknowledgeMessage=", acknowledgeMessage);
}
// send the ACK reply
this.write(messageChunk);
}