From 221c689ebbac9bda42c005b7f0278ce420766b22 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 6 Jun 2013 04:31:12 +0200 Subject: [PATCH] udp_wrap, tcp_wrap: add out arg to AddressToJS Prep work for removing process._errno. The handle.getsockname() function will return a status code in the future and set the address and port properties on the object that's passed in from JS land. --- src/node_internals.h | 10 ++++++++++ src/tcp_wrap.cc | 6 ++---- src/udp_wrap.cc | 3 --- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/node_internals.h b/src/node_internals.h index 92c4fbd213..11d780e240 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -25,6 +25,9 @@ #include #include +#include +#include + #include "v8.h" namespace node { @@ -98,6 +101,13 @@ inline v8::Local NewInstance(v8::Persistent& ctor, int argc = 0, v8::Handle* argv = NULL); +// Convert a struct sockaddr to a { address: '1.2.3.4', port: 1234 } JS object. +// Sets address and port properties on the info object and returns it. +// If |info| is omitted, a new object is returned. +v8::Local AddressToJS( + const sockaddr* addr, + v8::Handle info = v8::Handle()); + #ifdef _WIN32 // emulate snprintf() on windows, _snprintf() doesn't zero-terminate the buffer // on overflow... diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index cf7b027175..7401dd07ea 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -53,8 +53,6 @@ static Cached onconnection_sym; typedef class ReqWrap ConnectWrap; -Local AddressToJS(const sockaddr* addr); - Local TCPWrap::Instantiate() { // If this assert fire then process.binding('tcp_wrap') hasn't been @@ -417,7 +415,7 @@ void TCPWrap::Connect6(const FunctionCallbackInfo& args) { // also used by udp_wrap.cc -Local AddressToJS(const sockaddr* addr) { +Local AddressToJS(const sockaddr* addr, Handle info) { static Cached address_sym; static Cached family_sym; static Cached port_sym; @@ -438,7 +436,7 @@ Local AddressToJS(const sockaddr* addr) { ipv6_sym = String::New("IPv6"); } - Local info = Object::New(); + if (info.IsEmpty()) info = Object::New(); switch (addr->sa_family) { case AF_INET6: diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 01ce1c2759..bd6ac68e80 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -47,9 +47,6 @@ using v8::Value; typedef ReqWrap SendWrap; -// see tcp_wrap.cc -Local AddressToJS(const sockaddr* addr); - static Persistent constructor; static Cached buffer_sym; static Cached oncomplete_sym;