|
|
@ -11,6 +11,8 @@ |
|
|
|
#include <arpa/inet.h> /* inet_ntop */ |
|
|
|
#include <netinet/in.h> /* sockaddr_in, sockaddr_in6 */ |
|
|
|
|
|
|
|
#include <pthread.h> |
|
|
|
|
|
|
|
using namespace v8; |
|
|
|
using namespace node; |
|
|
|
|
|
|
@ -183,6 +185,12 @@ Connection::Connect (const Arguments& args) |
|
|
|
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
|
|
|
|
* sub-optimal and cannot handle massive numbers of requests but it is |
|
|
|
* quite portable. |
|
|
@ -196,38 +204,10 @@ Connection::Connect (const Arguments& args) |
|
|
|
, Connection::AfterResolve |
|
|
|
, connection |
|
|
|
); |
|
|
|
#endif // __APPLE__
|
|
|
|
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 |
|
|
|
Connection::Resolve (eio_req *req) |
|
|
|
{ |
|
|
@ -242,6 +222,10 @@ Connection::Resolve (eio_req *req) |
|
|
|
free(connection->port_); |
|
|
|
connection->port_ = NULL; |
|
|
|
|
|
|
|
#ifdef __APPLE__ |
|
|
|
Connection::AfterResolve(req); |
|
|
|
#endif // __APPLE__
|
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
@ -263,7 +247,7 @@ Connection::AfterResolve (eio_req *req) |
|
|
|
// no error. return.
|
|
|
|
if (r == 0 && req->result == 0) { |
|
|
|
oi_socket_attach (EV_DEFAULT_UC_ &connection->socket_); |
|
|
|
return 0; |
|
|
|
goto out; |
|
|
|
} |
|
|
|
|
|
|
|
puts("net.cc: resolve failed"); |
|
|
@ -271,9 +255,44 @@ Connection::AfterResolve (eio_req *req) |
|
|
|
connection->OnDisconnect(); |
|
|
|
connection->Detach(); |
|
|
|
|
|
|
|
out: |
|
|
|
|
|
|
|
#ifdef __APPLE__ |
|
|
|
free(req); |
|
|
|
#endif // __APPLE__
|
|
|
|
|
|
|
|
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> |
|
|
|
Connection::Close (const Arguments& args) |
|
|
|
{ |
|
|
|