diff --git a/moo/kernel/Socket.moo b/moo/kernel/Socket.moo index 511bc5a..b67564d 100644 --- a/moo/kernel/Socket.moo +++ b/moo/kernel/Socket.moo @@ -564,27 +564,7 @@ class ServerSocket(Socket) clisck := (self acceptedSocketClass) __with: fd. clisck beWatched. self onSocketAccepted: clisck from: cliaddr. - } - - (*-------------------------- - clisck := self _accept: cliaddr. - if (clisck notNil) ## if nil, _accept: failed with EWOULDBLOCK/EAGAIN. - { - ## the _accept method doesn't invoke the initialize method. - ## i should invoke it manually here. - clisck initialize. - clisck beWatched. - self onSocketAccepted: clisck from: cliaddr. - - ###if (self.acceptedEventAction notNil) - ####{ - ### clisck beWatched. - ### self.acceptedEventAction value: self value: clisck value: cliaddr. - ### clisck beWatched. - ###} - ###else { clisck close }. }. - ---------------------------*) ]. } @@ -614,9 +594,19 @@ class ServerSocket(Socket) method listen: backlog { - thisProcess addAsyncSemaphore: self.inreadysem. + | n | + + ## If listen is called before the socket handle is + ## added to the multiplexer, a spurious hangup event might + ## be generated. At least, such behavior was observed + ## in linux with epoll in the level trigger mode. + ### System signal: self.inreadysem onInput: self.handle. + ### thisProcess addAsyncSemaphore: self.inreadysem. + ### n := self _listen: backlog. + n := self _listen: backlog. System signal: self.inreadysem onInput: self.handle. - ^self _listen: backlog. + thisProcess addAsyncSemaphore: self.inreadysem. + ^n. } method onSocketAccepted: clisck from: cliaddr diff --git a/moo/lib/exec.c b/moo/lib/exec.c index e8e4eb1..220e75c 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -1354,7 +1354,7 @@ static int delete_sem_from_sem_io_tuple (moo_t* moo, moo_oop_semaphore_t sem, in static void _signal_io_semaphore (moo_t* moo, moo_oop_semaphore_t sem) { moo_oop_process_t proc; - + proc = signal_semaphore (moo, sem); if (moo->processor->active == moo->nil_process && (moo_oop_t)proc != moo->_nil) @@ -1384,26 +1384,25 @@ static void signal_io_semaphore (moo_t* moo, moo_ooi_t io_handle, moo_ooi_t mask moo_ooi_t sem_io_index; sem_io_index = moo->sem_io_map[io_handle]; - - insem = moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_OUTPUT]; - outsem = moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT]; - - if (insem) - { - if ((mask & (MOO_SEMAPHORE_IO_MASK_OUTPUT | MOO_SEMAPHORE_IO_MASK_ERROR)) || - (!outsem && (mask & MOO_SEMAPHORE_IO_MASK_HANGUP))) - { - _signal_io_semaphore (moo, insem); - } - } + insem = moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT]; + outsem = moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_OUTPUT]; if (outsem) { - if (mask & (MOO_SEMAPHORE_IO_MASK_INPUT | MOO_SEMAPHORE_IO_MASK_HANGUP | MOO_SEMAPHORE_IO_MASK_ERROR)) + if ((mask & (MOO_SEMAPHORE_IO_MASK_OUTPUT | MOO_SEMAPHORE_IO_MASK_ERROR)) || + (!insem && (mask & MOO_SEMAPHORE_IO_MASK_HANGUP))) { _signal_io_semaphore (moo, outsem); } } + + if (insem) + { + if (mask & (MOO_SEMAPHORE_IO_MASK_INPUT | MOO_SEMAPHORE_IO_MASK_HANGUP | MOO_SEMAPHORE_IO_MASK_ERROR)) + { + _signal_io_semaphore (moo, insem); + } + } } else { diff --git a/moo/lib/main.c b/moo/lib/main.c index daa7422..5357254 100644 --- a/moo/lib/main.c +++ b/moo/lib/main.c @@ -1041,7 +1041,7 @@ static int _add_poll_fd (moo_t* moo, int fd, int event_mask) /* epoll_wait may return again if the worker thread consumes events. * switch to level-trigger. */ /* TODO: verify if EPOLLLET is desired */ - ev.events |= EPOLLET; + ev.events |= EPOLLET/* | EPOLLRDHUP | EPOLLHUP */; #endif /*ev.data.ptr = (void*)event_data;*/ ev.data.fd = fd;