Skip to content

Instantly share code, notes, and snippets.

@kaero
Created July 14, 2013 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaero/5996374 to your computer and use it in GitHub Desktop.
Save kaero/5996374 to your computer and use it in GitHub Desktop.
namespace elmo {
using namespace node;
using namespace v8;
static Handle<Value> get_loop_state(const Arguments& args) {
HandleScope scope;
Local<Array> handles = Array::New();
uv_loop_t *loop = uv_default_loop();
ngx_queue_t* q;
uv_handle_t* h;
const char* type;
int i = 0;
Local<Object> handle_desc;
ngx_queue_foreach(q, &loop->handle_queue) {
h = ngx_queue_data(q, uv_handle_t, handle_queue);
switch (h->type) {
#define X(uc, lc) case UV_##uc: type = #lc; break;
UV_HANDLE_TYPE_MAP(X)
#undef X
default: type = "UNKNOWN";
}
handle_desc = Object::New();
handle_desc->Set(String::NewSymbol("type"),
String::NewSymbol(type));
handle_desc->Set(String::NewSymbol("ref"),
Boolean::New(!(h->flags & UV__HANDLE_REF)));
handle_desc->Set(String::NewSymbol("active"),
Boolean::New(!(h->flags & UV__HANDLE_ACTIVE)));
handle_desc->Set(String::NewSymbol("internal"),
Boolean::New(!(h->flags & UV__HANDLE_INTERNAL)));
handles->Set(i++, handle_desc);
}
return scope.Close(handles);
}
static void init(Handle<Object> exports) {
exports->Set(String::NewSymbol("getLoopState"),
FunctionTemplate::New(node::GetActiveHandles)->GetFunction());
}
} // namespace elmo
NODE_MODULE(elmo, elmo::init)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment