Browse Source

Add connection.fd getter.

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
a1e5089d9b
  1. 24
      src/net.cc
  2. 2
      src/net.h

24
src/net.cc

@ -23,6 +23,8 @@ namespace node {
#define SERVER_SYMBOL String::NewSymbol("server") #define SERVER_SYMBOL String::NewSymbol("server")
#define REMOTE_ADDRESS_SYMBOL String::NewSymbol("remoteAddress") #define REMOTE_ADDRESS_SYMBOL String::NewSymbol("remoteAddress")
#define FD_SYMBOL String::NewSymbol("fd")
#define READY_STATE_SYMBOL String::NewSymbol("readyState") #define READY_STATE_SYMBOL String::NewSymbol("readyState")
#define OPEN_SYMBOL String::NewSymbol("open") #define OPEN_SYMBOL String::NewSymbol("open")
#define OPENING_SYMBOL String::NewSymbol("opening") #define OPENING_SYMBOL String::NewSymbol("opening")
@ -71,11 +73,16 @@ void Connection::Initialize(v8::Handle<v8::Object> target) {
NODE_SET_PROTOTYPE_METHOD(constructor_template, "setTimeout", SetTimeout); NODE_SET_PROTOTYPE_METHOD(constructor_template, "setTimeout", SetTimeout);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "setNoDelay", SetNoDelay); NODE_SET_PROTOTYPE_METHOD(constructor_template, "setNoDelay", SetNoDelay);
// Getter for connection.readyState // Getter for connection.readyState
constructor_template->PrototypeTemplate()->SetAccessor( constructor_template->PrototypeTemplate()->SetAccessor(
READY_STATE_SYMBOL, READY_STATE_SYMBOL,
ReadyStateGetter); ReadyStateGetter);
// Getter for connection.readyState
constructor_template->PrototypeTemplate()->SetAccessor(
FD_SYMBOL,
FDGetter);
// Assign class to its place as tcp.Connection // Assign class to its place as tcp.Connection
target->Set(String::NewSymbol("Connection"), target->Set(String::NewSymbol("Connection"),
constructor_template->GetFunction()); constructor_template->GetFunction());
@ -112,6 +119,21 @@ Handle<Value> Connection::ReadyStateGetter(Local<String> property,
String::New("This shouldn't happen."))); String::New("This shouldn't happen.")));
} }
Handle<Value> Connection::FDGetter(Local<String> property,
const AccessorInfo& info) {
// Unwrap the javascript object to get the C++ object
Connection *connection = ObjectWrap::Unwrap<Connection>(info.This());
assert(connection);
HandleScope scope;
assert(property == FD_SYMBOL);
Local<Integer> fd = Integer::New(connection->stream_.recvfd);
return scope.Close(fd);
}
// Constructor - these actions are not taken in the normal constructor // Constructor - these actions are not taken in the normal constructor
// (Connection::Connection) because sometimes the Connection needs to be // (Connection::Connection) because sometimes the Connection needs to be
// reinitialized without destroying the object. // reinitialized without destroying the object.

2
src/net.h

@ -32,6 +32,8 @@ class Connection : public EventEmitter {
static v8::Handle<v8::Value> ReadyStateGetter(v8::Local<v8::String> _, static v8::Handle<v8::Value> ReadyStateGetter(v8::Local<v8::String> _,
const v8::AccessorInfo& info); const v8::AccessorInfo& info);
static v8::Handle<v8::Value> FDGetter(v8::Local<v8::String> _,
const v8::AccessorInfo& info);
Connection() : EventEmitter() { Connection() : EventEmitter() {
encoding_ = BINARY; encoding_ = BINARY;

Loading…
Cancel
Save