Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!news.ecn.uoknor.edu!news.wildstar.net!news.ececs.uc.edu!newsfeeds.sol.net!news.maxwell.syr.edu!news.mathworks.com!rill.news.pipex.net!pipex!netcom.net.uk!netcom-uk-feed0!news.enterprise.net!usenet From: Karl Pielorz <karl@skynet.co.uk> Newsgroups: comp.unix.bsd.freebsd.misc Subject: Checking Socket validity under BSD Date: Thu, 06 Mar 1997 16:05:01 +0000 Organization: Enterprise PLC - Internet Services Lines: 45 Message-ID: <331EEB2D.61B8@skynet.co.uk> Reply-To: karl@skynet.co.uk NNTP-Posting-Host: max08-206.enterprise.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.0b2 (WinNT; I) X-Priority: 3 (Normal) Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:36649 Hi, I've written a program that creates & connects a socket to a remote machine, and quite happily reads & writes data to it, mostly in a do{}while loop. The only problem I've got is trying to check to see if the remote machine has closed it's socket... According to the man pages a SIGPIPE would be generated if the socket gets closed / becomes invalid, which will cause most normal threads (that aren't looking for signals like SIGPIPE) to exit, this does happen - but only after you try to write() some data to the socket that's closed... The program uses non-blocking IO and spends most of it's time in a loop like: transferred = read( mysocket, buffer, sizeof( buffer )); if( transferred >0 ){ write( mydestination, buffer, transferred ); } transferred = read( mydestination, buffer, sizeof( buffer )); if( transferred >0 ){ write( mysocket, buffer, transferred ); } (the above is sort of in pseudo code :( What I'd really like to do is have something like: if( is_still_valid( mysocket ){ read ... } The closest I can get is using select() - but it's a bit messy to say the least... If anyone can suggest a better method, any help would be gratefully received... Regards, Karl Pielorz