Allow for net reconnects
This commit is contained in:
parent
71d237e6a0
commit
16e32c8fd9
30
lib/net.js
30
lib/net.js
@ -71,11 +71,7 @@ function allocRecvBuffer () {
|
||||
recvBuffer.used = 0;
|
||||
}
|
||||
|
||||
function Socket (peerInfo) {
|
||||
process.EventEmitter.call(this);
|
||||
|
||||
var self = this;
|
||||
|
||||
function initSocket (self) {
|
||||
self._readWatcher = ioWatchers.alloc();
|
||||
self._readWatcher.callback = function () {
|
||||
// If this is the first recv (recvBuffer doesn't exist) or we've used up
|
||||
@ -163,18 +159,24 @@ function Socket (peerInfo) {
|
||||
self._writeWatcher = ioWatchers.alloc();
|
||||
self._writeWatcher.callback = self._doFlush;
|
||||
self.writable = false;
|
||||
}
|
||||
|
||||
function Socket (peerInfo) {
|
||||
process.EventEmitter.call(this);
|
||||
|
||||
if (peerInfo) {
|
||||
self.fd = peerInfo.fd;
|
||||
self.remoteAddress = peerInfo.remoteAddress;
|
||||
self.remotePort = peerInfo.remotePort;
|
||||
initSocket(this);
|
||||
|
||||
self._readWatcher.set(self.fd, true, false);
|
||||
self._readWatcher.start();
|
||||
self.readable = true;
|
||||
this.fd = peerInfo.fd;
|
||||
this.remoteAddress = peerInfo.remoteAddress;
|
||||
this.remotePort = peerInfo.remotePort;
|
||||
|
||||
self._writeWatcher.set(self.fd, false, true);
|
||||
self.writable = true;
|
||||
this._readWatcher.set(this.fd, true, false);
|
||||
this._readWatcher.start();
|
||||
this.readable = true;
|
||||
|
||||
this._writeWatcher.set(this.fd, false, true);
|
||||
this.writable = true;
|
||||
}
|
||||
};
|
||||
process.inherits(Socket, process.EventEmitter);
|
||||
@ -376,6 +378,8 @@ Socket.prototype.flush = function () {
|
||||
// stream.connect(80, 'nodejs.org') - TCP connect to port 80 on nodejs.org
|
||||
// stream.connect('/tmp/socket') - UNIX connect to socket specified by path
|
||||
Socket.prototype.connect = function () {
|
||||
initSocket(this);
|
||||
|
||||
var self = this;
|
||||
if (self.fd) throw new Error('Socket already opened');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user