diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-10-03 15:36:30 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-10-03 15:36:30 +0400 |
commit | 908a20ca2880a9047f7fbf07e33f18caf53f5109 (patch) | |
tree | 5e13173d96bb08f47b57fb613ec055c2b7eab3c8 /src/Network/KRPC/Protocol.hs | |
parent | fbecd1c50e3b2d721b9c0dd7050680f7fef7294e (diff) |
IPv6 enabled communication
Diffstat (limited to 'src/Network/KRPC/Protocol.hs')
-rw-r--r-- | src/Network/KRPC/Protocol.hs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/Network/KRPC/Protocol.hs b/src/Network/KRPC/Protocol.hs index 108c47c4..32065ff7 100644 --- a/src/Network/KRPC/Protocol.hs +++ b/src/Network/KRPC/Protocol.hs | |||
@@ -205,19 +205,20 @@ kresponse = KResponse . M.fromList | |||
205 | type KRemoteAddr = SockAddr | 205 | type KRemoteAddr = SockAddr |
206 | type KRemote = Socket | 206 | type KRemote = Socket |
207 | 207 | ||
208 | sockAddrFamily :: SockAddr -> Family | ||
209 | sockAddrFamily (SockAddrInet _ _ ) = AF_INET | ||
210 | sockAddrFamily (SockAddrInet6 _ _ _ _) = AF_INET6 | ||
211 | sockAddrFamily (SockAddrUnix _ ) = AF_UNIX | ||
212 | |||
208 | withRemote :: (MonadBaseControl IO m, MonadIO m) => (KRemote -> m a) -> m a | 213 | withRemote :: (MonadBaseControl IO m, MonadIO m) => (KRemote -> m a) -> m a |
209 | withRemote = bracket (liftIO (socket AF_INET Datagram defaultProtocol)) | 214 | withRemote = bracket (liftIO (socket AF_INET6 Datagram defaultProtocol)) |
210 | (liftIO . sClose) | 215 | (liftIO . sClose) |
211 | {-# SPECIALIZE withRemote :: (KRemote -> IO a) -> IO a #-} | 216 | {-# SPECIALIZE withRemote :: (KRemote -> IO a) -> IO a #-} |
212 | 217 | ||
213 | |||
214 | maxMsgSize :: Int | 218 | maxMsgSize :: Int |
219 | --maxMsgSize = 512 -- release: size of payload of one udp packet | ||
220 | maxMsgSize = 64 * 1024 -- bench: max UDP MTU | ||
215 | {-# INLINE maxMsgSize #-} | 221 | {-# INLINE maxMsgSize #-} |
216 | -- release | ||
217 | --maxMsgSize = 512 -- size of payload of one udp packet | ||
218 | -- bench | ||
219 | maxMsgSize = 64 * 1024 -- max udp size | ||
220 | |||
221 | 222 | ||
222 | -- TODO eliminate toStrict | 223 | -- TODO eliminate toStrict |
223 | sendMessage :: BEncode msg => msg -> KRemoteAddr -> KRemote -> IO () | 224 | sendMessage :: BEncode msg => msg -> KRemoteAddr -> KRemote -> IO () |
@@ -242,7 +243,10 @@ remoteServer :: (MonadBaseControl IO remote, MonadIO remote) | |||
242 | remoteServer servAddr action = bracket (liftIO bindServ) (liftIO . sClose) loop | 243 | remoteServer servAddr action = bracket (liftIO bindServ) (liftIO . sClose) loop |
243 | where | 244 | where |
244 | bindServ = do | 245 | bindServ = do |
245 | sock <- socket AF_INET Datagram defaultProtocol | 246 | let family = sockAddrFamily servAddr |
247 | sock <- socket family Datagram defaultProtocol | ||
248 | when (family == AF_INET6) $ do | ||
249 | setSocketOption sock IPv6Only 0 | ||
246 | bindSocket sock servAddr | 250 | bindSocket sock servAddr |
247 | return sock | 251 | return sock |
248 | 252 | ||