Ticket #23 (new defect)
Opened 4 years ago
`setSocketOption' fails with `Linger' option
| Reported by: | vvv | Owned by: | |
|---|---|---|---|
| Priority: | minor | Milestone: | |
| Component: | network | Version: | |
| Keywords: | Cc: |
Description
setSocketOption uses FFI binding to setsockopt(2):
foreign import CALLCONV unsafe "setsockopt" c_setsockopt :: CInt -> CInt -> CInt -> Ptr CInt -> CInt -> IO CInt
This binding treats OPTVAL (4th argument) as a pointer to `int'. This is fine in most cases excepting the one when `SO_LINGER' option is being set. In the latter case OPTVAL must be a pointer to `struct linger'. (See libc manual.)
Haskell programs that try 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 the code of socket-linger.hs and socket-linger.c.)
Still, the necessity of `SO_LINGER' option is controversial. I think we better just remove `Linger' constructor from `Network/Socket.hsc'.
Note: See
TracTickets for help on using
tickets.
