0

In the server part, how could i detect that an allready connected client(TCP stream) has just disconnect?

Grutt
  • 21
  • 3
  • 1
    Possible duplicate of [Detecting TCP Client Disconnect](https://stackoverflow.com/questions/283375/detecting-tcp-client-disconnect) – Fantastic Mr Fox Jun 20 '18 at 15:09
  • @FantasticMrFox: Does that work for libuv as well? – MSalters Jun 21 '18 at 07:19
  • @MSalters My guess is yes. the answer here https://stackoverflow.com/a/17665015/1294207 is pretty simply, write a bunch and expect to eventually receive a `ECONNRESET` error. This is a TCP problem, not a wrapping lib problem. So the TCP_handle of libuv will likely exhibit the same behaviour. – Fantastic Mr Fox Jun 21 '18 at 07:35

1 Answers1

1

@MSalters, I finally found the answer. The libuv callback function of "uv_read_start" does not return 0 (nread != 0) when the connexion is closed, it returns UV_EOF. In my configuration UV_EOF is -4095. The disconnection happens when nread == UV_EOF. I think it is possible to make a posix read on the FD associated to the handle, but this is not pretty at all (and much more complicated because the IOs are asynchronous...).

Grutt
  • 21
  • 3