Socket flush...

David Jacobson rimux dcj at AUSTIN.LOCKHEED.COM
Sat Mar 23 01:58:15 AEST 1991


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 at shrike.austin.lockheed.com
____________________________________|_______________________________________



More information about the Comp.unix.programmer mailing list