🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.programmer
1 messages
1 total messages Started by nick black Wed, 17 Jan 2001 15:25
socket problems
#3345
Author: nick black
Date: Wed, 17 Jan 2001 15:25
48 lines
3243 bytes
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"
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads