[network] `setSocketOption' fails with `Linger' option

Johan Tibell johan.tibell at gmail.com
Sun Dec 13 12:37:43 EST 2009


Would you mind filing a ticket for this as well now when the trac
instance is working?

Thanks a lot!

-- Johan

On Mon, Nov 30, 2009 at 3:49 PM, Valery V. Vorotyntsev
<valery.vv at gmail.com> wrote:
> See http://is.gd/57Ptu (Network.Socket.setSocketOption).
>
> `setSocketOption' uses FFI binding to setsockopt(2), named
> `c_setsockopt'.
>
>> foreign import CALLCONV unsafe "setsockopt"
>>   c_setsockopt :: CInt -> CInt -> CInt -> Ptr CInt -> CInt -> IO CInt
>
> The binding treats OPTVAL (4th argument) as a pointer to `int'. This
> is mostly fine but not when `SO_LINGER' option is being set. In the
> latter case OPTVAL must be a pointer to `struct linger'. [1]
>
>  [1] http://www.gnu.org/s/libc/manual/html_node/Socket_002dLevel-Options.html
>
> Haskell programs trying to set SO_LINGER socket option will
> successfully compile but fail in runtime.
>
>    $ runhaskell socket-linger.hs || echo X
>    $ runhaskell -DLINGER socket-linger.hs || echo X
>    socket-linger.hs: setSocketOption: invalid argument (Invalid argument)
>    X
>
>    $ gcc -g -Wall -W -o /tmp/1 socket-linger.c && /tmp/1 || echo X
>    $ gcc -g -DLINGER_AS_INT -Wall -W -o /tmp/1 socket-linger.c &&
> /tmp/1 || echo X
>    setsockopt: Invalid argument
>    X
>
> (See attached files `socket-linger.c', `socket-linger.hs'.)
>
> The necessity of `SO_LINGER' option is controversial (see [2]).
> I think it is better to comment the `Linger' constructor out of
> Network/Socket.hsc.
>
>  [2] http://www.developerweb.net/forum/archive/index.php/t-2982.html
>
> Cheers.
>
> --
> vvv
>


More information about the Libraries mailing list