Hi, as a pproject for a company I'm writing a tcp/ip application on
linux using C language.
My application has 2 connections as client to remote servers and is by
itself a server "accepting" remote client connections.
I'm using select() mechanism to manage all those connections. Everyting
works nicely until any of the remote sideds disconnects.
In some of such cases, I'm not succeeding to reconnect to this remote as
client or re-accept connection from tjhe remote client.
Reading some documentation on tcp/ip programming, I had the impression
that the select mechanism should detect such remote disconnect event,
thus enabling me to make a further "read" from this socket which should
end in reading 0 bytes. Reading 0 bytes should indicate disconnection
and let me disconnect propperly from my side and try to reconnect.
However, it seems that select does not detect all those disconnect
events and even worse, I can not see any rule behind when it does detect
this and when it does not.
So, I have a couple of questions and I'll most apreciate any assistance.
1. Would you confirm that select, indeed, does not detect each and every
remote disconnection and do you know if there is a rule behind those
cases?
2. If I need to detect those disconnections to react propperly in my
application and I can not rely on select, what would you suggest me to
do? should I use a kind of "ping" mechanism to check every some seconds
if the connection is still "alive"? or may be use multithread instead of
select, where each thread is responsible for each connection source and
instead of select I loop on read from this source and so, can detect
when I read 0 bytes, which is the disconnect indication and react
accordingly?
Does this make sense or you see issues in such implementation also?
Thanks, Rafi.