From: naruse@... Date: 2020-01-28T21:36:53+00:00 Subject: [ruby-core:97013] [Ruby master Feature#16597] missing poll() Issue #16597 has been updated by naruse (Yui NARUSE). akr (Akira Tanaka) wrote: > As far as I know, it is impossible for TCP because shutdown(SHUT_RD) and close() doesn't notify it to the other end of the connection if no unread data. (Please point out me if I'm wrong.) > poll() doesn't help for this problem with TCP. > > (An approximation is getsockopt(TCP_INFO) for Linux which can be used to investigate TCP state of a connection.) > > I'm not sure for pipe but kernel knows that the other end is closed or not. > > What the event flag of poll() you want to use? > https://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html If you want to know a connection is closed, you need to check FIN or RST packet of TCP. They are sent by shutdown(SHUT_WR) or close (hard close) in socket. To detect that, it needs to use poll with POLLHUP flag. Note that it also needs to clear internal buffer before calling poll. On Linux it can use recv with MSG_TRUNC, but on other platform it needs it needs to read all data already received. ---------------------------------------- Feature #16597: missing poll() https://bugs.ruby-lang.org/issues/16597#change-84100 * Author: michals (Michal Such�nek) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- When using a socket or a pipe for writing select() cannot determine that the socket is closed. It tells you that it is ready to write but if you don't have data to write you cannot tell that it is in fact closed. ruby internally uses poll() which can tell when a write socket is closed (without attempting a write()) but presents the broken select() interface. -- https://bugs.ruby-lang.org/ Unsubscribe: