diff options
-rw-r--r-- | examples/client-server.tcl | 2 | ||||
-rw-r--r-- | jim-aio.c | 14 | ||||
-rw-r--r-- | jim-eventloop.c | 23 | ||||
-rw-r--r-- | jim-eventloop.h | 2 | ||||
-rw-r--r-- | tests/event.test | 2 |
5 files changed, 19 insertions, 24 deletions
diff --git a/examples/client-server.tcl b/examples/client-server.tcl index 0740773..01b1ed2 100644 --- a/examples/client-server.tcl +++ b/examples/client-server.tcl @@ -34,8 +34,8 @@ if {[os.fork] == 0} { $f writable {} } - $f readable [list onread $f] $f writable [list onwrite $f] + $f readable [list onread $f] alarm 10 catch -signal { @@ -292,16 +292,8 @@ static void JimAioDelProc(Jim_Interp *interp, void *privData) Jim_DecrRefCount(interp, af->filename); #ifdef jim_ext_eventloop - /* remove existing EventHandlers */ - if (af->rEvent) { - Jim_DeleteFileHandler(interp, af->fp); - } - if (af->wEvent) { - Jim_DeleteFileHandler(interp, af->fp); - } - if (af->eEvent) { - Jim_DeleteFileHandler(interp, af->fp); - } + /* remove all existing EventHandlers */ + Jim_DeleteFileHandler(interp, af->fp, JIM_EVENT_READABLE | JIM_EVENT_WRITABLE | JIM_EVENT_EXCEPTION); #endif Jim_Free(af); } @@ -810,7 +802,7 @@ static int aio_eventinfo(Jim_Interp *interp, AioFile * af, unsigned mask, Jim_Ob if (*scriptHandlerObj) { /* Delete old handler */ - Jim_DeleteFileHandler(interp, af->fp); + Jim_DeleteFileHandler(interp, af->fp, mask); *scriptHandlerObj = NULL; } diff --git a/jim-eventloop.c b/jim-eventloop.c index ac45eb5..5681b00 100644 --- a/jim-eventloop.c +++ b/jim-eventloop.c @@ -160,25 +160,28 @@ void Jim_CreateFileHandler(Jim_Interp *interp, FILE * handle, int mask, eventLoop->fileEventHead = fe; } -void Jim_DeleteFileHandler(Jim_Interp *interp, FILE * handle) +/** + * Removes all event handlers for 'handle' that match 'mask'. + */ +void Jim_DeleteFileHandler(Jim_Interp *interp, FILE * handle, int mask) { - Jim_FileEvent *fe, *prev = NULL; + Jim_FileEvent *fe, *next, *prev = NULL; Jim_EventLoop *eventLoop = Jim_GetAssocData(interp, "eventloop"); - fe = eventLoop->fileEventHead; - while (fe) { - if (fe->handle == handle) { + for (fe = eventLoop->fileEventHead; fe; fe = next) { + if (fe->handle == handle && (fe->mask & mask)) { + /* Remove this entry from the list */ if (prev == NULL) - eventLoop->fileEventHead = fe->next; + next = eventLoop->fileEventHead = fe->next; else - prev->next = fe->next; + next = prev->next = fe->next; if (fe->finalizerProc) fe->finalizerProc(interp, fe->clientData); Jim_Free(fe); - return; + continue; } prev = fe; - fe = fe->next; + next = fe->next; } } @@ -448,7 +451,7 @@ int Jim_ProcessEvents(Jim_Interp *interp, int flags) if (mask) { if (fe->fileProc(interp, fe->clientData, mask) != JIM_OK) { /* Remove the element on handler error */ - Jim_DeleteFileHandler(interp, fe->handle); + Jim_DeleteFileHandler(interp, fe->handle, mask); } processed++; /* After an event is processed our file event list diff --git a/jim-eventloop.h b/jim-eventloop.h index 4da5408..99f32f8 100644 --- a/jim-eventloop.h +++ b/jim-eventloop.h @@ -67,7 +67,7 @@ JIM_EXPORT void Jim_CreateFileHandler (Jim_Interp *interp, Jim_FileProc *proc, void *clientData, Jim_EventFinalizerProc *finalizerProc); JIM_EXPORT void Jim_DeleteFileHandler (Jim_Interp *interp, - FILE *handle); + FILE *handle, int mask); JIM_EXPORT jim_wide Jim_CreateTimeHandler (Jim_Interp *interp, jim_wide milliseconds, Jim_TimeProc *proc, void *clientData, diff --git a/tests/event.test b/tests/event.test index b460227..a969f4c 100644 --- a/tests/event.test +++ b/tests/event.test @@ -195,7 +195,7 @@ test event-13.1 "vwait/signal" signal { list [catch -signal { alarm 0.1 # This is just to prevent the vwait from exiting immediately - stdin readable { puts "stdin is readable" } + stdin readable { format test } vwait forever } msg] $msg } {5 SIGALRM} |