Skip to content

Commit

Permalink
Use per-Client instance Emit() references instead of global reference
Browse files Browse the repository at this point in the history
  • Loading branch information
mscdex committed Oct 2, 2012
1 parent 9118c3f commit 0a12603
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/binding.cc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ using namespace node;
using namespace v8; using namespace v8;


static Persistent<FunctionTemplate> Client_constructor; static Persistent<FunctionTemplate> Client_constructor;
static Persistent<Function> Emit;
static Persistent<String> emit_symbol; static Persistent<String> emit_symbol;
static Persistent<String> connect_symbol; static Persistent<String> connect_symbol;
static Persistent<String> resquery_symbol; static Persistent<String> resquery_symbol;
Expand Down Expand Up @@ -158,6 +157,7 @@ const my_bool MY_BOOL_TRUE = 1,


class Client : public ObjectWrap { class Client : public ObjectWrap {
public: public:
Persistent<Function> Emit;
uv_poll_t *poll_handle; uv_poll_t *poll_handle;
uv_os_sock_t mysql_sock; uv_os_sock_t mysql_sock;
MYSQL mysql, *mysql_ret; MYSQL mysql, *mysql_ret;
Expand All @@ -173,6 +173,8 @@ class Client : public ObjectWrap {
~Client() { ~Client() {
destructing = true; destructing = true;
close(); close();
Emit.Dispose();
Emit.Clear();
} }


void init() { void init() {
Expand Down Expand Up @@ -252,7 +254,7 @@ class Client : public ObjectWrap {
close_symbol, close_symbol,
Local<Boolean>::New(Boolean::New(obj->had_error)) Local<Boolean>::New(Boolean::New(obj->had_error))
}; };
Emit->Call(obj->handle_, 2, emit_argv); obj->Emit->Call(obj->handle_, 2, emit_argv);
if (try_catch.HasCaught()) if (try_catch.HasCaught())
FatalException(try_catch); FatalException(try_catch);
FREE(obj->poll_handle); FREE(obj->poll_handle);
Expand Down Expand Up @@ -285,7 +287,6 @@ class Client : public ObjectWrap {
int status = 0, new_events = 0; int status = 0, new_events = 0;
bool done = false; bool done = false;
while (!done) { while (!done) {
//printf("STATE BEFORE: %s\n", STATE_TEXT(state));
switch (state) { switch (state) {
case STATE_CONNECT: case STATE_CONNECT:
status = mysql_real_connect_start(&mysql_ret, &mysql, status = mysql_real_connect_start(&mysql_ret, &mysql,
Expand Down Expand Up @@ -532,7 +533,6 @@ class Client : public ObjectWrap {
case STATE_CLOSED: case STATE_CLOSED:
return; return;
} }
//printf("STATE AFTER (%s): %s\n", done ? "done" : "not done", STATE_TEXT(state));
} }
if (status & MYSQL_WAIT_READ) if (status & MYSQL_WAIT_READ)
new_events |= UV_READABLE; new_events |= UV_READABLE;
Expand Down Expand Up @@ -678,11 +678,9 @@ class Client : public ObjectWrap {
obj->Wrap(args.This()); obj->Wrap(args.This());
obj->Ref(); obj->Ref();


if (Emit.IsEmpty()) { obj->Emit = Persistent<Function>::New(
Emit = Persistent<Function>::New( Local<Function>::Cast(obj->handle_->Get(emit_symbol))
Local<Function>::Cast(obj->handle_->Get(emit_symbol)) );
);
}


return args.This(); return args.This();
} }
Expand Down

0 comments on commit 0a12603

Please sign in to comment.