[69] in 6.033-lab

home help back first fref pref prev next nref lref last post

Re: 6.033 Lab questions

daemon@ATHENA.MIT.EDU (Constantine Sapuntzakis)
Fri Feb 27 23:21:55 1998

To: Dave <dbb@MIT.EDU>
Cc: 6.033-lab@MIT.EDU
From: Constantine Sapuntzakis <csapuntz@tma-1.lcs.mit.edu>
Date: 26 Feb 1998 17:21:18 -0500
In-Reply-To: Dave's message of Wed, 25 Feb 1998 19:04:07 EST
Resent-To: 6.033-lab-mtg@menelaus.MIT.EDU
Resent-From: "Kevin 'Bob' Fu" <fubob@mit.edu>


Dave <dbb@MIT.EDU> writes:

> Hi there.
> I have a couple more quick questions:
> 1) What's the best way of determining if a connection has
> been closed? I've been running the client program (Except it loops
> indefinately, waiting for input from the server), and control-c'ing it.
> However, I've been using getpeername to detect if a socket has been
> closed or not, and it doesn't seem to recognize that the client
> has closed the socket after I kill the client. Is there a better way
> of detecting this? I suppose i could use read, and make sure it's non
> blocking, test for an error,and then use select, but that seems to
> defeat the purpose of using select to block. Also, if I fork two processes
> to deal with a request (one to listen to the client, one to listen to the
> server), and when one of them detects an error, it closes both the
> socket to the client and the socket to the server, will the other
> process also be able to detect that both sockets are closed and exit as well?

If the client shutdown the side of the connection that writes to your proxy,
the select should return with the file descriptor associated with that
connection ready for reading.

When you do the read, the read will return 0 bytes indicating EOF.

If the server shuts down a connection you are writing to, your write will
return EPIPE.  You will also get SIGPIPE sent to your process, which you have
to catch. You can do this using the signal command.

signal (SIGPIPE, SIG_IGN);

in your initialization code.

> 
> 
> 2) How should I deal with EOFs? The multifinger client could just
> stop, because the EOF indicated the the sucket should be closed.
> Currently, I'm just doing nothing if read received an EOF.
> Is that alright? How would I write an EOF?

Any EOF detected should be propogated. See the "shutdown" command on how to do
this. This means:

1) Received EOF on read from client - shutdown half of socket that writes
to server

2) Received EOF on write to client - shutdown half of socket that reads from
server

3) Received EOF on read from server - shutdown half of socket that writes to
client

4) Received EOF on write to server - shutdown half of socket that reads from
client.

-Costa
csapuntz@mit.edu


home help back first fref pref prev next nref lref last post