Problem with Socket under Linux...

Ian Piumarta ian.piumarta at
Mon Apr 22 12:53:19 UTC 2002

Hi Goran,

> int sqSocketReceiveDataAvailable(SocketPtr s)
> {
>   if (!socketValid(s))
>     return -1;
>   if (SOCKETSTATE(s) == Connected)
>     {
>       if (socketReadable(SOCKET(s)))
>         return true;
>       PSP(s)->pendingEvents|= READ_NOTIFY;
>       aioHandle(SOCKET(s), dataHandler, PSP(s), AIO_RW);
>     }
>   return false;
> }
> I don't really now why this code looks like it does but I do wonder why
> the unix version notifies the readSemaphore even if the socket is not
> "socketReadable".

It probably comes from my misunderstanding of exactly the conditions
under which the semaphore should be signalled.  (As far as I know,
nobody ever specified the behaviour of the socket semaphore stuff in
any kind of rigorous manner -- so I'm basically guessing where to
signal them.)  If the Unix and win behaviours differ then I happily
concede that the win version is probably right.

> I don't really know what aioHandle is/does

It ensures that the socket is select()ed for i/o, which might not be the
case if it has just been connected and no reads were performed before
asking if data is available, or if a read of all available data has just

> but I
> assume it will result in that "notify()" is called which in turn signals
> the readSema.

Correct.  The notify() is done in the function dataHandler().

> Obviously I am missing something fundamental here -
> shouldn't the readSemaphore only be signalled if there is something to
> read?

This should be the case, since the signal happens in the dataHandler which
is only called when select() determines that data is available on the

> On Win32 it seems to never signal the semaphore which also
> seems.... funny. :-)

It depends on the assumptions.  Does polling a socket for data enable
the signaling of its semaphore, or must you actually try to read data
from it first?

I suggest you try commenting out the line

        PSP(s)->pendingEvents|= READ_NOTIFY;

and then run every socket test in your possession to see what works/breaks.

> We have just semi-verified it's a Linux - thing, Jonas here running
> on Win2k does not have it - at least not when doing some simple
> tests.

If you send me your test suite then I'll hack on this at my end.  (I
need to fix a problem with mouse wheels anyway, so this is the perfect
opportunity to look at the socket stuff.)



More information about the Squeak-dev mailing list