Fix crash in oi_socket; add ready state reader to Connection objects.
This commit is contained in:
Родитель
478e45a32f
Коммит
69ab87ca53
|
@ -914,9 +914,14 @@ void oi_socket_force_close (oi_socket *socket)
|
|||
void
|
||||
oi_socket_write(oi_socket *socket, oi_buf *buf)
|
||||
{
|
||||
assert(socket->write_action != NULL && "Do not write to a closed socket");
|
||||
assert(socket->got_full_close == FALSE && "Do not write to a closing socket");
|
||||
assert(socket->got_half_close == FALSE && "Do not write to a closing socket");
|
||||
if (socket->write_action == NULL) {
|
||||
assert(0 && "Do not write to a closed socket");
|
||||
goto error;
|
||||
}
|
||||
if (socket->got_full_close == TRUE || socket->got_half_close == TRUE) {
|
||||
assert(0 && "Do not write to a closing socket");
|
||||
goto error;
|
||||
}
|
||||
|
||||
oi_queue_insert_head(&socket->out_stream, &buf->queue);
|
||||
buf->written = 0;
|
||||
|
@ -924,6 +929,10 @@ oi_socket_write(oi_socket *socket, oi_buf *buf)
|
|||
if (socket->attached) {
|
||||
ev_io_start(SOCKET_LOOP_ &socket->write_watcher);
|
||||
}
|
||||
return;
|
||||
|
||||
error:
|
||||
if (buf->release) buf->release(buf);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
44
src/net.cc
44
src/net.cc
|
@ -31,6 +31,12 @@ using namespace node;
|
|||
#define PROTOCOL_SYMBOL String::NewSymbol("protocol")
|
||||
#define CONNECTION_HANDLER_SYMBOL String::NewSymbol("connection_handler")
|
||||
|
||||
#define READY_STATE_SYMBOL String::NewSymbol("readyState")
|
||||
#define OPEN_SYMBOL String::NewSymbol("open")
|
||||
#define READ_ONLY_SYMBOL String::NewSymbol("readOnly")
|
||||
#define WRITE_ONLY_SYMBOL String::NewSymbol("writeOnly")
|
||||
#define CLOSED_SYMBOL String::NewSymbol("closed")
|
||||
|
||||
static const struct addrinfo tcp_hints =
|
||||
/* ai_flags */ { AI_PASSIVE
|
||||
/* ai_family */ , AF_UNSPEC
|
||||
|
@ -62,13 +68,49 @@ Connection::Initialize (v8::Handle<v8::Object> target)
|
|||
NODE_SET_PROTOTYPE_METHOD(constructor_template, "forceClose", ForceClose);
|
||||
|
||||
constructor_template->PrototypeTemplate()->SetAccessor(
|
||||
String::NewSymbol("encoding"),
|
||||
ENCODING_SYMBOL,
|
||||
EncodingGetter,
|
||||
EncodingSetter);
|
||||
|
||||
constructor_template->PrototypeTemplate()->SetAccessor(
|
||||
READY_STATE_SYMBOL,
|
||||
ReadyStateGetter);
|
||||
|
||||
target->Set(String::NewSymbol("Connection"), constructor_template->GetFunction());
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Connection::ReadyStateGetter (Local<String> _, const AccessorInfo& info)
|
||||
{
|
||||
Connection *connection = NODE_UNWRAP(Connection, info.This());
|
||||
if (!connection) return Handle<Value>();
|
||||
|
||||
HandleScope scope;
|
||||
|
||||
if (connection->socket_.got_full_close) {
|
||||
return CLOSED_SYMBOL;
|
||||
}
|
||||
|
||||
if (connection->socket_.got_half_close) {
|
||||
if (connection->socket_.read_action)
|
||||
return READ_ONLY_SYMBOL;
|
||||
else
|
||||
return CLOSED_SYMBOL;
|
||||
}
|
||||
|
||||
if (connection->socket_.read_action && connection->socket_.write_action)
|
||||
return OPEN_SYMBOL;
|
||||
else if (connection->socket_.write_action)
|
||||
return WRITE_ONLY_SYMBOL;
|
||||
else if (connection->socket_.read_action)
|
||||
return READ_ONLY_SYMBOL;
|
||||
else
|
||||
return CLOSED_SYMBOL;
|
||||
|
||||
assert(0 && "This shouldnt happen");
|
||||
return ThrowException(String::New("This shouldn't happen."));
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Connection::EncodingGetter (Local<String> _, const AccessorInfo& info)
|
||||
{
|
||||
|
|
10
src/net.h
10
src/net.h
|
@ -25,8 +25,14 @@ protected:
|
|||
static v8::Handle<v8::Value> Close (const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> FullClose (const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> ForceClose (const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> EncodingGetter (v8::Local<v8::String> _, const v8::AccessorInfo& info);
|
||||
static void EncodingSetter (v8::Local<v8::String> _, v8::Local<v8::Value> value, const v8::AccessorInfo& info);
|
||||
|
||||
static v8::Handle<v8::Value> EncodingGetter (v8::Local<v8::String> _,
|
||||
const v8::AccessorInfo& info);
|
||||
static void EncodingSetter (v8::Local<v8::String> _,
|
||||
v8::Local<v8::Value> value, const v8::AccessorInfo& info);
|
||||
|
||||
static v8::Handle<v8::Value> ReadyStateGetter (v8::Local<v8::String> _,
|
||||
const v8::AccessorInfo& info);
|
||||
|
||||
Connection (v8::Handle<v8::Object> handle);
|
||||
virtual ~Connection ();
|
||||
|
|
Загрузка…
Ссылка в новой задаче