(Phobos - SocketStream) Am I doing something wrong or is this a bug?

BCS none at anon.com
Tue Nov 3 16:35:07 PST 2009


Hello Zane,

> BCS Wrote:
> 
>> Hello Zane,
>> 
>>> While trying to learn sockets in Phobos, I ran into a problem.  I
>>> was trying to download the google logo via an HTTP GET.  when I do a
>>> socketStream.read, the returned "bytes read" value indicates that
>>> less bytes were read in than were available (4097 bytes to be
>>> exact).  The google logo is 8558 bytes in size as indicated by the
>>> HTTP headers received.  Here is my code:
>>> 
>> The network connection might not have all the data yet. Try calling
>> it in a loop kind of like your header reading code.
>> 
> I do not see how this can be the case.  Per the Phobos spec for
> InputStream, "Read a block of data big enough to fill the given array
> buffer. "  This sounds to me like it should do just that, fill my
> array....and not return until done.  readLine needs to be looped
> because it only reads up to a carriage return / newline combination
> (and there are multiple lines).  Can anyone confirm that my
> speculations are correct?  Otherwise, the documentation seems
> misleading and I will need help with a correct implementation.

If I were you, I'd just try the looped version because there might be a bug. 
I seem to recall that the stream stuff in some places gets defined to return 
on out of data conditions. (BTW this would be consistent with the liked named 
"read" function from posix.)

Looking into the code (Stream.read() and SocketStream.readBlock()) it doesn't 
block if there isn't enough data. 

If this is a code bug or a documentation deficiency is another question.





More information about the Digitalmars-d mailing list