Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Socket v6only #18

Merged
merged 1 commit into from

2 participants

@kazu-yamamoto

IPV6_V6ONLY is set to 0 in Network.Socket.socket.
This option must be set between socket() and bind().
If we set this in Network.Socket.bind, there is no choice for users to set it to 1.
Thus, this is set in Network.Socket.socket.

@tibbe tibbe merged commit 51b2c5a into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 28, 2011
  1. @kazu-yamamoto
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 5 deletions.
  1. +4 −4 Network.hs
  2. +7 −1 Network/Socket.hsc
View
8 Network.hs
@@ -160,13 +160,16 @@ connect' host serv = do
#endif
-- | Creates the server side socket which has been bound to the
--- specified port.
+-- specified port.
--
-- NOTE: To avoid the \"Address already in use\"
-- problems popped up several times on the GHC-Users mailing list we
-- set the 'ReuseAddr' socket option on the listening socket. If you
-- don't want this behaviour, please use the lower level
-- 'Network.Socket.listen' instead.
+--
+-- If available, the 'IPv6Only' socket option is set to 0
+-- so that both IPv4 and IPv6 can be accepted with this socket.
listenOn :: PortID -- ^ Port Identifier
-> IO Socket -- ^ Connected Socket
@@ -240,9 +243,6 @@ listen' serv = do
(sClose)
(\sock -> do
setSocketOption sock ReuseAddr 1
-#ifdef HAVE_DECL_IPV6_V6ONLY
- setSocketOption sock IPv6Only 0
-#endif
bindSocket sock (addrAddress addr)
listen sock maxListenQueue
return sock
View
8 Network/Socket.hsc
@@ -402,6 +402,8 @@ 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.
socket :: Family -- Family Name (usually AF_INET)
-> SocketType -- Socket Type (usually Stream)
-> ProtocolNumber -- Protocol Number (getProtocolByName to find value)
@@ -417,7 +419,11 @@ socket family stype protocol = do
# endif
#endif
socket_status <- newMVar NotConnected
- return (MkSocket fd family stype protocol socket_status)
+ let sock = MkSocket fd family stype protocol socket_status
+#ifdef HAVE_DECL_IPV6_V6ONLY
+ when (family == AF_INET6) $ setSocketOption sock IPv6Only 0
+#endif
+ return sock
-- | Build a pair of connected socket objects using the given address
-- family, socket type, and protocol number. Address family, socket
Something went wrong with that request. Please try again.