Skip to content

Instantly share code, notes, and snippets.

@orlandov
Created March 2, 2010 05:25
Show Gist options
  • Select an option

  • Save orlandov/319164 to your computer and use it in GitHub Desktop.

Select an option

Save orlandov/319164 to your computer and use it in GitHub Desktop.
static int eio_AfterConnect(eio_req *req) {
printf("eio_AfterConnect; rc = %d\n", req->result);
ev_unref(EV_DEFAULT_UC);
}
static int eio_Connect(eio_req *req) {
// Note: this function is executed in the thread pool! CAREFUL
int *foo = (int*)(req->data);
printf("** %p\n", foo);
// this should print 420 but segfaults instead
printf("** %d\n", *(int*)(req->data));
req->result = 666;
return 0;
}
static Handle<Value> Connect(const Arguments& args) {
HandleScope scope;
int *foo = (int *) malloc(sizeof(int));
*foo = 420;
printf("foo is %d\n", *foo);
eio_custom(eio_Connect, EIO_PRI_DEFAULT, eio_AfterConnect, foo);
ev_ref(EV_DEFAULT_UC);
return Undefined();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment