diff options
-rw-r--r-- | src/Network/QueryResponse.hs | 24 |
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 | ||
573 | chanTransport :: (addr -> TChan (x, addr)) -> addr -> TChan (x, addr) -> TVar Bool -> Transport err addr x | ||
574 | chanTransport 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. | ||
586 | testPairTransport :: IO (Transport err SockAddr ByteString, Transport err SockAddr ByteString) | ||
587 | testPairTransport = 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 | |||
573 | serializeClient :: Client err meth tid addr x -> IO (Client err meth tid addr x) | 597 | serializeClient :: Client err meth tid addr x -> IO (Client err meth tid addr x) |
574 | serializeClient c = do | 598 | serializeClient c = do |
575 | mvar <- newMVar () | 599 | mvar <- newMVar () |