Browse Source

Add connection.fd getter.

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

22
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")
@ -76,6 +78,11 @@ void Connection::Initialize(v8::Handle<v8::Object> target) {
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<Value> Connection::ReadyStateGetter(Local<String> property,
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
// (Connection::Connection) because sometimes the Connection needs to be
// 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> _,
const v8::AccessorInfo& info);
static v8::Handle<v8::Value> FDGetter(v8::Local<v8::String> _,
const v8::AccessorInfo& info);
Connection() : EventEmitter() {
encoding_ = BINARY;

Loading…
Cancel
Save