Re: read-sequence from socket



David Reitter <david.reitter@xxxxxxxxx> wrote:
+---------------
| I'm trying to read into a buffer from a socket using `read-sequence'.
|
| I'd like `read-sequence' to stop when there is no more data, and
| the :input-timeout argument to `make-socket' in the current CCL allows
| me to specify a timeout, upon which an error is signalled. However,
| I'm unclear how I would then find out how many bytes were read -
| that's the normal return value of `read-sequence'.
+---------------

You're going to find that doing this with READ-SEQUENCE is likely
to interact badly with the underlying operating system, since if
the timeout exception occurs in the middle of a read the "amount
already read" is not well-defined for many [most?] OSs.

What I would do instead in this case is write your own version
of READ-SEQUENCE which uses whatever underlying "select()/poll()"
calls [or equiv.] intermingled with native "read()"s (which will
be non-blocking if you only issue one when the "select()/poll()"
says there's something there [though if you're really paranoid
you might want to do an FIONREAD "ioctl()" or equiv. to be sure]),
so that the timeouts *only* ever occur during the "select()/poll()"
calls. In that case, you'll have a deterministic count of "amount
already read".


-Rob

p.s. Even with the above, setting a static timeout value which
can properly handle unexpected delays [e.g. temporary routing
loops or route flapping] which can persist for several minutes
is considered by networking experts to be... "interesting", at
the very least. You have been warned. ;-}

-----
Rob Warnock <rpw3@xxxxxxxx>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607

.



Relevant Pages

  • Re: Socket recv() question?
    ... There's a limited amount of RAM in CE devices. ... Configure tx timeout ... increasing the timeout using the select method on the socket descriptor. ... sockets to send binary data from a pc to Pocket PC. ...
    (microsoft.public.windowsce.app.development)
  • Re: Checking for Network Connection
    ... I'm sure there is a timeout option for the socket call, ... after this amount of time"? ...
    (comp.lang.ruby)
  • mod_perl 1: Apache::print() and timeouts
    ... list and the mod_perl Development mailing list, but with no response. ... if I look at the documentation for the "Timeout" directive ... The total amount of time it takes to receive a GET request. ... The amount of time between ACKs on transmissions of TCP packets ...
    (comp.lang.perl.misc)
  • Re: Always On Top/Not Movable/Not Closeable, then not
    ... Now I need to keep it on top and not allow it to be moved or closed, but after a certain amount of time, allow it to be moved until the full timeout where it would automatically close. ... How can I allow the window to be moved without showing the close window button? ... Petr Vileta, Czech republic ...
    (comp.lang.perl.tk)
  • rpc.umntall timeout
    ... I watched at the code to see if I couldn't set a timeout on the sending ... be worth creating an option for this, I don't know if waiting a big amount ... Jeremie Le Hen ... < jeremie at le-hen dot org>< ttz at chchile dot org> ...
    (freebsd-current)