summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/QueryResponse.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/Network/QueryResponse.hs b/src/Network/QueryResponse.hs
index e4c73cd8..6df9ac5a 100644
--- a/src/Network/QueryResponse.hs
+++ b/src/Network/QueryResponse.hs
@@ -570,6 +570,30 @@ udpTransport' bind_address = do
570 } 570 }
571 return (tr, sock) 571 return (tr, sock)
572 572
573chanTransport :: (addr -> TChan (x, addr)) -> addr -> TChan (x, addr) -> TVar Bool -> Transport err addr x
574chanTransport chanFromAddr self achan aclosed = Transport
575 { awaitMessage = \kont -> do
576 x <- atomically $ (Just <$> readTChan achan)
577 `orElse`
578 (readTVar aclosed >>= check >> return Nothing)
579 kont $ Right <$> x
580 , sendMessage = \them bs -> do
581 atomically $ writeTChan (chanFromAddr them) (bs,self)
582 , closeTransport = atomically $ writeTVar aclosed True
583 }
584
585-- | Returns a pair of transports linked together to simulate two computers talking to each other.
586testPairTransport :: IO (Transport err SockAddr ByteString, Transport err SockAddr ByteString)
587testPairTransport = do
588 achan <- atomically newTChan
589 bchan <- atomically newTChan
590 aclosed <- atomically $ newTVar False
591 bclosed <- atomically $ newTVar False
592 let a = SockAddrInet 1 1
593 b = SockAddrInet 2 2
594 return ( chanTransport (const bchan) a achan aclosed
595 , chanTransport (const achan) b bchan bclosed )
596
573serializeClient :: Client err meth tid addr x -> IO (Client err meth tid addr x) 597serializeClient :: Client err meth tid addr x -> IO (Client err meth tid addr x)
574serializeClient c = do 598serializeClient c = do
575 mvar <- newMVar () 599 mvar <- newMVar ()