f



read/write error on socket

I have client and server connected.
client write and read from csock.
server write and read from ssock
suppose the server does :
.....
close(ssock);	//send FIN to client
othertask();
.....

READ ERROR

if after the server close() the client does:
....
read(csock,...);
....
read(csock,...);
....
close(csock,...);
....
read(csock,...);
....

first read return 0  (read FIN)

second read also return 0.

third  read return -1 with errno set to EBADF.

QUESTION 1:
Indeed if after the server close() the client does:
.....
write(csock, "hello", 6);	//server send RST
....
read(csock,...);
....
write(csock, ...);

first write return 6 without signaling nothing.

read return:
	0 if the client read before the RST arrives.
	-1 with errno set to ECONNRESET otherwise.

second write comports the SIGPIPE signal.
if it is ignored write return -1 and errno=EPIPE, otherwise it
comports the client termination.
is ok?

IS THE SITUATION THE SAME WHEN THE SERVER CRASH BEFORE THE CLIENT'S
FIRST WRITE?

QUESTION 2:
when read fails with errno=ENOTCONN?

QUESTION 3:
In general if I don't set the timeout option, is possible that a
read() fails with errno=ETIMEDOUT?

WRITE ERROR

when write fails and errno =ECONNRESET??

0
gio
4/6/2007 7:13:57 PM
comp.os.linux.development.apps 5216 articles. 1 followers. Post Follow

1 Replies
707 Views

Similar Articles

[PageSpeed] 37

On Apr 6, 12:13 pm, "gio" <giorginooo.ro...@yahoo.it> wrote:

> QUESTION 1:
> Indeed if after the server close() the client does:
> ....
> write(csock, "hello", 6);     //server send RST
> ...
> read(csock,...);
> ...
> write(csock, ...);
>
> first write return 6 without signaling nothing.
>
> read return:
>         0 if the client read before the RST arrives.
>         -1 with errno set to ECONNRESET otherwise.
>
> second write comports the SIGPIPE signal.
> if it is ignored write return -1 and errno=EPIPE, otherwise it
> comports the client termination.
> is ok?

I'm not sure what you're asking.

> IS THE SITUATION THE SAME WHEN THE SERVER CRASH BEFORE THE CLIENT'S
> FIRST WRITE?

Again, I'm not sure what you're asking.

> QUESTION 2:
> when read fails with errno=ENOTCONN?

Read will fail with ENOTCONN when you pass a socket that must be
connected in order for data to be read (such as a TCP socket) that is
not connected. For example, if a non-blocking 'connect' is in
progress.

> QUESTION 3:
> In general if I don't set the timeout option, is possible that a
> read() fails with errno=ETIMEDOUT?

Yes. A 'read' function will block for as long as it takes for data to
arrive. If while waiting for data to arrive, the TCP connection times
out, the 'read' function will return ETIMEDOUT. There are at least two
ways this can happen. One is if a 'write' is still in progress when
you call 'read' -- if that 'write' times out, the TCP connection times
out. Another is if you have TCP keep alives enabled.

> WRITE ERROR
>
> when write fails and errno =ECONNRESET??

When the connection has been reset by the other end. This can happen
if the other end reboots and the new instance of the OS has no idea
that the connection ever existed. It can also happen if the other side
closes the connection without reading all data.

DS

0
David
4/14/2007 8:28:01 AM
Reply: