reading from socket gives 0 bytes

Kamil Kukura kamk at
Mon Apr 15 08:22:04 UTC 2002

Yanni Jew wrote:

>There was a half-second delay in the line above the code you've
>noted below. I had added the delay to work around a problem I
>had (as explained in the release notes for PostreSQL client).
>Up to now, I had thought it was a problem with the Socket code.
>Now that I look at it, the Socket code seems perfectly reasonable,
>but the #next method needs to be written in a much more robust manner.
>I'm thinking that it needs to re-try the read (N times) before
>giving up. The delay before the data appears on the socket is unpredictable,
>since it depends on the OS and machine configuration. You don't necessarily
>want to change the standardDeadline value, since that could cause
>unacceptable delays in other places.
>Hope that helps. By the way, I've never tried the code under Win2000.
So good news (though someone might take it as bad news) is it works even 
under ms-windows. I was playing with this pre-delay and found for my 
system (PII-450, database is local, version 7.2 running under Cygwin) 
the value of 100ms fits good. But one problem was still there. When 
postmaster process has been freshly started, the first two connections 
simply failed because of this zero length receive. Any other subsequent 
connection was fine. So I changed #next like this:

"        (Delay forMilliseconds: 100) wait."
        (socket waitForDataUntil: Socket standardDeadline) ifFalse: 
[self error: 'timed out getting data'].
        [    | zeroRead |
            lastReadIndex _ socket receiveDataInto: readBuffer.
            (zeroRead _ lastReadIndex = 0) ifTrue: [
                self log: 'next' text: '**** zero length receive from 
socket ****'.
                (Delay forMilliseconds: 100) wait].
            zeroRead ] whileTrue.

I can see the receive of 0 bytes looping for two times. But it only 
happens upon new connection is created. I have written simple connection 
pooling mechanism so it doesn't happen so often.

>P.S. I'm curious what you're doing with PostgreSQL and Squeak.
>For the last few months, I've not worked with Squeak/Postgres, but
>earlier, I was working on a database backed web "thingy". Now, there's
>SWAZOO and SSP, which cover off a few of the things I had in mind.
Well, I fell in love with smalltalk and squeak so hard I switched the 
development of a web application I work on to Comanche/Seaside. First, I 
was disappointed that there's no layer such as ODBC/JDBC with database 
drivers, but I got used to and your client is performing very well.

More information about the Squeak-dev mailing list