aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHenry Rawas <henryr@schakra.com>2011-07-06 17:13:17 -0700
committerRyan Dahl <ry@tinyclouds.org>2011-07-07 15:55:12 -0700
commit3c52fd006e2fa186132b6a9aec8064a80dd7e09a (patch)
treebf9d67f7f80a3fa37fd87a34ba85f8490cb5343e /lib
parentb6f6a1ca110dc40074c63a30e86351aa4e9ddf71 (diff)
downloadandroid-node-v8-3c52fd006e2fa186132b6a9aec8064a80dd7e09a.tar.gz
android-node-v8-3c52fd006e2fa186132b6a9aec8064a80dd7e09a.tar.bz2
android-node-v8-3c52fd006e2fa186132b6a9aec8064a80dd7e09a.zip
net_uv: fix test-net-eaddrinuse.js
Diffstat (limited to 'lib')
-rw-r--r--lib/net_uv.js38
1 files changed, 28 insertions, 10 deletions
diff --git a/lib/net_uv.js b/lib/net_uv.js
index 039ff70b57..88ecea51cf 100644
--- a/lib/net_uv.js
+++ b/lib/net_uv.js
@@ -450,10 +450,7 @@ function Server(/* [ options, ] listener */) {
this.connections = 0;
this.allowHalfOpen = options.allowHalfOpen || false;
-
- this._handle = new TCP();
- this._handle.socket = this;
- this._handle.onconnection = onconnection;
+ this._handle = null;
}
util.inherits(Server, events.EventEmitter);
exports.Server = Server;
@@ -465,6 +462,11 @@ function toPort(x) { return (x = Number(x)) >= 0 ? x : false; }
function listenip(self, ip, port, addressType) {
var r = 0;
+ // assign handle in listen, and clean up if bind or listen fails
+ self._handle = new TCP();
+ self._handle.socket = this;
+ self._handle.onconnection = onconnection;
+
if (ip && port) {
debug("bind to " + ip);
if (addressType == 6) {
@@ -473,14 +475,27 @@ function listenip(self, ip, port, addressType) {
r = self._handle.bind(ip, port);
}
}
-
if (r) {
- self.emit('error', errnoException(errno, 'listen'));
- } else {
- self._handle.listen(self._backlog || 128);
+ self._handle.close();
+ self._handle = null;
+
process.nextTick(function() {
- self.emit('listening');
+ self.emit('error', errnoException(errno, 'listen'));
});
+ } else {
+ r = self._handle.listen(self._backlog || 128);
+ if (r) {
+ self._handle.close();
+ self._handle = null;
+
+ process.nextTick(function() {
+ self.emit('error', errnoException(errno, 'listen'));
+ });
+ } else {
+ process.nextTick(function() {
+ self.emit('listening');
+ });
+ }
}
}
@@ -539,7 +554,10 @@ function onconnection(clientHandle) {
Server.prototype.close = function() {
- this._handle.close();
+ if (this._handle != null) {
+ this._handle.close();
+ this._handle = null;
+ }
};