本文整理汇总了TypeScript中stream.Duplex.emit方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Duplex.emit方法的具体用法?TypeScript Duplex.emit怎么用?TypeScript Duplex.emit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stream.Duplex
的用法示例。
在下文中一共展示了Duplex.emit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
client.on('close', function(reason) {
stream.push(null);
stream.emit('close');
log.debug('client went away');
});
示例2: connect
/**
* Starts the connection establishment to the proxy and destination.
* @param existing_socket Connected socket to use instead of creating a new one (internal use).
*/
public connect(existing_socket?: Duplex) {
this._onDataReceived = (data: Buffer) => this.onDataReceived(data);
this._onClose = () => this.onClose();
this._onError = (err: Error) => this.onError(err);
this._onConnect = () => this.onConnect();
// Start timeout timer (defaults to 30 seconds)
const timer = setTimeout(
() => this.onEstablishedTimeout(),
this._options.timeout || DEFAULT_TIMEOUT
);
// check whether unref is available as it differs from browser to NodeJS (#33)
if (timer.unref && typeof timer.unref === 'function') {
timer.unref();
}
// If an existing socket is provided, use it to negotiate SOCKS handshake. Otherwise create a new Socket.
if (existing_socket) {
this._socket = existing_socket;
} else {
this._socket = new net.Socket();
}
// Attach Socket error handlers.
this._socket.once('close', this._onClose);
this._socket.once('error', this._onError);
this._socket.once('connect', this._onConnect);
this._socket.on('data', this._onDataReceived);
this.state = SocksClientState.Connecting;
this._receiveBuffer = new ReceiveBuffer();
if (existing_socket) {
this._socket.emit('connect');
} else {
(this._socket as net.Socket).connect(
this._options.proxy.port,
this._options.proxy.host || this._options.proxy.ipaddress
);
if (
this._options.set_tcp_nodelay !== undefined &&
this._options.set_tcp_nodelay !== null
) {
(this._socket as net.Socket).setNoDelay(
!!this._options.set_tcp_nodelay
);
}
}
// Listen for established event so we can re-emit any excess data received during handshakes.
this.prependOnceListener('established', info => {
setImmediate(() => {
if (this._receiveBuffer.length > 0) {
const excessData = this._receiveBuffer.get(
this._receiveBuffer.length
);
info.socket.emit('data', excessData);
}
info.socket.resume();
});
});
}