problems with ghc-5.02 Socket module (SunOS)

Volker Stolz
Mon, 15 Oct 2001 16:07:00 +0200

In local.glasgow-haskell-users, you wrote:
> Fail: invalid argument
> Action: getSocketOption
> Reason: Invalid argument
> even though there IS a listener on the socket
> (other programs can connect to it).
> I have ghc-5.02 (binary package for SunOS)
> Any hints appreciated. how to find out what is invalid?

'truss' says:

connect(3, 0x500BB040, 16, 1)                   Err#150 EINPROGRESS
poll(0xFFBEF500, 1, 134218)                     = 1
getsockopt(3, 65535, 4103, 0x500BB058, 0x500BB064, 1) Err#22 EINVAL

Which is highly suspicious: getsockopt should never return EINVAL,
so something is seriously wrong. The interface is

int getsockopt(int s, int level, int optname, void  *optval,
     socklen_t *optlen);

Notice the last parameter. Passing just "1" can't be right. The
manpage mentions that

For getsockopt(), optlen is a value-result
     parameter, initially  containing  the  size  of  the  buffer
     pointed to by optval, and modified on return to indicate the
     actual size of the value returned. Use  a  0  optval  if  no
     option value is to be supplied or returned.

IMO it should be a pointer to a CInt containing "1".
I'm currently getting ready a source-version of ghc to test this,
but Slowlaris takes ages to build. I'd assume instead of 'alloca'
it should be 'withObject'.
Whatever. Maybe Simon M. finds a solution faster than me?
Volker Stolz * * PGP + S/MIME