|
@ -13,34 +13,25 @@ class Connection : public ObjectWrap { |
|
|
public: |
|
|
public: |
|
|
static void Initialize (v8::Handle<v8::Object> target); |
|
|
static void Initialize (v8::Handle<v8::Object> target); |
|
|
|
|
|
|
|
|
Connection (v8::Handle<v8::Object> handle, v8::Handle<v8::Function> protocol_class); |
|
|
|
|
|
virtual ~Connection () { Close(); } |
|
|
|
|
|
|
|
|
|
|
|
int Connect (struct addrinfo *address) { |
|
|
|
|
|
return oi_socket_connect (&socket_, address); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Send (oi_buf *buf) { |
|
|
|
|
|
oi_socket_write (&socket_, buf); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SendEOF (void) { |
|
|
|
|
|
oi_socket_write_eof (&socket_); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Close (void) { |
|
|
|
|
|
oi_socket_close (&socket_); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SetAcceptor (v8::Handle<v8::Object> acceptor_handle); |
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
protected: |
|
|
|
|
|
/* v8 interface */ |
|
|
|
|
|
static v8::Persistent<v8::FunctionTemplate> constructor_template; |
|
|
static v8::Handle<v8::Value> v8New (const v8::Arguments& args); |
|
|
static v8::Handle<v8::Value> v8New (const v8::Arguments& args); |
|
|
static v8::Handle<v8::Value> v8Connect (const v8::Arguments& args); |
|
|
static v8::Handle<v8::Value> v8Connect (const v8::Arguments& args); |
|
|
static v8::Handle<v8::Value> v8Send (const v8::Arguments& args); |
|
|
static v8::Handle<v8::Value> v8Send (const v8::Arguments& args); |
|
|
static v8::Handle<v8::Value> v8SendEOF (const v8::Arguments& args); |
|
|
static v8::Handle<v8::Value> v8SendEOF (const v8::Arguments& args); |
|
|
static v8::Handle<v8::Value> v8Close (const v8::Arguments& args); |
|
|
static v8::Handle<v8::Value> v8Close (const v8::Arguments& args); |
|
|
|
|
|
|
|
|
|
|
|
Connection (v8::Handle<v8::Object> handle, v8::Handle<v8::Function> protocol_class); |
|
|
|
|
|
virtual ~Connection () { Close(); } |
|
|
|
|
|
|
|
|
|
|
|
int Connect (struct addrinfo *address) { return oi_socket_connect (&socket_, address); } |
|
|
|
|
|
void Send (oi_buf *buf) { oi_socket_write (&socket_, buf); } |
|
|
|
|
|
void SendEOF (void) { oi_socket_write_eof (&socket_); } |
|
|
|
|
|
void Close (void) { oi_socket_close (&socket_); } |
|
|
|
|
|
|
|
|
|
|
|
void SetAcceptor (v8::Handle<v8::Object> acceptor_handle); |
|
|
|
|
|
|
|
|
virtual void OnConnect (void); |
|
|
virtual void OnConnect (void); |
|
|
virtual void OnReceive (const void *buf, size_t len); |
|
|
virtual void OnReceive (const void *buf, size_t len); |
|
|
virtual void OnDrain (void); |
|
|
virtual void OnDrain (void); |
|
@ -51,7 +42,10 @@ protected: |
|
|
|
|
|
|
|
|
v8::Local<v8::Object> GetProtocol (void); |
|
|
v8::Local<v8::Object> GetProtocol (void); |
|
|
|
|
|
|
|
|
//private:
|
|
|
enum encoding encoding_; |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
|
/* liboi callbacks */ |
|
|
/* liboi callbacks */ |
|
|
static void on_connect (oi_socket *s) { |
|
|
static void on_connect (oi_socket *s) { |
|
|
Connection *connection = static_cast<Connection*> (s->data); |
|
|
Connection *connection = static_cast<Connection*> (s->data); |
|
@ -88,8 +82,6 @@ protected: |
|
|
|
|
|
|
|
|
static int Resolve (eio_req *req); |
|
|
static int Resolve (eio_req *req); |
|
|
static int AfterResolve (eio_req *req); |
|
|
static int AfterResolve (eio_req *req); |
|
|
|
|
|
|
|
|
enum encoding encoding_; |
|
|
|
|
|
char *host_; |
|
|
char *host_; |
|
|
char *port_; |
|
|
char *port_; |
|
|
oi_socket socket_; |
|
|
oi_socket socket_; |
|
@ -101,8 +93,14 @@ class Acceptor : public ObjectWrap { |
|
|
public: |
|
|
public: |
|
|
static void Initialize (v8::Handle<v8::Object> target); |
|
|
static void Initialize (v8::Handle<v8::Object> target); |
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
|
|
static v8::Persistent<v8::FunctionTemplate> constructor_template; |
|
|
|
|
|
static v8::Handle<v8::Value> v8New (const v8::Arguments& args); |
|
|
|
|
|
static v8::Handle<v8::Value> v8Listen (const v8::Arguments& args); |
|
|
|
|
|
static v8::Handle<v8::Value> v8Close (const v8::Arguments& args); |
|
|
|
|
|
|
|
|
Acceptor (v8::Handle<v8::Object> handle, v8::Handle<v8::Object> options); |
|
|
Acceptor (v8::Handle<v8::Object> handle, v8::Handle<v8::Object> options); |
|
|
~Acceptor () { Close(); } |
|
|
virtual ~Acceptor () { Close(); } |
|
|
|
|
|
|
|
|
int Listen (struct addrinfo *address) { |
|
|
int Listen (struct addrinfo *address) { |
|
|
int r = oi_server_listen (&server_, address); |
|
|
int r = oi_server_listen (&server_, address); |
|
@ -115,13 +113,8 @@ public: |
|
|
oi_server_close (&server_); |
|
|
oi_server_close (&server_); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected: |
|
|
virtual Connection* OnConnection (struct sockaddr *addr, socklen_t len); |
|
|
Connection* OnConnection (struct sockaddr *addr, socklen_t len); |
|
|
virtual void OnError (struct oi_error error); |
|
|
void OnError (struct oi_error error); |
|
|
|
|
|
|
|
|
|
|
|
static v8::Handle<v8::Value> v8New (const v8::Arguments& args); |
|
|
|
|
|
static v8::Handle<v8::Value> v8Listen (const v8::Arguments& args); |
|
|
|
|
|
static v8::Handle<v8::Value> v8Close (const v8::Arguments& args); |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
static oi_socket* on_connection (oi_server *s, struct sockaddr *addr, socklen_t len) { |
|
|
static oi_socket* on_connection (oi_server *s, struct sockaddr *addr, socklen_t len) { |
|
|