0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

tcp: propagate libuv tcp accept() errors to net_uv.js

This commit is contained in:
Ben Noordhuis 2011-08-10 23:59:21 +02:00
parent 46b0654347
commit 460614125b
2 changed files with 26 additions and 19 deletions

View File

@ -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;

View File

@ -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();
// 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_);
// 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();
}
// 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));
int r = uv_accept(handle, (uv_stream_t*)&client_wrap->handle_);
// uv_accept should always work.
assert(r == 0);
// Successful accept. Call the onconnection callback in JavaScript land.
Local<Value> argv[1] = { client_obj };
MakeCallback(wrap->object_, "onconnection", 1, argv);
}