|
@ -11,6 +11,8 @@ |
|
|
#include <arpa/inet.h> /* inet_ntop */ |
|
|
#include <arpa/inet.h> /* inet_ntop */ |
|
|
#include <netinet/in.h> /* sockaddr_in, sockaddr_in6 */ |
|
|
#include <netinet/in.h> /* sockaddr_in, sockaddr_in6 */ |
|
|
|
|
|
|
|
|
|
|
|
#include <pthread.h> |
|
|
|
|
|
|
|
|
using namespace v8; |
|
|
using namespace v8; |
|
|
using namespace node; |
|
|
using namespace node; |
|
|
|
|
|
|
|
@ -183,6 +185,12 @@ Connection::Connect (const Arguments& args) |
|
|
connection->host_ = strdup(*host_sv); |
|
|
connection->host_ = strdup(*host_sv); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#ifdef __APPLE__ |
|
|
|
|
|
/* Bypass the thread pool and do it sync on this broken ass platform */ |
|
|
|
|
|
eio_req *req = static_cast<eio_req*>(malloc(sizeof(eio_req))); |
|
|
|
|
|
req->data = connection; |
|
|
|
|
|
Connection::Resolve(req); |
|
|
|
|
|
#else |
|
|
/* For the moment I will do DNS lookups in the eio thread pool. This is
|
|
|
/* For the moment I will do DNS lookups in the eio thread pool. This is
|
|
|
* sub-optimal and cannot handle massive numbers of requests but it is |
|
|
* sub-optimal and cannot handle massive numbers of requests but it is |
|
|
* quite portable. |
|
|
* quite portable. |
|
@ -196,38 +204,10 @@ Connection::Connect (const Arguments& args) |
|
|
, Connection::AfterResolve |
|
|
, Connection::AfterResolve |
|
|
, connection |
|
|
, connection |
|
|
); |
|
|
); |
|
|
|
|
|
#endif // __APPLE__
|
|
|
return Undefined(); |
|
|
return Undefined(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Handle<Value> |
|
|
|
|
|
Connection::SetEncoding (const Arguments& args) |
|
|
|
|
|
{ |
|
|
|
|
|
HandleScope scope; |
|
|
|
|
|
|
|
|
|
|
|
Connection *connection = NODE_UNWRAP(Connection, args.This()); |
|
|
|
|
|
if (!connection) return Handle<Value>(); |
|
|
|
|
|
|
|
|
|
|
|
if (!args[0]->IsString()) { |
|
|
|
|
|
connection->encoding_ = RAW; |
|
|
|
|
|
return scope.Close(RAW_SYMBOL); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch (ParseEncoding(args[0])) { |
|
|
|
|
|
case ASCII: |
|
|
|
|
|
connection->encoding_ = ASCII; |
|
|
|
|
|
return scope.Close(ASCII_SYMBOL); |
|
|
|
|
|
|
|
|
|
|
|
case UTF8: |
|
|
|
|
|
connection->encoding_ = UTF8; |
|
|
|
|
|
return scope.Close(UTF8_SYMBOL); |
|
|
|
|
|
|
|
|
|
|
|
case RAW: |
|
|
|
|
|
default: |
|
|
|
|
|
connection->encoding_ = RAW; |
|
|
|
|
|
return scope.Close(RAW_SYMBOL); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
Connection::Resolve (eio_req *req) |
|
|
Connection::Resolve (eio_req *req) |
|
|
{ |
|
|
{ |
|
@ -242,6 +222,10 @@ Connection::Resolve (eio_req *req) |
|
|
free(connection->port_); |
|
|
free(connection->port_); |
|
|
connection->port_ = NULL; |
|
|
connection->port_ = NULL; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef __APPLE__ |
|
|
|
|
|
Connection::AfterResolve(req); |
|
|
|
|
|
#endif // __APPLE__
|
|
|
|
|
|
|
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -263,7 +247,7 @@ Connection::AfterResolve (eio_req *req) |
|
|
// no error. return.
|
|
|
// no error. return.
|
|
|
if (r == 0 && req->result == 0) { |
|
|
if (r == 0 && req->result == 0) { |
|
|
oi_socket_attach (EV_DEFAULT_UC_ &connection->socket_); |
|
|
oi_socket_attach (EV_DEFAULT_UC_ &connection->socket_); |
|
|
return 0; |
|
|
goto out; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
puts("net.cc: resolve failed"); |
|
|
puts("net.cc: resolve failed"); |
|
@ -271,9 +255,44 @@ Connection::AfterResolve (eio_req *req) |
|
|
connection->OnDisconnect(); |
|
|
connection->OnDisconnect(); |
|
|
connection->Detach(); |
|
|
connection->Detach(); |
|
|
|
|
|
|
|
|
|
|
|
out: |
|
|
|
|
|
|
|
|
|
|
|
#ifdef __APPLE__ |
|
|
|
|
|
free(req); |
|
|
|
|
|
#endif // __APPLE__
|
|
|
|
|
|
|
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Handle<Value> |
|
|
|
|
|
Connection::SetEncoding (const Arguments& args) |
|
|
|
|
|
{ |
|
|
|
|
|
HandleScope scope; |
|
|
|
|
|
|
|
|
|
|
|
Connection *connection = NODE_UNWRAP(Connection, args.This()); |
|
|
|
|
|
if (!connection) return Handle<Value>(); |
|
|
|
|
|
|
|
|
|
|
|
if (!args[0]->IsString()) { |
|
|
|
|
|
connection->encoding_ = RAW; |
|
|
|
|
|
return scope.Close(RAW_SYMBOL); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch (ParseEncoding(args[0])) { |
|
|
|
|
|
case ASCII: |
|
|
|
|
|
connection->encoding_ = ASCII; |
|
|
|
|
|
return scope.Close(ASCII_SYMBOL); |
|
|
|
|
|
|
|
|
|
|
|
case UTF8: |
|
|
|
|
|
connection->encoding_ = UTF8; |
|
|
|
|
|
return scope.Close(UTF8_SYMBOL); |
|
|
|
|
|
|
|
|
|
|
|
case RAW: |
|
|
|
|
|
default: |
|
|
|
|
|
connection->encoding_ = RAW; |
|
|
|
|
|
return scope.Close(RAW_SYMBOL); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Handle<Value> |
|
|
Handle<Value> |
|
|
Connection::Close (const Arguments& args) |
|
|
Connection::Close (const Arguments& args) |
|
|
{ |
|
|
{ |
|
|