Skip to content

Commit

Permalink
tcp: propagate libuv tcp accept() errors to net_uv.js
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Aug 10, 2011
1 parent 46b0654 commit 4606141
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
5 changes: 5 additions & 0 deletions lib/net_uv.js
Expand Up @@ -653,6 +653,11 @@ function onconnection(clientHandle) {

debug("onconnection");

if (!clientHandle) {
self.emit('error', errnoException(errno, 'accept'));
return;
}

if (self.maxConnections && self.connections >= self.maxConnections) {
clientHandle.close();
return;
Expand Down
34 changes: 18 additions & 16 deletions src/tcp_wrap.cc
Expand Up @@ -214,27 +214,29 @@ class TCPWrap : public StreamWrap {
// uv_close() on the handle.
assert(wrap->object_.IsEmpty() == false);

if (status != 0) {
// TODO Handle server error (set errno and call onconnection with NULL)
assert(0);
return;
}
Handle<Value> argv[1];

if (status == 0) {
// Instantiate the client javascript object and handle.
Local<Object> client_obj = tcpConstructor->NewInstance();

// Instanciate the client javascript object and handle.
Local<Object> client_obj = tcpConstructor->NewInstance();
// Unwrap the client javascript object.
assert(client_obj->InternalFieldCount() > 0);
TCPWrap* client_wrap =
static_cast<TCPWrap*>(client_obj->GetPointerFromInternalField(0));

// Unwrap the client javascript object.
assert(client_obj->InternalFieldCount() > 0);
TCPWrap* client_wrap =
static_cast<TCPWrap*>(client_obj->GetPointerFromInternalField(0));
int r = uv_accept(handle, (uv_stream_t*)&client_wrap->handle_);

int r = uv_accept(handle, (uv_stream_t*)&client_wrap->handle_);
// uv_accept should always work.
assert(r == 0);

// uv_accept should always work.
assert(r == 0);
// Successful accept. Call the onconnection callback in JavaScript land.
argv[0] = client_obj;
} else {
SetErrno(uv_last_error().code);
argv[0] = v8::Null();
}

// Successful accept. Call the onconnection callback in JavaScript land.
Local<Value> argv[1] = { client_obj };
MakeCallback(wrap->object_, "onconnection", 1, argv);
}

Expand Down

0 comments on commit 4606141

Please sign in to comment.