Skip to content

Commit

Permalink
Partially added reconnect handlers, but backing library is now
Browse files Browse the repository at this point in the history
reconnecting for reasons unknown. Checking in before I wipe the
reconnect handlers, just in case.
  • Loading branch information
jeremycx committed May 27, 2011
1 parent 544f021 commit de8a03d
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/LDAP.cc
Expand Up @@ -65,6 +65,8 @@ class LDAPConnection : public EventEmitter
LDAP *ld;
ev_io read_watcher_;
ev_io write_watcher_;
Persistent<Function> reconnect_handler;
int has_reconnect_handler;

public:
static Persistent<FunctionTemplate> s_ct;
Expand All @@ -84,9 +86,10 @@ class LDAPConnection : public EventEmitter
NODE_SET_PROTOTYPE_METHOD(s_ct, "Close", Close);
NODE_SET_PROTOTYPE_METHOD(s_ct, "Search", Search);
NODE_SET_PROTOTYPE_METHOD(s_ct, "Modify", Modify);
NODE_SET_PROTOTYPE_METHOD(s_ct, "Bind", Bind);
NODE_SET_PROTOTYPE_METHOD(s_ct, "Bind", Bind);
NODE_SET_PROTOTYPE_METHOD(s_ct, "Rename", Rename);
NODE_SET_PROTOTYPE_METHOD(s_ct, "Add", Add);
NODE_SET_PROTOTYPE_METHOD(s_ct, "SetReconnect", SetReconnect);

symbol_connected = NODE_PSYMBOL("connected");
symbol_disconnected = NODE_PSYMBOL("disconnected");
Expand All @@ -107,6 +110,7 @@ class LDAPConnection : public EventEmitter
c->read_watcher_.data = c;

c->ld = NULL;
c->has_reconnect_handler = 0;

return args.This();
}
Expand Down Expand Up @@ -136,6 +140,20 @@ class LDAPConnection : public EventEmitter
return scope.Close(Integer::New(0));
}


NODE_METHOD(SetReconnect) {
HandleScope scope;
GETOBJ(c);

ENFORCE_ARG_LENGTH(1, "Invalid number of arguments to SetReconnect()");
REQ_FUN_ARG(0, cb);

c->reconnect_handler = Persistent<Function>::New(cb);
c->has_reconnect_handler = 1;

RETURN_INT(0);
}

NODE_METHOD(Close) {
HandleScope scope;
GETOBJ(c);
Expand Down Expand Up @@ -404,7 +422,8 @@ class LDAPConnection : public EventEmitter
RETURN_INT(msgid);
}

static Local<Value> parseReply(LDAPConnection * c, LDAPMessage * res)

Local<Value> parseReply(LDAPConnection * c, LDAPMessage * res)
{
HandleScope scope;
LDAPMessage * entry = NULL;
Expand Down Expand Up @@ -447,6 +466,17 @@ class LDAPConnection : public EventEmitter
return scope.Close(js_result_list);
}

int Reconnect(const Arguments& args) {
if (has_reconnect_handler) {
Local<Value> argv[1];

argv[0] = args.This();
reconnect_handler->Call(Context::GetCurrent()->Global(), 1, argv);
} else {
return 1;
}
}

static void
io_event (EV_P_ ev_io *w, int revents)
{
Expand Down

0 comments on commit de8a03d

Please sign in to comment.