Browse Source

Don't use AI_PASSIVE in getaddrinfo() for client connections.

v0.7.4-release
Ryan 16 years ago
parent
commit
6e4e228665
  1. 29
      src/net.cc

29
src/net.cc

@ -38,15 +38,18 @@ using namespace node;
#define WRITE_ONLY_SYMBOL String::NewSymbol("writeOnly") #define WRITE_ONLY_SYMBOL String::NewSymbol("writeOnly")
#define CLOSED_SYMBOL String::NewSymbol("closed") #define CLOSED_SYMBOL String::NewSymbol("closed")
static const struct addrinfo tcp_hints = static const struct addrinfo server_tcp_hints =
/* ai_flags */ { AI_PASSIVE /* ai_flags */ { AI_PASSIVE | AI_NUMERICSERV
/* ai_family */ , AF_UNSPEC /* ai_family */ , AF_INET //AF_UNSPEC
/* ai_socktype */ , SOCK_STREAM /* ai_socktype */ , SOCK_STREAM
/* ai_protocol */ , 0 , 0
/* ai_addrlen */ , 0 };
/* ai_addr */ , NULL
/* ai_canonname */ , NULL static const struct addrinfo client_tcp_hints =
/* ai_next */ , NULL /* ai_flags */ { AI_NUMERICSERV
/* ai_family */ , AF_INET //AF_UNSPEC
/* ai_socktype */ , SOCK_STREAM
, 0
}; };
Persistent<FunctionTemplate> Connection::constructor_template; Persistent<FunctionTemplate> Connection::constructor_template;
@ -228,7 +231,7 @@ Connection::Resolve (eio_req *req)
{ {
Connection *connection = static_cast<Connection*> (req->data); Connection *connection = static_cast<Connection*> (req->data);
struct addrinfo *address = NULL; struct addrinfo *address = NULL;
req->result = getaddrinfo(connection->host_, connection->port_, &tcp_hints, &address); req->result = getaddrinfo(connection->host_, connection->port_, &client_tcp_hints, &address);
req->ptr2 = address; req->ptr2 = address;
free(connection->host_); free(connection->host_);
@ -566,7 +569,6 @@ Acceptor::Listen (const Arguments& args)
if (args.Length() < 1) if (args.Length() < 1)
return ThrowException(String::New("Must give at least a port as argument.")); return ThrowException(String::New("Must give at least a port as argument."));
HandleScope scope; HandleScope scope;
String::AsciiValue port(args[0]->ToString()); String::AsciiValue port(args[0]->ToString());
@ -580,11 +582,10 @@ Acceptor::Listen (const Arguments& args)
// matter--ever. If someone actually complains then simply swap it out // matter--ever. If someone actually complains then simply swap it out
// with a libeio call. // with a libeio call.
struct addrinfo *address = NULL; struct addrinfo *address = NULL;
int r = getaddrinfo(host, *port, &tcp_hints, &address); int r = getaddrinfo(host, *port, &server_tcp_hints, &address);
if (r != 0)
return ThrowException(String::New(strerror(errno)));
free(host); free(host);
if (r != 0)
return ThrowException(String::New(strerror(errno)));
acceptor->Listen(address); acceptor->Listen(address);
return Undefined(); return Undefined();

Loading…
Cancel
Save