summaryrefslogtreecommitdiff
path: root/src/Network/KRPC
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/KRPC')
-rw-r--r--src/Network/KRPC/Protocol.hs20
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
205type KRemoteAddr = SockAddr 205type KRemoteAddr = SockAddr
206type KRemote = Socket 206type KRemote = Socket
207 207
208sockAddrFamily :: SockAddr -> Family
209sockAddrFamily (SockAddrInet _ _ ) = AF_INET
210sockAddrFamily (SockAddrInet6 _ _ _ _) = AF_INET6
211sockAddrFamily (SockAddrUnix _ ) = AF_UNIX
212
208withRemote :: (MonadBaseControl IO m, MonadIO m) => (KRemote -> m a) -> m a 213withRemote :: (MonadBaseControl IO m, MonadIO m) => (KRemote -> m a) -> m a
209withRemote = bracket (liftIO (socket AF_INET Datagram defaultProtocol)) 214withRemote = 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
214maxMsgSize :: Int 218maxMsgSize :: Int
219--maxMsgSize = 512 -- release: size of payload of one udp packet
220maxMsgSize = 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
219maxMsgSize = 64 * 1024 -- max udp size
220
221 222
222-- TODO eliminate toStrict 223-- TODO eliminate toStrict
223sendMessage :: BEncode msg => msg -> KRemoteAddr -> KRemote -> IO () 224sendMessage :: BEncode msg => msg -> KRemoteAddr -> KRemote -> IO ()
@@ -242,7 +243,10 @@ remoteServer :: (MonadBaseControl IO remote, MonadIO remote)
242remoteServer servAddr action = bracket (liftIO bindServ) (liftIO . sClose) loop 243remoteServer 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