0

I have a situation -

There is a TCP connection between A-->B in established state. A sends a few bytes to B and then terminates itself. The B is neither doing send() or recv().

I would like to know if there is a way to know that the connection is broken.

I know that, for broken connections recv() returns '0'. But in the above situation - A has sent some data to B, so the first (one or multiple) recv() would return me the sent data and finally I would get recv() == 0. But I want to know about the broken connection, without having to pump-out all data from the recv-buffer.

  1. I would like to get a notification about the incoming FIN/RST packets
  2. I have keep-alive activated, so I would like to get a notification when the keep-alive packet is unreplied by the partner

Thanks, Sandeep

pppsandeep
  • 11
  • 1
  • 2

1 Answers1

0

Wherever you want to check for the live connection you can try send(fd, buf, 0, 0) i.e send 0 bytes of data. If connection is broken it would fail.

Rohan
  • 52,392
  • 12
  • 90
  • 87
  • If the cconnection is *already known to be broken* at this end it may fail. For example, if there has already been a retransmission timeout, or an RST has been received. This technique won't detect a connection that has just been broken after successful transfers. – user207421 Aug 27 '12 at 21:37
  • Furthermore... I need some 'notification' from the stack when the connection is broken. The design is such that it is not suitable to query the stack via send() or recv(). – pppsandeep Aug 28 '12 at 06:24
  • @pppsandeep Bad luck, there isn't any such thing in TCP. – user207421 Aug 28 '12 at 07:20