Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!milano.sw.mcc.com!lad-shrike!dcj From: dcj@AUSTIN.LOCKHEED.COM (David Jacobson rimux) Newsgroups: comp.unix.programmer Subject: Socket flush... Message-ID: <519@shrike.AUSTIN.LOCKHEED.COM> Date: 22 Mar 91 15:58:15 GMT Organization: Lockheed Austin Div. Lines: 53 ut-emx!rutgers.edu!phri!marob!nsi1!mms ( Michael Sykora ) of Organization: The Nikko Securities Co., International, Inc. Advised me on clearing a socket: > Assuming you are using stream sockets: > > - find the maximum TCP segment size by issuing a getsockopt() call > for TCP_MAXSEG > - set the socket for non-blocking I/O (if it isn't already set) > - call read() for TCP_MAXSEG bytes repeatedly until it returns > < TCP_MAXSEG > - (if read() returned < 0, it's an error, of course) > - (if read() returned >0 but < TCP_MAXSEG, you've cleaned > out the buffer - as of that moment) > - if read() returned a 0 that means that either there was no > data available or that the connection is broken, so you > may need to test for the latter in this case > - reset the socket for blocking I/O, if necessary I have a little different situation than above...maybe someone could shed some light on it: __________ ____________ | "sender" | ---SOCKET---> | "receiver" | |__________| |____________| My sender is writing data to the receiver via a socket. The sender is told by another process that all the data it is currently writing to to the receiver is BAD. Questions: Can I clear the socket from the senders end? Can I read data from a socket I've been writing to and discard it (bidirectional) ? How would you keep the receiver from processing the remaining BAD data its reading from the socket? > Hope this helps, > Mike Sykora Thanx much! Every little bit helps, David Jacobson. ____________________________________ _______________________________________ . | David C. Jacobson =========___/ \___ Lockheed | (512) 386-4267 =======`/ . \' Austin Division | INTERNET: ====/' `\ (LAD) | dcj@shrike.austin.lockheed.com ____________________________________|_______________________________________