|
|
@ -25,6 +25,7 @@ var getsockname = process.getsockname; |
|
|
|
var getaddrinfo = process.getaddrinfo; |
|
|
|
var needsLookup = process.needsLookup; |
|
|
|
var EINPROGRESS = process.EINPROGRESS; |
|
|
|
var ENOENT = process.ENOENT; |
|
|
|
var END_OF_FILE = 42; |
|
|
|
|
|
|
|
|
|
|
@ -318,7 +319,7 @@ Socket.prototype.connect = function () { |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof(arguments[0]) == 'string' && arguments.length == 1) { |
|
|
|
if (typeof(arguments[0]) == 'string') { |
|
|
|
self.fd = socket('unix'); |
|
|
|
self.type = 'unix'; |
|
|
|
// TODO check if sockfile exists?
|
|
|
@ -457,12 +458,32 @@ Server.prototype.listen = function () { |
|
|
|
// the first argument specifies a path
|
|
|
|
self.fd = socket('unix'); |
|
|
|
self.type = 'unix'; |
|
|
|
// TODO unlink sockfile if exists?
|
|
|
|
// if (lstat(SOCKFILE, &tstat) == 0) {
|
|
|
|
// assert(S_ISSOCK(tstat.st_mode));
|
|
|
|
// unlink(SOCKFILE);
|
|
|
|
// }
|
|
|
|
bind(self.fd, arguments[0]); |
|
|
|
var path = arguments[0]; |
|
|
|
self.path = path; |
|
|
|
// unlink sockfile if it exists
|
|
|
|
process.fs.stat(path, function (r) { |
|
|
|
if (r instanceof Error) { |
|
|
|
if (r.errno == ENOENT) { |
|
|
|
bind(self.fd, path); |
|
|
|
doListen(); |
|
|
|
} else { |
|
|
|
throw r; |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (!r.isFile()) { |
|
|
|
throw new Error("Non-file exists at " + path); |
|
|
|
} else { |
|
|
|
process.fs.unlink(path, function (err) { |
|
|
|
if (err) { |
|
|
|
throw err; |
|
|
|
} else { |
|
|
|
bind(self.fd, path); |
|
|
|
doListen(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (arguments.length == 0) { |
|
|
|
self.fd = socket('tcp'); |
|
|
|
self.type = 'tcp'; |
|
|
@ -488,9 +509,19 @@ Server.prototype.address = function () { |
|
|
|
|
|
|
|
|
|
|
|
Server.prototype.close = function () { |
|
|
|
if (!this.fd) throw new Error('Not running'); |
|
|
|
this.watcher.stop(); |
|
|
|
close(this.fd); |
|
|
|
this.fd = null; |
|
|
|
this.emit("close"); |
|
|
|
var self = this; |
|
|
|
if (!self.fd) throw new Error('Not running'); |
|
|
|
|
|
|
|
self.watcher.stop(); |
|
|
|
|
|
|
|
close(self.fd); |
|
|
|
self.fd = null; |
|
|
|
|
|
|
|
if (self.type === "unix") { |
|
|
|
process.fs.unlink(self.path, function () { |
|
|
|
self.emit("close"); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
self.emit("close"); |
|
|
|
} |
|
|
|
}; |
|
|
|