Guest User

Untitled

a guest
May 20th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. static int eio_AfterConnect(eio_req *req) {
  2. printf("eio_AfterConnect; rc = %d\n", req->result);
  3. ev_unref(EV_DEFAULT_UC);
  4. }
  5.  
  6. static int eio_Connect(eio_req *req) {
  7. // Note: this function is executed in the thread pool! CAREFUL
  8.  
  9. int *foo = (int*)(req->data);
  10. printf("** %p\n", foo);
  11.  
  12. // this should print 420 but segfaults instead
  13. printf("** %d\n", *(int*)(req->data));
  14.  
  15. req->result = 666;
  16. return 0;
  17. }
  18.  
  19. static Handle<Value> Connect(const Arguments& args) {
  20. HandleScope scope;
  21.  
  22. int *foo = (int *) malloc(sizeof(int));
  23. *foo = 420;
  24.  
  25. printf("foo is %d\n", *foo);
  26.  
  27. eio_custom(eio_Connect, EIO_PRI_DEFAULT, eio_AfterConnect, foo);
  28. ev_ref(EV_DEFAULT_UC);
  29.  
  30. return Undefined();
  31. }
Add Comment
Please, Sign In to add comment