Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress setSocketOption IPv6Only errors on all platforms #181

Merged
merged 4 commits into from
Oct 2, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions Network/Socket.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,9 @@ instance Show SockAddr where
-- and protocol number. The address family is usually 'AF_INET',
-- 'AF_INET6', or 'AF_UNIX'. The socket type is usually 'Stream' or
-- 'Datagram'. The protocol number is usually 'defaultProtocol'.
-- If 'AF_INET6' is used, the 'IPv6Only' socket option is set to 0
-- so that both IPv4 and IPv6 can be handled with one socket.
-- If 'AF_INET6' is used and the socket type is 'Stream' or 'Datagram',
-- the 'IPv6Only' socket option is set to 0 so that both IPv4 and IPv6
-- can be handled with one socket.
socket :: Family -- Family Name (usually AF_INET)
-> SocketType -- Socket Type (usually Stream)
-> ProtocolNumber -- Protocol Number (getProtocolByName to find value)
Expand All @@ -320,13 +321,16 @@ socket family stype protocol = do
withSocketsDo $ return ()
let sock = MkSocket fd family stype protocol socket_status
#if HAVE_DECL_IPV6_V6ONLY
-- The default value of the IPv6Only option is platform specific,
-- so we explicitly set it to 0 to provide a common default.
# if defined(mingw32_HOST_OS)
-- the IPv6Only option is only supported on Windows Vista and later,
-- so trying to change it might throw an error
when (family == AF_INET6) $
E.catch (setSocketOption sock IPv6Only 0) $ (\(_ :: E.IOException) -> return ())
-- The IPv6Only option is only supported on Windows Vista and later,
-- so trying to change it might throw an error.
when (family == AF_INET6 && (stype == Stream || stype == Datagram)) $
E.catch (setSocketOption sock IPv6Only 0) $ (\(_ :: E.IOException) -> return ())
# else
when (family == AF_INET6) $ setSocketOption sock IPv6Only 0
when (family == AF_INET6 && (stype == Stream || stype == Datagram)) $
setSocketOption sock IPv6Only 0 `onException` sClose sock
# endif
#endif
return sock
Expand Down