node-opcua-transport
Advanced tools
Comparing version 2.0.0-alpha.6 to 2.0.0-alpha.7
@@ -43,3 +43,2 @@ /// <reference types="node" /> | ||
createChunk(msgType: string, chunkType: string, length: number): Buffer; | ||
protected _write_chunk(messageChunk: Buffer): void; | ||
/** | ||
@@ -56,13 +55,14 @@ * write the message_chunk on the socket. | ||
write(messageChunk: Buffer): void; | ||
private _fulfill_pending_promises; | ||
private _on_message_received; | ||
private _cleanup_timers; | ||
private _start_one_time_message_receiver; | ||
private on_socket_closed; | ||
/** | ||
* disconnect the TCP layer and close the underlying socket. | ||
* The ```"close"``` event will be emitted to the observers with err=null. | ||
* | ||
* @method disconnect | ||
* @async | ||
* @param callback | ||
*/ | ||
disconnect(callback: ErrorCallback): void; | ||
isValid(): boolean; | ||
protected _write_chunk(messageChunk: Buffer): void; | ||
protected on_socket_ended(err: Error | null): void; | ||
private _on_socket_data; | ||
private _on_socket_close; | ||
private _on_socket_ended_message; | ||
private _on_socket_end; | ||
private _on_socket_error; | ||
/** | ||
@@ -88,13 +88,13 @@ * @method _install_socket | ||
protected _install_one_time_message_receiver(callback: CallbackWithData): void; | ||
/** | ||
* disconnect the TCP layer and close the underlying socket. | ||
* The ```"close"``` event will be emitted to the observers with err=null. | ||
* | ||
* @method disconnect | ||
* @async | ||
* @param callback | ||
*/ | ||
disconnect(callback: ErrorCallback): void; | ||
isValid(): boolean; | ||
private _fulfill_pending_promises; | ||
private _on_message_received; | ||
private _cleanup_timers; | ||
private _start_one_time_message_receiver; | ||
private on_socket_closed; | ||
private _on_socket_data; | ||
private _on_socket_close; | ||
private _on_socket_ended_message; | ||
private _on_socket_end; | ||
private _on_socket_error; | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chalk_1 = require("chalk"); | ||
const events_1 = require("events"); | ||
const _ = require("underscore"); | ||
const chalk_1 = require("chalk"); | ||
const node_opcua_assert_1 = require("node-opcua-assert"); | ||
const node_opcua_buffer_utils_1 = require("node-opcua-buffer-utils"); | ||
const debug = require("node-opcua-debug"); | ||
const node_opcua_packet_assembler_1 = require("node-opcua-packet-assembler"); | ||
const debug = require("node-opcua-debug"); | ||
const message_builder_base_1 = require("./message_builder_base"); | ||
@@ -89,9 +89,2 @@ const tools_1 = require("./tools"); | ||
} | ||
_write_chunk(messageChunk) { | ||
if (this._socket !== null) { | ||
this.bytesWritten += messageChunk.length; | ||
this.chunkWrittenCount++; | ||
this._socket.write(messageChunk); | ||
} | ||
} | ||
/** | ||
@@ -108,3 +101,4 @@ * write the message_chunk on the socket. | ||
write(messageChunk) { | ||
node_opcua_assert_1.assert((this._pendingBuffer === undefined) || this._pendingBuffer === messageChunk, " write should be used with buffer created by createChunk"); | ||
node_opcua_assert_1.assert((this._pendingBuffer === undefined) | ||
|| this._pendingBuffer === messageChunk, " write should be used with buffer created by createChunk"); | ||
const header = message_builder_base_1.readRawMessageHeader(messageChunk); | ||
@@ -116,2 +110,111 @@ node_opcua_assert_1.assert(header.length === messageChunk.length); | ||
} | ||
/** | ||
* disconnect the TCP layer and close the underlying socket. | ||
* The ```"close"``` event will be emitted to the observers with err=null. | ||
* | ||
* @method disconnect | ||
* @async | ||
* @param callback | ||
*/ | ||
disconnect(callback) { | ||
node_opcua_assert_1.assert(_.isFunction(callback), "expecting a callback function, but got " + callback); | ||
if (this._disconnecting) { | ||
callback(); | ||
return; | ||
} | ||
node_opcua_assert_1.assert(!this._disconnecting, "TCP Transport has already been disconnected"); | ||
this._disconnecting = true; | ||
// xx assert(!this._theCallback, | ||
// "disconnect shall not be called while the 'one time message receiver' is in operation"); | ||
this._cleanup_timers(); | ||
if (this._socket) { | ||
this._socket.end(); | ||
this._socket.destroy(); | ||
// xx this._socket.removeAllListeners(); | ||
this._socket = null; | ||
} | ||
setImmediate(() => { | ||
this.on_socket_ended(null); | ||
callback(); | ||
}); | ||
} | ||
isValid() { | ||
return this._socket !== null && !this._socket.destroyed && !this._disconnecting; | ||
} | ||
_write_chunk(messageChunk) { | ||
if (this._socket !== null) { | ||
this.bytesWritten += messageChunk.length; | ||
this.chunkWrittenCount++; | ||
this._socket.write(messageChunk); | ||
} | ||
} | ||
on_socket_ended(err) { | ||
node_opcua_assert_1.assert(!this._onSocketEndedHasBeenCalled); | ||
this._onSocketEndedHasBeenCalled = true; // we don't want to send close event twice ... | ||
/** | ||
* notify the observers that the transport layer has been disconnected. | ||
* @event close | ||
* @param err the Error object or null | ||
*/ | ||
this.emit("close", err || null); | ||
} | ||
/** | ||
* @method _install_socket | ||
* @param socket {Socket} | ||
* @protected | ||
*/ | ||
_install_socket(socket) { | ||
node_opcua_assert_1.assert(socket); | ||
this._socket = socket; | ||
if (doDebug) { | ||
debugLog("_install_socket ", this.name); | ||
} | ||
// install packet assembler ... | ||
this.packetAssembler = new node_opcua_packet_assembler_1.PacketAssembler({ | ||
readMessageFunc: message_builder_base_1.readRawMessageHeader, | ||
minimumSizeInBytes: this.headerSize | ||
}); | ||
if (!this.packetAssembler) { | ||
throw new Error("Internal Error"); | ||
} | ||
this.packetAssembler.on("message", (messageChunk) => this._on_message_received(messageChunk)); | ||
this._socket | ||
.on("data", (data) => this._on_socket_data(data)) | ||
.on("close", (hadError) => this._on_socket_close(hadError)) | ||
.on("end", (err) => this._on_socket_end(err)) | ||
.on("error", (err) => this._on_socket_error(err)); | ||
const doDestroyOnTimeout = false; | ||
if (doDestroyOnTimeout) { | ||
// set socket timeout | ||
debugLog("setting _socket.setTimeout to ", this.timeout); | ||
this._socket.setTimeout(this.timeout, () => { | ||
console.log(` _socket ${this.name} has timed out (timeout = ${this.timeout})`); | ||
if (this._socket) { | ||
this._socket.destroy(); | ||
// 08/2008 shall we do this ? | ||
this._socket.removeAllListeners(); | ||
this._socket = null; | ||
} | ||
}); | ||
} | ||
} | ||
/** | ||
* @method _install_one_time_message_receiver | ||
* | ||
* install a one time message receiver callback | ||
* | ||
* Rules: | ||
* * TCP_transport will not emit the ```message``` event, while the "one time message receiver" is in operation. | ||
* * the TCP_transport will wait for the next complete message chunk and call the provided callback func | ||
* ```callback(null,messageChunk);``` | ||
* * if a messageChunk is not received within ```TCP_transport.timeout``` or if the underlying socket reports an error, | ||
* the callback function will be called with an Error. | ||
* | ||
*/ | ||
_install_one_time_message_receiver(callback) { | ||
node_opcua_assert_1.assert(!this._theCallback, "callback already set"); | ||
node_opcua_assert_1.assert(_.isFunction(callback)); | ||
this._theCallback = callback; | ||
this._start_one_time_message_receiver(); | ||
} | ||
_fulfill_pending_promises(err, data) { | ||
@@ -178,15 +281,6 @@ this._cleanup_timers(); | ||
} | ||
on_socket_ended(err) { | ||
node_opcua_assert_1.assert(!this._onSocketEndedHasBeenCalled); | ||
this._onSocketEndedHasBeenCalled = true; // we don't want to send close event twice ... | ||
/** | ||
* notify the observers that the transport layer has been disconnected. | ||
* @event close | ||
* @param err the Error object or null | ||
*/ | ||
this.emit("close", err || null); | ||
} | ||
_on_socket_data(data) { | ||
if (!this.packetAssembler) | ||
if (!this.packetAssembler) { | ||
throw new Error("internal Error"); | ||
} | ||
this.bytesRead += data.length; | ||
@@ -240,93 +334,4 @@ if (data.length > 0) { | ||
} | ||
/** | ||
* @method _install_socket | ||
* @param socket {Socket} | ||
* @protected | ||
*/ | ||
_install_socket(socket) { | ||
node_opcua_assert_1.assert(socket); | ||
this._socket = socket; | ||
if (doDebug) | ||
debugLog("_install_socket ", this.name); | ||
// install packet assembler ... | ||
this.packetAssembler = new node_opcua_packet_assembler_1.PacketAssembler({ | ||
readMessageFunc: message_builder_base_1.readRawMessageHeader, | ||
minimumSizeInBytes: this.headerSize | ||
}); | ||
if (!this.packetAssembler) | ||
throw new Error("Internal Error"); | ||
this.packetAssembler.on("message", (messageChunk) => this._on_message_received(messageChunk)); | ||
this._socket | ||
.on("data", (data) => this._on_socket_data(data)) | ||
.on("close", (hadError) => this._on_socket_close(hadError)) | ||
.on("end", (err) => this._on_socket_end(err)) | ||
.on("error", (err) => this._on_socket_error(err)); | ||
const doDestroyOnTimeout = false; | ||
if (doDestroyOnTimeout) { | ||
// set socket timeout | ||
debugLog("setting _socket.setTimeout to ", this.timeout); | ||
this._socket.setTimeout(this.timeout, () => { | ||
console.log(` _socket ${this.name} has timed out (timeout = ${this.timeout})`); | ||
if (this._socket) { | ||
this._socket.destroy(); | ||
// 08/2008 shall we do this ? | ||
this._socket.removeAllListeners(); | ||
this._socket = null; | ||
} | ||
}); | ||
} | ||
} | ||
/** | ||
* @method _install_one_time_message_receiver | ||
* | ||
* install a one time message receiver callback | ||
* | ||
* Rules: | ||
* * TCP_transport will not emit the ```message``` event, while the "one time message receiver" is in operation. | ||
* * the TCP_transport will wait for the next complete message chunk and call the provided callback func | ||
* ```callback(null,messageChunk);``` | ||
* * if a messageChunk is not received within ```TCP_transport.timeout``` or if the underlying socket reports an error, | ||
* the callback function will be called with an Error. | ||
* | ||
*/ | ||
_install_one_time_message_receiver(callback) { | ||
node_opcua_assert_1.assert(!this._theCallback, "callback already set"); | ||
node_opcua_assert_1.assert(_.isFunction(callback)); | ||
this._theCallback = callback; | ||
this._start_one_time_message_receiver(); | ||
} | ||
/** | ||
* disconnect the TCP layer and close the underlying socket. | ||
* The ```"close"``` event will be emitted to the observers with err=null. | ||
* | ||
* @method disconnect | ||
* @async | ||
* @param callback | ||
*/ | ||
disconnect(callback) { | ||
node_opcua_assert_1.assert(_.isFunction(callback), "expecting a callback function, but got " + callback); | ||
if (this._disconnecting) { | ||
callback(); | ||
return; | ||
} | ||
node_opcua_assert_1.assert(!this._disconnecting, "TCP Transport has already been disconnected"); | ||
this._disconnecting = true; | ||
// xx assert(!this._theCallback, "disconnect shall not be called while the 'one time message receiver' is in operation"); | ||
this._cleanup_timers(); | ||
if (this._socket) { | ||
this._socket.end(); | ||
this._socket.destroy(); | ||
// xx this._socket.removeAllListeners(); | ||
this._socket = null; | ||
} | ||
setImmediate(() => { | ||
this.on_socket_ended(null); | ||
callback(); | ||
}); | ||
} | ||
isValid() { | ||
return this._socket !== null && !this._socket.destroyed && !this._disconnecting; | ||
} | ||
} | ||
exports.TCP_transport = TCP_transport; | ||
//# sourceMappingURL=tcp_transport.js.map |
{ | ||
"name": "node-opcua-transport", | ||
"version": "2.0.0-alpha.6", | ||
"version": "2.0.0-alpha.7", | ||
"description": "pure nodejs OPCUA SDK - module -transport", | ||
@@ -14,24 +14,24 @@ "main": "./dist/source/index.js", | ||
"chalk": "^2.4.1", | ||
"node-opcua-assert": "^2.0.0-alpha.6", | ||
"node-opcua-basic-types": "^2.0.0-alpha.6", | ||
"node-opcua-binary-stream": "^2.0.0-alpha.6", | ||
"node-opcua-buffer-utils": "^2.0.0-alpha.6", | ||
"node-opcua-chunkmanager": "^2.0.0-alpha.6", | ||
"node-opcua-debug": "^2.0.0-alpha.6", | ||
"node-opcua-factory": "^2.0.0-alpha.6", | ||
"node-opcua-nodeid": "^2.0.0-alpha.6", | ||
"node-opcua-packet-assembler": "^2.0.0-alpha.6", | ||
"node-opcua-status-code": "^2.0.0-alpha.6", | ||
"node-opcua-types": "^2.0.0-alpha.6", | ||
"node-opcua-utils": "^2.0.0-alpha.6", | ||
"node-opcua-assert": "^2.0.0-alpha.7", | ||
"node-opcua-basic-types": "^2.0.0-alpha.7", | ||
"node-opcua-binary-stream": "^2.0.0-alpha.7", | ||
"node-opcua-buffer-utils": "^2.0.0-alpha.7", | ||
"node-opcua-chunkmanager": "^2.0.0-alpha.7", | ||
"node-opcua-debug": "^2.0.0-alpha.7", | ||
"node-opcua-factory": "^2.0.0-alpha.7", | ||
"node-opcua-nodeid": "^2.0.0-alpha.7", | ||
"node-opcua-packet-assembler": "^2.0.0-alpha.7", | ||
"node-opcua-status-code": "^2.0.0-alpha.7", | ||
"node-opcua-types": "^2.0.0-alpha.7", | ||
"node-opcua-utils": "^2.0.0-alpha.7", | ||
"underscore": "^1.9.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^10.12.0", | ||
"@types/node": "^10.12.12", | ||
"@types/underscore": "^1.8.9", | ||
"colors": "^1.3.2", | ||
"node-opcua-debug": "^2.0.0-alpha.5", | ||
"node-opcua-generator": "^2.0.0-alpha.6", | ||
"node-opcua-generator": "^2.0.0-alpha.7", | ||
"should": "13.2.3", | ||
"sinon": "^7.0.0" | ||
"sinon": "^7.1.1" | ||
}, | ||
@@ -53,3 +53,3 @@ "author": "Etienne Rossignon", | ||
"homepage": "http://node-opcua.github.io/", | ||
"gitHead": "12f2b33c00f146e37797ef9ab2631e868b072bc0" | ||
"gitHead": "af4f00cca7a45563e759c88afa21bba73152dd03" | ||
} |
@@ -0,10 +1,10 @@ | ||
import { default as chalk } from "chalk"; | ||
import { EventEmitter } from "events"; | ||
import { Socket } from "net"; | ||
import * as _ from "underscore"; | ||
import { Socket } from "net"; | ||
import { default as chalk } from "chalk"; | ||
import { assert } from "node-opcua-assert"; | ||
import { createFastUninitializedBuffer } from "node-opcua-buffer-utils"; | ||
import * as debug from "node-opcua-debug"; | ||
import { PacketAssembler } from "node-opcua-packet-assembler"; | ||
import * as debug from "node-opcua-debug"; | ||
@@ -97,3 +97,3 @@ import { readRawMessageHeader } from "./message_builder_base"; | ||
dispose() { | ||
public dispose() { | ||
assert(!this._timerId); | ||
@@ -121,3 +121,3 @@ if (this._socket) { | ||
*/ | ||
createChunk(msgType: string, chunkType: string, length: number): Buffer { | ||
public createChunk(msgType: string, chunkType: string, length: number): Buffer { | ||
@@ -136,10 +136,2 @@ assert(msgType === "MSG"); | ||
protected _write_chunk(messageChunk: Buffer) { | ||
if (this._socket !== null) { | ||
this.bytesWritten += messageChunk.length; | ||
this.chunkWrittenCount++; | ||
this._socket.write(messageChunk); | ||
} | ||
} | ||
/** | ||
@@ -155,5 +147,6 @@ * write the message_chunk on the socket. | ||
*/ | ||
write(messageChunk: Buffer) { | ||
public write(messageChunk: Buffer) { | ||
assert((this._pendingBuffer === undefined) || this._pendingBuffer === messageChunk, " write should be used with buffer created by createChunk"); | ||
assert((this._pendingBuffer === undefined) | ||
|| this._pendingBuffer === messageChunk, " write should be used with buffer created by createChunk"); | ||
@@ -167,3 +160,125 @@ const header = readRawMessageHeader(messageChunk); | ||
/** | ||
* disconnect the TCP layer and close the underlying socket. | ||
* The ```"close"``` event will be emitted to the observers with err=null. | ||
* | ||
* @method disconnect | ||
* @async | ||
* @param callback | ||
*/ | ||
public disconnect(callback: ErrorCallback): void { | ||
assert(_.isFunction(callback), "expecting a callback function, but got " + callback); | ||
if (this._disconnecting) { | ||
callback(); | ||
return; | ||
} | ||
assert(!this._disconnecting, "TCP Transport has already been disconnected"); | ||
this._disconnecting = true; | ||
// xx assert(!this._theCallback, | ||
// "disconnect shall not be called while the 'one time message receiver' is in operation"); | ||
this._cleanup_timers(); | ||
if (this._socket) { | ||
this._socket.end(); | ||
this._socket.destroy(); | ||
// xx this._socket.removeAllListeners(); | ||
this._socket = null; | ||
} | ||
setImmediate(() => { | ||
this.on_socket_ended(null); | ||
callback(); | ||
}); | ||
} | ||
public isValid(): boolean { | ||
return this._socket !== null && !this._socket.destroyed && !this._disconnecting; | ||
} | ||
protected _write_chunk(messageChunk: Buffer) { | ||
if (this._socket !== null) { | ||
this.bytesWritten += messageChunk.length; | ||
this.chunkWrittenCount++; | ||
this._socket.write(messageChunk); | ||
} | ||
} | ||
protected on_socket_ended(err: Error | null) { | ||
assert(!this._onSocketEndedHasBeenCalled); | ||
this._onSocketEndedHasBeenCalled = true; // we don't want to send close event twice ... | ||
/** | ||
* notify the observers that the transport layer has been disconnected. | ||
* @event close | ||
* @param err the Error object or null | ||
*/ | ||
this.emit("close", err || null); | ||
} | ||
/** | ||
* @method _install_socket | ||
* @param socket {Socket} | ||
* @protected | ||
*/ | ||
protected _install_socket(socket: Socket) { | ||
assert(socket); | ||
this._socket = socket; | ||
if (doDebug) { debugLog("_install_socket ", this.name); } | ||
// install packet assembler ... | ||
this.packetAssembler = new PacketAssembler({ | ||
readMessageFunc: readRawMessageHeader, | ||
minimumSizeInBytes: this.headerSize | ||
}); | ||
if (!this.packetAssembler) { throw new Error("Internal Error"); } | ||
this.packetAssembler.on("message", (messageChunk: Buffer) => this._on_message_received(messageChunk)); | ||
this._socket | ||
.on("data", (data: Buffer) => this._on_socket_data(data)) | ||
.on("close", (hadError) => this._on_socket_close(hadError)) | ||
.on("end", (err: Error) => this._on_socket_end(err)) | ||
.on("error", (err: Error) => this._on_socket_error(err)); | ||
const doDestroyOnTimeout = false; | ||
if (doDestroyOnTimeout) { | ||
// set socket timeout | ||
debugLog("setting _socket.setTimeout to ", this.timeout); | ||
this._socket.setTimeout(this.timeout, () => { | ||
console.log(` _socket ${this.name} has timed out (timeout = ${this.timeout})`); | ||
if (this._socket) { | ||
this._socket.destroy(); | ||
// 08/2008 shall we do this ? | ||
this._socket.removeAllListeners(); | ||
this._socket = null; | ||
} | ||
}); | ||
} | ||
} | ||
/** | ||
* @method _install_one_time_message_receiver | ||
* | ||
* install a one time message receiver callback | ||
* | ||
* Rules: | ||
* * TCP_transport will not emit the ```message``` event, while the "one time message receiver" is in operation. | ||
* * the TCP_transport will wait for the next complete message chunk and call the provided callback func | ||
* ```callback(null,messageChunk);``` | ||
* * if a messageChunk is not received within ```TCP_transport.timeout``` or if the underlying socket reports an error, | ||
* the callback function will be called with an Error. | ||
* | ||
*/ | ||
protected _install_one_time_message_receiver(callback: CallbackWithData) { | ||
assert(!this._theCallback, "callback already set"); | ||
assert(_.isFunction(callback)); | ||
this._theCallback = callback; | ||
this._start_one_time_message_receiver(); | ||
} | ||
private _fulfill_pending_promises(err: Error | null, data?: Buffer): boolean { | ||
@@ -243,17 +358,4 @@ | ||
protected on_socket_ended(err: Error | null) { | ||
assert(!this._onSocketEndedHasBeenCalled); | ||
this._onSocketEndedHasBeenCalled = true; // we don't want to send close event twice ... | ||
/** | ||
* notify the observers that the transport layer has been disconnected. | ||
* @event close | ||
* @param err the Error object or null | ||
*/ | ||
this.emit("close", err || null); | ||
} | ||
private _on_socket_data(data: Buffer): void { | ||
if (!this.packetAssembler) throw new Error("internal Error"); | ||
if (!this.packetAssembler) { throw new Error("internal Error"); } | ||
this.bytesRead += data.length; | ||
@@ -317,104 +419,2 @@ if (data.length > 0) { | ||
} | ||
/** | ||
* @method _install_socket | ||
* @param socket {Socket} | ||
* @protected | ||
*/ | ||
protected _install_socket(socket: Socket) { | ||
assert(socket); | ||
this._socket = socket; | ||
if (doDebug) debugLog("_install_socket ", this.name); | ||
// install packet assembler ... | ||
this.packetAssembler = new PacketAssembler({ | ||
readMessageFunc: readRawMessageHeader, | ||
minimumSizeInBytes: this.headerSize | ||
}); | ||
if (!this.packetAssembler) throw new Error("Internal Error"); | ||
this.packetAssembler.on("message", (messageChunk: Buffer) => this._on_message_received(messageChunk)); | ||
this._socket | ||
.on("data", (data: Buffer) => this._on_socket_data(data)) | ||
.on("close", (hadError) => this._on_socket_close(hadError)) | ||
.on("end", (err: Error) => this._on_socket_end(err)) | ||
.on("error", (err: Error) => this._on_socket_error(err)); | ||
const doDestroyOnTimeout = false; | ||
if (doDestroyOnTimeout) { | ||
// set socket timeout | ||
debugLog("setting _socket.setTimeout to ", this.timeout); | ||
this._socket.setTimeout(this.timeout, () => { | ||
console.log(` _socket ${this.name} has timed out (timeout = ${this.timeout})`); | ||
if (this._socket) { | ||
this._socket.destroy(); | ||
// 08/2008 shall we do this ? | ||
this._socket.removeAllListeners(); | ||
this._socket = null; | ||
} | ||
}); | ||
} | ||
} | ||
/** | ||
* @method _install_one_time_message_receiver | ||
* | ||
* install a one time message receiver callback | ||
* | ||
* Rules: | ||
* * TCP_transport will not emit the ```message``` event, while the "one time message receiver" is in operation. | ||
* * the TCP_transport will wait for the next complete message chunk and call the provided callback func | ||
* ```callback(null,messageChunk);``` | ||
* * if a messageChunk is not received within ```TCP_transport.timeout``` or if the underlying socket reports an error, | ||
* the callback function will be called with an Error. | ||
* | ||
*/ | ||
protected _install_one_time_message_receiver(callback: CallbackWithData) { | ||
assert(!this._theCallback, "callback already set"); | ||
assert(_.isFunction(callback)); | ||
this._theCallback = callback; | ||
this._start_one_time_message_receiver(); | ||
} | ||
/** | ||
* disconnect the TCP layer and close the underlying socket. | ||
* The ```"close"``` event will be emitted to the observers with err=null. | ||
* | ||
* @method disconnect | ||
* @async | ||
* @param callback | ||
*/ | ||
disconnect(callback: ErrorCallback): void { | ||
assert(_.isFunction(callback), "expecting a callback function, but got " + callback); | ||
if (this._disconnecting) { | ||
callback(); | ||
return; | ||
} | ||
assert(!this._disconnecting, "TCP Transport has already been disconnected"); | ||
this._disconnecting = true; | ||
// xx assert(!this._theCallback, "disconnect shall not be called while the 'one time message receiver' is in operation"); | ||
this._cleanup_timers(); | ||
if (this._socket) { | ||
this._socket.end(); | ||
this._socket.destroy(); | ||
// xx this._socket.removeAllListeners(); | ||
this._socket = null; | ||
} | ||
setImmediate(() => { | ||
this.on_socket_ended(null); | ||
callback(); | ||
}); | ||
} | ||
public isValid(): boolean { | ||
return this._socket !== null && !this._socket.destroyed && !this._disconnecting; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
291106
3726