Expose errno exception creation

This commit is contained in:
Ryan Dahl 2010-02-08 07:36:40 -08:00
parent 979f5889d5
commit b6edae5671
2 changed files with 16 additions and 4 deletions

View File

@ -27,6 +27,7 @@ var socketError = process.socketError;
var getsockname = process.getsockname; var getsockname = process.getsockname;
var getaddrinfo = process.getaddrinfo; var getaddrinfo = process.getaddrinfo;
var needsLookup = process.needsLookup; var needsLookup = process.needsLookup;
var errnoException = process.errnoException;
var EINPROGRESS = process.EINPROGRESS; var EINPROGRESS = process.EINPROGRESS;
var ENOENT = process.ENOENT; var ENOENT = process.ENOENT;
var END_OF_FILE = 0; var END_OF_FILE = 0;
@ -406,9 +407,7 @@ Socket.prototype.connect = function () {
self._writeWatcher.callback = self._doFlush; self._writeWatcher.callback = self._doFlush;
self.emit('connect'); self.emit('connect');
} else if (errno != EINPROGRESS) { } else if (errno != EINPROGRESS) {
var e = new Error('connection error'); self.forceClose(errnoException(errno, 'connect'));
e.errno = errno;
self.forceClose(e);
} }
}; };
} }

View File

@ -1246,6 +1246,18 @@ static Handle<Value> NeedsLookup(const Arguments& args) {
} }
static Handle<Value> CreateErrnoException(const Arguments& args) {
HandleScope scope;
int errorno = args[0]->Int32Value();
String::Utf8Value syscall(args[1]->ToString());
Local<Value> exception = ErrnoException(errorno, *syscall);
return scope.Close(exception);
}
void InitNet2(Handle<Object> target) { void InitNet2(Handle<Object> target) {
HandleScope scope; HandleScope scope;
@ -1275,6 +1287,7 @@ void InitNet2(Handle<Object> target) {
NODE_SET_METHOD(target, "getpeername", GetPeerName); NODE_SET_METHOD(target, "getpeername", GetPeerName);
NODE_SET_METHOD(target, "getaddrinfo", GetAddrInfo); NODE_SET_METHOD(target, "getaddrinfo", GetAddrInfo);
NODE_SET_METHOD(target, "needsLookup", NeedsLookup); NODE_SET_METHOD(target, "needsLookup", NeedsLookup);
NODE_SET_METHOD(target, "errnoException", CreateErrnoException);
target->Set(String::NewSymbol("ENOENT"), Integer::New(ENOENT)); target->Set(String::NewSymbol("ENOENT"), Integer::New(ENOENT));
target->Set(String::NewSymbol("EINPROGRESS"), Integer::New(EINPROGRESS)); target->Set(String::NewSymbol("EINPROGRESS"), Integer::New(EINPROGRESS));