Re: Is it possible to detect TCP session term without reading pending data?

From: Andrei Voropaev (avorop_at_mail.ru)
Date: 04/16/04


Date: 16 Apr 2004 07:25:53 GMT

On 2004-04-15, aprotopa <aprotopapas@yahoo.com> wrote:
> Hi all -
> I have an application which should only read from a TCP socket if
> condition X is true. But the application should also be able to
> detect if the TCP peer closed the connection from his side.
> The problem happens when condition X is false while the peer
> terminates the connection, but there is data pending to be read on the
> socket. In that case, poll() becomes useless to me because it only
> tells me that there is data to read, not that the connection has been
> terminated.
> Does anyone know a usage of poll() or some other system function
> that would give the application the ability to detect the closed
> connection in this special case?
> I work mostly on Solaris, but ideally I would like to find a
> portable solution to this problem.

Really, it all depends on your specific situation. For example, if you
still write while your X is false, then after your peer has closed
connection 'send' shall return EPIPE (of course if you use MSG_NOSIGNAL
flag). Also poll may set POLLHUP flag. If your application does not
write and your X might be false for long time, then it's better to read
from socket and discard incoming data (your protocol allows discarding,
right ? :)

Andrei



Relevant Pages

  • Why there is no option to set the source (local) address for HttpWebRequest?
    ... I am writing a HTTP client, that will run on a computer with multiple IP ... I want to bind the TCP socket for the HTTP connection to a ... I suggest adding an event that it fired after the creation of the TCP socket ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: non-blocking connect and poll
    ... > connected already may result in error EISCONN (So, ... > to see if connection was successful after socket becomes writable). ... My concern is that if connectfails, and them my poll() shows POLLIN, ...
    (comp.unix.programmer)
  • Re: Linux select command issues
    ... the select command to monitor a tcp socket for incoming data. ... the shutdown simply does not cause the select to return. ... If you want to close the connection it's more straighforward to just ...
    (comp.unix.programmer)
  • strange socket behaviour
    ... I have a short program that the client make a connection to server, a thread is then created to poll any data sent from the server. ... The main thread will close the socket after 5 seconds. ...
    (comp.lang.python)
  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation [try #3]
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... kernel socket family. ... presentation side is left to the client. ... Each connection goes to a particular "service". ...
    (Linux-Kernel)