diff --git a/src/node_net2.cc b/src/node_net2.cc index 1e4d25044b..5e7cfef179 100644 --- a/src/node_net2.cc +++ b/src/node_net2.cc @@ -29,6 +29,7 @@ #include + namespace node { using namespace v8; @@ -47,13 +48,15 @@ static Persistent unix_symbol; static Persistent recv_msg_template; -#define FD_ARG(a) \ - if (!(a)->IsInt32()) { \ - return ThrowException(Exception::TypeError( \ - String::New("Bad file descriptor argument"))); \ - } \ + +#define FD_ARG(a) \ + if (!(a)->IsInt32()) { \ + return ThrowException(Exception::TypeError( \ + String::New("Bad file descriptor argument"))); \ + } \ int fd = (a)->Int32Value(); + static inline const char *errno_string(int errorno) { #define ERRNO_CASE(e) case e: return #e; switch (errorno) { @@ -394,18 +397,22 @@ static inline Local ErrnoException(int errorno, return e; } + static inline bool SetCloseOnExec(int fd) { return (fcntl(fd, F_SETFD, FD_CLOEXEC) != -1); } + static inline bool SetNonBlock(int fd) { return (fcntl(fd, F_SETFL, O_NONBLOCK) != -1); } + static inline bool SetSockFlags(int fd) { return SetNonBlock(fd) && SetCloseOnExec(fd); } + // Creates nonblocking pipe static Handle Pipe(const Arguments& args) { HandleScope scope; @@ -426,6 +433,7 @@ static Handle Pipe(const Arguments& args) { return scope.Close(a); } + // Creates nonblocking socket pair static Handle SocketPair(const Arguments& args) { HandleScope scope; @@ -450,6 +458,7 @@ static Handle SocketPair(const Arguments& args) { return scope.Close(a); } + // Creates a new non-blocking socket fd // t.socket("TCP"); // t.socket("UNIX"); @@ -597,6 +606,7 @@ static Handle Close(const Arguments& args) { return Undefined(); } + // t.shutdown(fd, "read"); -- SHUT_RD // t.shutdown(fd, "write"); -- SHUT_WR // t.shutdown(fd, "readwrite"); -- SHUT_RDWR @@ -660,6 +670,7 @@ static Handle Connect(const Arguments& args) { return Undefined(); } + static Handle GetSockName(const Arguments& args) { HandleScope scope; @@ -691,6 +702,7 @@ static Handle GetSockName(const Arguments& args) { return scope.Close(info); } + static Handle GetPeerName(const Arguments& args) { HandleScope scope; @@ -804,6 +816,7 @@ static Handle SocketError(const Arguments& args) { return scope.Close(Integer::New(error)); } + // var bytesRead = t.read(fd, buffer, offset, length); // returns null on EAGAIN or EINTR, raises an exception on all other errors // returns 0 on EOF. @@ -846,6 +859,7 @@ static Handle Read(const Arguments& args) { return scope.Close(Integer::New(bytes_read)); } + // bytesRead = t.recvMsg(fd, buffer, offset, length) // if (recvMsg.fd) { // receivedFd = recvMsg.fd; @@ -962,6 +976,7 @@ static Handle Write(const Arguments& args) { return scope.Close(Integer::New(written)); } + // var bytesWritten = t.sendFD(self.fd) // returns null on EAGAIN or EINTR, raises an exception on all other errors static Handle SendFD(const Arguments& args) { @@ -1017,6 +1032,7 @@ static Handle SendFD(const Arguments& args) { return scope.Close(Integer::New(written)); } + // Probably only works for Linux TCP sockets? // Returns the amount of data on the read queue. static Handle ToRead(const Arguments& args) { @@ -1052,7 +1068,10 @@ static Handle SetNoDelay(const Arguments& args) { } +// // G E T A D D R I N F O +// + struct resolve_request { Persistent cb;