Sorry if the question are ridiculous.
I wrote an network application, i struck with following situation.
The TCP client keep on sending some message (heart beat) every
particular time interval to server and also client keep on monitoring
message from server.
Some time Server suddenly getting proper shutdown by some reason.
Client also getting know that recv() return zero. But client still
trying to send some message over the same socket.
My questions are :
=============
i) Should i make socket as invalid (-1 or less then zero) once
shutdown detected ?
ii) I could see hang / freeze in the application if would client send
any more message once shutdown detected. Is this problem due to
socket been use after shutdown ?
iii) The kernel should keep on track socket information isn't it ? so
hang would not occur and send() or recv() should return.
iv) I was created socket with unblock (time out ) option.
Thanks in advance
Ganesh.
> My questions are :
> =============
> i) Should i make socket as invalid (-1 or less then zero) once
> shutdown detected ?
You need to keep track of the socket value until you 'close' it.
Otherwise, how will you 'close' it?
> ii) I could see hang / freeze in the application if would client send
> any more message once shutdown detected. Is this problem due to
> socket been use after shutdown ?
There should be no problem. After the socket is shutdown, all attempts
to send or receive data through it should immediately fail.
> iii) The kernel should keep on track socket information isn't it ? so
> hang would not occur and send() or recv() should return.
That's correct. However, there are cases where a blocking 'recv' can
block forever. If you don't want this, don't use blocking 'recv'.
(Just because the socket is shutdown at one end, it is not necessarily
shutdown on the other end.) If you use a 'test connectivity' approach,
you cannot use a non-blocking 'recv' unless you use something like
'alarm' to time it out.
> iv) I was created socket with unblock (time out ) option.
I'm not sure what you mean by this. Is this a blocking socket or not?
If you're using a receive timeout socket option, that's not a good
idea. Either use non-blocking operations or 'alarm'. (Or you can have
another thread time out the socket and issue a 'shutdown' operation.
Do not use a 'close' for this purpose!)
DS