Add connection.fd getter.

This commit is contained in:
Ryan Dahl committed 2009-10-14 17:07:50 +02:00
1 parent d2f5094096
commit a1e5089d9b
2 files changed
+25 -1

No files matched your search

+23 -1
View File
@@ -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<v8::Object> 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<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
View File
@@ -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;