From a1e5089d9b2f3af61da5a7231e328dc49b05aebe Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 14 Oct 2009 17:07:50 +0200 Subject: [PATCH] Add connection.fd getter. --- src/net.cc | 24 +++++++++++++++++++++++- src/net.h | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/net.cc b/src/net.cc index d4536e8..8c5fad1 100644 --- a/src/net.cc +++ b/src/net.cc @@ -23,6 +23,8 @@ namespace node { #define SERVER_SYMBOL String::NewSymbol("server") #define REMOTE_ADDRESS_SYMBOL String::NewSymbol("remoteAddress") +#define FD_SYMBOL String::NewSymbol("fd") + #define READY_STATE_SYMBOL String::NewSymbol("readyState") #define OPEN_SYMBOL String::NewSymbol("open") #define OPENING_SYMBOL String::NewSymbol("opening") @@ -71,11 +73,16 @@ void Connection::Initialize(v8::Handle target) { NODE_SET_PROTOTYPE_METHOD(constructor_template, "setTimeout", SetTimeout); NODE_SET_PROTOTYPE_METHOD(constructor_template, "setNoDelay", SetNoDelay); - // Getter for connection.readyState + // Getter for connection.readyState constructor_template->PrototypeTemplate()->SetAccessor( READY_STATE_SYMBOL, ReadyStateGetter); + // Getter for connection.readyState + constructor_template->PrototypeTemplate()->SetAccessor( + FD_SYMBOL, + FDGetter); + // Assign class to its place as tcp.Connection target->Set(String::NewSymbol("Connection"), constructor_template->GetFunction()); @@ -112,6 +119,21 @@ Handle Connection::ReadyStateGetter(Local property, String::New("This shouldn't happen."))); } +Handle Connection::FDGetter(Local property, + const AccessorInfo& info) { + // Unwrap the javascript object to get the C++ object + Connection *connection = ObjectWrap::Unwrap(info.This()); + assert(connection); + + HandleScope scope; + + assert(property == FD_SYMBOL); + + Local fd = Integer::New(connection->stream_.recvfd); + + return scope.Close(fd); +} + // Constructor - these actions are not taken in the normal constructor // (Connection::Connection) because sometimes the Connection needs to be // reinitialized without destroying the object. diff --git a/src/net.h b/src/net.h index 99a3aa6..e1261ab 100644 --- a/src/net.h +++ b/src/net.h @@ -32,6 +32,8 @@ class Connection : public EventEmitter { static v8::Handle ReadyStateGetter(v8::Local _, const v8::AccessorInfo& info); + static v8::Handle FDGetter(v8::Local _, + const v8::AccessorInfo& info); Connection() : EventEmitter() { encoding_ = BINARY; -- 2.7.4