changed io semaphore signaling code to signal an output semaphore to be triggered upon HANGUP or ERROR if no input semaphore is attached on the IO handle watched

This commit is contained in:
hyunghwan.chung 2018-02-18 15:55:07 +00:00
parent 9531c6a7e8
commit 54747b0d7c
2 changed files with 19 additions and 10 deletions

View File

@ -164,7 +164,8 @@ static MOO_INLINE void vm_cleanup (moo_t* moo)
if ((sem_io_index = moo->sem_io_map[i]) >= 0)
{
MOO_ASSERT (moo, sem_io_index < moo->sem_io_tuple_count);
MOO_ASSERT (moo, moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT] || moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_OUTPUT]);
MOO_ASSERT (moo, moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT] ||
moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_OUTPUT]);
if (moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT])
{
@ -1370,21 +1371,29 @@ static void signal_io_semaphore (moo_t* moo, moo_ooi_t io_handle, moo_ooi_t mask
{
if (io_handle >= 0 && io_handle < moo->sem_io_map_capa && moo->sem_io_map[io_handle] >= 0)
{
moo_oop_semaphore_t sem;
moo_oop_semaphore_t insem, outsem;
moo_ooi_t sem_io_index;
sem_io_index = moo->sem_io_map[io_handle];
sem = moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_OUTPUT];
if (sem && (mask & MOO_SEMAPHORE_IO_MASK_OUTPUT))
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)
{
_signal_io_semaphore (moo, sem);
if ((mask & MOO_SEMAPHORE_IO_MASK_OUTPUT) ||
(!outsem && (mask & (MOO_SEMAPHORE_IO_MASK_HANGUP | MOO_SEMAPHORE_IO_MASK_ERROR))))
{
_signal_io_semaphore (moo, insem);
}
}
sem = moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT];
if (sem && (mask & (MOO_SEMAPHORE_IO_MASK_INPUT | MOO_SEMAPHORE_IO_MASK_HANGUP | MOO_SEMAPHORE_IO_MASK_ERROR)))
if (outsem)
{
_signal_io_semaphore (moo, sem);
if (mask & (MOO_SEMAPHORE_IO_MASK_INPUT | MOO_SEMAPHORE_IO_MASK_HANGUP | MOO_SEMAPHORE_IO_MASK_ERROR))
{
_signal_io_semaphore (moo, outsem);
}
}
}
else

View File

@ -1487,7 +1487,7 @@ static void* iothr_main (void* arg)
memcpy (xtn->ev.buf, xtn->ev.reg.ptr, xtn->ev.reg.len * MOO_SIZEOF(*xtn->ev.buf));
nfds = xtn->ev.reg.len;
MUTEX_UNLOCK (&xtn->ev.reg.pmtx);
n = poll (xtn->ev.buf, nfds, 10000);
n = poll(xtn->ev.buf, nfds, 10000);
if (n > 0)
{
/* compact the return buffer as poll() doesn't */
@ -1727,7 +1727,7 @@ static void vm_muxwait (moo_t* moo, const moo_ntime_t* dur, moo_vmprim_muxwait_c
n = epoll_wait (xtn->ep, xtn->ev.buf, MOO_COUNTOF(xtn->ev.buf), tmout);
#elif defined(USE_POLL)
memcpy (xtn->ev.buf, xtn->ev.reg.ptr, xtn->ev.reg.len * MOO_SIZEOF(*xtn->ev.buf));
n = poll (xtn->ev.buf, xtn->ev.reg.len, tmout);
n = poll(xtn->ev.buf, xtn->ev.reg.len, tmout);
if (n > 0)
{
/* compact the return buffer as poll() doesn't */