Algorithm for reading from continuous stream

From: Chee Liang (cheeliang_at_DIESPAM.iname.com)
Date: 03/01/04


Date: Tue, 02 Mar 2004 00:53:05 +0800

Hi all,

I don't have much experience with reading from continuous stream (I
hope I'm using the right term here) as opposed to nicely packet-ed
methods like readline, gets, fgets, etc. Thus hope to get some ideas
on how to go about doing it.

Say I have a winsock stream, and I wish to read in line by line
(separated by newline). How can I go about doing that neatly? How
about variable sized packets from the socket?

After reading in the 1st time, and processing, I'm sure to have left
over bytes and the end of the buffer. How can I combine this neatly
with the next read from the socket? Circular buffer? I thought of
using a 2*n buffer, but it still might overflow unless every line is
<=n size.

Hope my questions isn't too vaguely phrased.

Thanks a lot!



Relevant Pages

  • CAsyncSocket -> OnReceive -> Receive does not remove data in the queue?
    ... I have data that is send from on socket to another. ... As per the documentation, for every OnReceive(... ... I then handle the buffer of data, I read 8 bytes of data and that ... In other words I am reading the same 4096 bytes again. ...
    (microsoft.public.vc.mfc)
  • Re: client-server using named pipes
    ... network socket and writes that data to a named pipe, ... we read the message from the client into a buffer. ... of reading to a buffer, i want to read the message directly into the ...
    (comp.unix.programmer)
  • Reading bytes from a socket
    ... I have a problem while reading bytes from a socket. ... it seems that the buffer maximum size is 8192 bytes. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: writeBytes hanging on SSL connection?
    ... Write on any socket will block if the reader isn't reading, once you have filled up the socket send buffer. ...
    (comp.lang.java.programmer)
  • Re: Discovering variable types...
    ... >memory it points to is on the heap. ... sequentially reading data, if one is randomly reading records, then a ... >project is what's prompting me to improve disk access. ... from a memory buffer I can do it in about a second. ...
    (comp.lang.pascal.delphi.misc)