Questions about select for sockets

Corinna Vinschen corinna-cygwin@cygwin.com
Wed Apr 7 15:31:38 GMT 2021


On Apr  7 10:04, Ken Brown wrote:
> On 4/6/2021 3:36 PM, Corinna Vinschen wrote:
> > On Apr  6 20:24, Corinna Vinschen wrote:
> > > On Apr  6 13:37, Ken Brown wrote:
> > > > On 4/6/2021 12:28 PM, Corinna Vinschen wrote:
> > > > > On Apr  6 11:44, Ken Brown wrote:
> > > > > > On 4/6/2021 10:33 AM, Corinna Vinschen wrote:
> > > > > > > We may also have to change the saw_shutdown_read/saw_shutdown_write
> > > > > > > handling.  I checked this on Linux and what happens is:
> > > > > > > 
> > > > > > >      After shutdown (fd, SHUT_RD), the socket is ready for reading and writing
> > > > > > 
> > > > > > This seems surprising to me.  Is it really the shutdown that caused it to be
> > > > > > ready for writing in your test, or was it ready for writing anyway (e.g.,
> > > > > > because the relevant buffer was empty)?
> > > > > 
> > > > > I guess so, too.  How to make sure the socket isn't ready for writing
> > > > > without going to great lengths?
> > > > 
> > > > I guess you could have a subprocess write to the socket in a loop, so that
> > > > its buffer will quickly fill up and a further write will block.
> > > 
> > > Yeah, I was trying to minimize work, but I now lazily created a blocking
> > > server in the same process with a non-blocking client, calling send(2)
> > > until it fails.
> > > 
> > > And now everything is as expected.  SHUT_RD -> ready for reading,
> > > SHUT_WR -> ready for writing, SHUT_RDWR -> ready for both.
> > > 
> > > I attached my STC, for completeness.  Call with an argument
> > > 0 (== SHUT_RD), 1 (== SHUT_WR), or 2 (== SHUT_RDWR).
> > 
> > I pushed a patch to handle this better.  Please have a look.
> 
> You forgot this:
> 
> --- a/winsup/cygwin/select.cc
> +++ b/winsup/cygwin/select.cc
> @@ -528,6 +528,7 @@ set_bits (select_record *me, fd_set *readfds, fd_set *writefds,
>           if (!me->read_ready && me->read_selected
>               && sock->connect_state () == connect_failed)
>             UNIX_FD_SET (me->fd, readfds);
> +         ready++;
>         }
>        ready++;
>      }

Yeah, I remembered yesterday in the evening but had already forgotten
again this morning :)

Please push this change.


Thanks,
Corinna


More information about the Cygwin-developers mailing list