@@ -13,18 +13,22 @@ using namespace std;
1313using namespace node ;
1414using namespace v8 ;
1515
16- static Handle<Value> PollpriAsync (const Arguments&);
17- static int Pollpri (eio_req *);
18- // static int PollpriAfter(eio_req *);
19- static void PollpriAfter (ev_io* req, int revents);
16+ static Handle<Value> pollpri (const Arguments&);
17+ static int pollpri_thread (eio_req *);
18+ static int pollpri_after (eio_req *);
19+ // extern "C" void pollpri_event(struct ev_loop* loop, ev_io* req, int revents);
20+ extern " C" void pollpri_event (ev_io* req, int revents);
2021extern " C" void init (Handle<Object>);
2122
2223struct pollpri_request {
23- Persistent<Function> cb ;
24+ Persistent<Function> callback ;
2425 char path[1 ];
2526};
2627
27- static Handle<Value> PollpriAsync (const Arguments& args) {
28+ class Pollpri : public ObjectWrap {
29+ };
30+
31+ static Handle<Value> pollpri (const Arguments& args) {
2832 HandleScope scope;
2933 const char *usage = " usage: pollpri(path, cb)" ;
3034 if (args.Length () != 2 ) {
@@ -39,36 +43,42 @@ static Handle<Value> PollpriAsync(const Arguments& args) {
3943 pr->cb = Persistent<Function>::New (cb);
4044 strncpy (pr->path , *path, path.length () + 1 );
4145
46+ eio_custom (pollpri_thread, EIO_PRI_DEFAULT, pollpri_after, pr);
47+ ev_ref (EV_DEFAULT_UC);
48+ printf (" Leaving pollpri\n " );
49+ return (Undefined ());
50+ }
51+
52+ static int pollpri_thread (eio_req *req) {
53+ printf (" Entered pollpri_thread\n " );
54+ struct pollpri_request * pr = (struct pollpri_request *)req->data ;
4255 int epfd = epoll_create (1 );
4356 int fd = open (pr->path , O_RDWR | O_NONBLOCK);
4457 printf (" open(%s) returned %d: %s\n " , pr->path , fd, strerror (errno));
4558 struct epoll_event ev;
46- struct epoll_event events;
4759 ev.events = EPOLLPRI;
4860 ev.data .fd = fd;
4961 int n = epoll_ctl (epfd, EPOLL_CTL_ADD, fd, &ev);
5062 printf (" epoll_ctl(%d) returned %d (%d): %s\n " , fd, n, epfd, strerror (errno));
5163 ev_io pollpri_watcher;
52- ev_init (&pollpri_watcher, PollpriAfter );
64+ ev_init (&pollpri_watcher, pollpri_event );
5365 pollpri_watcher.data = pr;
54- ev_io_set (&pollpri_watcher, epfd, EV_READ);
66+ ev_io_set (&pollpri_watcher, epfd, EV_READ | EV_WRITE );
5567 ev_io_start (EV_DEFAULT_ &pollpri_watcher);
56-
57- // eio_custom(Pollpri, EIO_PRI_DEFAULT, PollpriAfter, pr );
58- // ev_ref(EV_DEFAULT_UC );
59- printf (" Leaving PollpriAsync \n " );
60- return (Undefined () );
68+ // struct epoll_event events;
69+ // n = epoll_wait(epfd, &events, 1, -1 );
70+ // printf("epoll_wait(%d) returned %d: %s\n", epfd, n, strerror(errno) );
71+ printf (" Leaving pollpri_thread \n " );
72+ return (0 );
6173}
6274
63- static int Pollpri (eio_req *req) {
64- struct pollpri_request * pr = (struct pollpri_request *)req->data ;
65- printf (" Entered Pollpri\n " );
66- return (0 );
75+ extern " C" void pollpri_event (ev_io* req, int revents) {
76+ printf (" Entered pollpri_event\n " );
77+ printf (" Leaving pollpri_event\n " );
6778}
6879
69- // static int PollpriAfter(eio_req *req) {
70- static void PollpriAfter (ev_io* req, int revents) {
71- printf (" Entered PollpriAfter\n " );
80+ static int pollpri_after (eio_req *req) {
81+ printf (" Entered pollpri_after\n " );
7282 HandleScope scope;
7383 // ev_unref(EV_DEFAULT_UC);
7484 struct pollpri_request * pr = (struct pollpri_request *)req->data ;
@@ -78,9 +88,11 @@ static void PollpriAfter(ev_io* req, int revents) {
7888 pr->cb ->Call (Context::GetCurrent ()->Global (), 2 , argv);
7989 // pr->cb.Dispose();
8090 // free(pr);
91+ printf (" Leaving pollpri_after\n " );
92+ return (0 );
8193}
8294
8395extern " C" void init (Handle<Object> target) {
8496 HandleScope scope;
85- NODE_SET_METHOD (target, " pollpri" , PollpriAsync );
97+ NODE_SET_METHOD (target, " pollpri" , pollpri );
8698}
0 commit comments