Browse Source

net_uv: reuse socket

v0.7.4-release
Henry Rawas 14 years ago
committed by Ryan Dahl
parent
commit
4c480551c3
  1. 23
      lib/net_uv.js

23
lib/net_uv.js

@ -30,6 +30,17 @@ exports.connect = exports.createConnection = function(port, host /* [cb] */ ) {
return s; return s;
}; };
/* called when creating new Socket, or when re-using a closed Socket */
function initSocketHandle(self) {
self._handle.socket = self;
self._handle.onread = onread;
self._writeRequests = [];
self._flags = 0;
self.destroyed = false;
}
function Socket(options) { function Socket(options) {
if (!(this instanceof Socket)) return new Socket(options); if (!(this instanceof Socket)) return new Socket(options);
@ -42,14 +53,9 @@ function Socket(options) {
} else { } else {
this._handle = new TCP(); this._handle = new TCP();
} }
this._handle.socket = this;
this._handle.onread = onread;
this.allowHalfOpen = options ? (options.allowHalfOpen || false) : false; this.allowHalfOpen = options ? (options.allowHalfOpen || false) : false;
this._writeRequests = []; initSocketHandle(this);
this._flags = 0;
} }
util.inherits(Socket, stream.Stream); util.inherits(Socket, stream.Stream);
@ -312,6 +318,11 @@ function connectip(self, port, ip) {
Socket.prototype.connect = function(port, host /* [cb] */) { Socket.prototype.connect = function(port, host /* [cb] */) {
var self = this; var self = this;
if (this.destroyed) {
this._handle = new TCP();
initSocketHandle(this);
}
if (typeof arguments[2] === 'function') { if (typeof arguments[2] === 'function') {
self.on('connect', arguments[2]); self.on('connect', arguments[2]);
} }

Loading…
Cancel
Save