mirror of https://github.com/nodejs/node.git
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.pull/41362/head
parent
d11e7c2075
commit
221c689ebb
|
@ -25,6 +25,9 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "v8.h"
|
||||
|
||||
namespace node {
|
||||
|
@ -98,6 +101,13 @@ inline v8::Local<v8::Object> NewInstance(v8::Persistent<v8::Function>& ctor,
|
|||
int argc = 0,
|
||||
v8::Handle<v8::Value>* 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<v8::Object> AddressToJS(
|
||||
const sockaddr* addr,
|
||||
v8::Handle<v8::Object> info = v8::Handle<v8::Object>());
|
||||
|
||||
#ifdef _WIN32
|
||||
// emulate snprintf() on windows, _snprintf() doesn't zero-terminate the buffer
|
||||
// on overflow...
|
||||
|
|
|
@ -53,8 +53,6 @@ static Cached<String> onconnection_sym;
|
|||
|
||||
typedef class ReqWrap<uv_connect_t> ConnectWrap;
|
||||
|
||||
Local<Object> AddressToJS(const sockaddr* addr);
|
||||
|
||||
|
||||
Local<Object> TCPWrap::Instantiate() {
|
||||
// If this assert fire then process.binding('tcp_wrap') hasn't been
|
||||
|
@ -417,7 +415,7 @@ void TCPWrap::Connect6(const FunctionCallbackInfo<Value>& args) {
|
|||
|
||||
|
||||
// also used by udp_wrap.cc
|
||||
Local<Object> AddressToJS(const sockaddr* addr) {
|
||||
Local<Object> AddressToJS(const sockaddr* addr, Handle<Object> info) {
|
||||
static Cached<String> address_sym;
|
||||
static Cached<String> family_sym;
|
||||
static Cached<String> port_sym;
|
||||
|
@ -438,7 +436,7 @@ Local<Object> AddressToJS(const sockaddr* addr) {
|
|||
ipv6_sym = String::New("IPv6");
|
||||
}
|
||||
|
||||
Local<Object> info = Object::New();
|
||||
if (info.IsEmpty()) info = Object::New();
|
||||
|
||||
switch (addr->sa_family) {
|
||||
case AF_INET6:
|
||||
|
|
|
@ -47,9 +47,6 @@ using v8::Value;
|
|||
|
||||
typedef ReqWrap<uv_udp_send_t> SendWrap;
|
||||
|
||||
// see tcp_wrap.cc
|
||||
Local<Object> AddressToJS(const sockaddr* addr);
|
||||
|
||||
static Persistent<Function> constructor;
|
||||
static Cached<String> buffer_sym;
|
||||
static Cached<String> oncomplete_sym;
|
||||
|
|
Loading…
Reference in New Issue