Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

socket problems

1 view
Skip to first unread message

nick black

unread,
Jan 17, 2001, 10:24:30 AM1/17/01
to
i'm doing what should be some relatively simple socket code, and am
honestly embarassed by this bug. the client/server pair here is but
part of a large system, but i'm almost completely sure the bug can be
localized to these two components, and slightly less sure it is purely
on the client side (the client is standalone, while the server is one of
many threads).

following some authentication and data exchange, which works perfectly,
the client sends a final command, recieves output from the server, and
shuts down (the client). the data exchange previous to this is to
facilitate changes to a virtual machine held elsewhere in the server
side; the data is not signifigant, but this exchange is done
exclusively using read(2) and write(2). these operations go as planned,
and all data (which changes from run to run) is transfered correctly, as
verified by debugging output and expected changes to the environment.
on the final transfer, however, we've got what amounts to:

/* server side previous stuffs */
/* writen just keeps writing and accounts for EAGAIN */
if(writen(control_fd,msg.ustring,msg.current)<0){
/* error */
}
if(close(control_fd)<0){
/* error */
}
/* loop back to accept, get new connection, etc */

/* client side previous stuffs */
while((ret=read(sd,buf,BUFSIZ))>0)){
/* do stuff with output, some may still be coming */
}
if(ret<0){
perror("couldn't read result from server: ");
}
/* close socket, exit */

at this point, the client sometimes sees the output, sometimes not, but
always dies with a broken pipe (EPIPE on read() return). i know writing
to a closed socket generates EPIPE, but a read? furthermore, the
server's close(2) should flush buffers and to a tcp active close, which
should be detected by the client and generate an EOF return of 0,
correct? anyone see what's wrong?

--
nick black * head developer, trellis network security * www.angband.org/~dank
"who can unlearn all the facts that i've learned? i sat in their chairs and my
synapses burned...thoughts follow my vision and dance in the sun; can this wait
'til i'm old? can i live while i'm young?" -phish, "chalkdust torture"

nick black

unread,
Jan 17, 2001, 10:25:46 AM1/17/01
to
0 new messages