summaryrefslogtreecommitdiff
path: root/src/Network/Tox/Crypto/Handlers.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/Tox/Crypto/Handlers.hs')
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs
index 50224178..8975e4dc 100644
--- a/src/Network/Tox/Crypto/Handlers.hs
+++ b/src/Network/Tox/Crypto/Handlers.hs
@@ -39,6 +39,7 @@ import SensibleDir
39import System.FilePath 39import System.FilePath
40import System.Environment 40import System.Environment
41import System.Directory 41import System.Directory
42import System.Timeout
42#ifdef THREAD_DEBUG 43#ifdef THREAD_DEBUG
43import Control.Concurrent.Lifted.Instrument 44import Control.Concurrent.Lifted.Instrument
44#else 45#else
@@ -766,8 +767,9 @@ tryAppendQueueOutgoing getExtra outq msg = do
766 mbWire <- nqToWire outq getExtra nextno be pktno msg 767 mbWire <- nqToWire outq getExtra nextno be pktno msg
767 case mbWire of 768 case mbWire of
768 Just (payload,seqno) -> do 769 Just (payload,seqno) -> do
769 PB.grokOutboundPacket (nqPacketBuffer outq) (PacketSent seqno payload) 770 (isFull,_) <- PB.grokOutboundPacket (nqPacketBuffer outq) (PacketSent seqno payload)
770 return $ OGSuccess payload 771 if isFull then return OGFull
772 else return $ OGSuccess payload
771 Nothing -> return OGEncodeFail 773 Nothing -> return OGEncodeFail
772 774
773 775
@@ -1253,12 +1255,16 @@ sendCrypto crypto session updateLocal cm = do
1253 dput XNetCrypto "sendCrypto: enter " 1255 dput XNetCrypto "sendCrypto: enter "
1254 getOutGoingParam <- nqToWireIO outq 1256 getOutGoingParam <- nqToWireIO outq
1255 dput XNetCrypto "sendCrypto: got the io extra stuff" 1257 dput XNetCrypto "sendCrypto: got the io extra stuff"
1256 r <- atomically $ do 1258 ncTime <- atomically $ readTVar (ncTimeOut session)
1259 r0 <- timeout (ncTime*1000) . atomically $ do
1257 result <- tryAppendQueueOutgoing getOutGoingParam outq cm 1260 result <- tryAppendQueueOutgoing getOutGoingParam outq cm
1258 case result of 1261 case result of
1259 OGSuccess x -> updateLocal >> return (Right x) 1262 OGSuccess x -> updateLocal >> return (Right x)
1260 OGFull -> return (Left "Outgoing packet buffer is full") 1263 OGFull -> retry -- return (Left "Outgoing packet buffer is full")
1261 OGEncodeFail -> return (Left "Failed to encode outgoing packet") 1264 OGEncodeFail -> return (Left "Failed to encode outgoing packet")
1265 let r = case r0 of
1266 Nothing -> Left "Outgoing packet buffer is full"
1267 Just x -> x
1262 case ncSockAddr session of 1268 case ncSockAddr session of
1263 HaveDHTKey saddr -> mapM_ (sendSessionPacket (ncAllSessions session) saddr) r 1269 HaveDHTKey saddr -> mapM_ (sendSessionPacket (ncAllSessions session) saddr) r
1264 _ -> return () 1270 _ -> return ()