🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #3344

socket problems

#3344
From: nick black
Date: Wed, 17 Jan 2001 15:24
48 lines
3297 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"
Technical Details
Message-ID: <944dfe$3ib$1@news-int.gatech.edu>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!nntp-relay.ihug.net!ihug.co.nz!news-hog.berkeley.edu!ucberkeley!awabi.library.ucla.edu!134.139.10.31!csulb.edu!gatech!GT-News!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fc89c,e47d06f6d00f7c5,start
X-Google-Attributes: gidfc89c,public
X-Google-Thread: fab93,e47d06f6d00f7c5,start
X-Google-Attributes: gidfab93,public
X-Google-Thread: 10260d,e47d06f6d00f7c5,start
X-Google-Attributes: gid10260d,public
X-Google-ArrivalTime: 2001-01-17 07:25:38 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!nntp-relay.ihug.net!ihug.co.nz!news-hog.berkeley.edu!ucberkeley!awabi.library.ucla.edu!134.139.10.31!csulb.edu!gatech!GT-News!not-for-mail
From: nick black <dank@angband.org>
Newsgroups: comp.unix.programmer,git.cc.talk.c,git.cc.general
Subject: socket problems
Date: 17 Jan 2001 15:24:30 GMT
Organization: the velvet sea
Lines: 48
Message-ID: <944dfe$3ib$1@news-int.gatech.edu>
NNTP-Posting-Host: angband.cnd.gatech.edu
X-Trace: news-int.gatech.edu 979745070 3659 199.77.147.62 (17 Jan 2001 15:24:30 GMT)
X-Complaints-To: usenet@news.gatech.edu
NNTP-Posting-Date: 17 Jan 2001 15:24:30 GMT
Followups-To: comp.unix.programmer
User-Agent: tin/1.4.1-19991201 ("Polish") (UNIX) (Linux/2.2.13 (i686))