[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] Bug in win32_dispatch?



Hi,

We are using libevent in the next scenario:

1) Create nonblocking socket.
2) Call "connect()" on it.
3) Create an event for socket and wait in event_base_dispatch() for socket events.
4) Check for EV_TIMEOUT, EV_READ or EV_WRITE passed to callback.

There is a problem on win32:

When we are connecting to a destination that is not listening on the socket, we receive
EV_WRITE event, which is not correct from my point of view.

The problem is in win32_dispatch from win32select.c:


   res = select(fd_count,
            (struct fd_set*)win32op->readset_out,
            (struct fd_set*)win32op->writeset_out,
            (struct fd_set*)win32op->exset_out, tv);

   EVBASE_ACQUIRE_LOCK(base, th_base_lock);

   event_debug(("%s: select returned %d", __func__, res));

   if (res <= 0) {
       return res;
   }

   if (win32op->readset_out->fd_count) {
       i = rand() % win32op->readset_out->fd_count;
       for (j=0; j<win32op->readset_out->fd_count; ++j) {
           if (++i >= win32op->readset_out->fd_count)
               i = 0;
           s = win32op->readset_out->fd_array[i];
           evmap_io_active(base, s, EV_READ);
       }
   }
   if (win32op->exset_out->fd_count) {
       i = rand() % win32op->exset_out->fd_count;
       for (j=0; j<win32op->exset_out->fd_count; ++j) {
           if (++i >= win32op->exset_out->fd_count)
               i = 0;
           s = win32op->exset_out->fd_array[i];
           evmap_io_active(base, s, EV_WRITE);
       }
   }
   if (win32op->writeset_out->fd_count) {
       SOCKET s;
       i = rand() % win32op->writeset_out->fd_count;
       for (j=0; j<win32op->writeset_out->fd_count; ++j) {
           if (++i >= win32op->writeset_out->fd_count)
               i = 0;
           s = win32op->writeset_out->fd_array[i];
           evmap_io_active(base, s, EV_WRITE);
       }
   }
   return (0);


As you see, EV_WRITE is returned if there is some socket error.

Is this behaviour a bug or "as designed"?

Thanks,
Alexey Simak
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.