diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-22 05:08:51 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-22 05:08:51 +0400 |
commit | ce8a1546bdcfbbb7c45407e3811cafc99d667ee1 (patch) | |
tree | 226ef8aaec8f15adb71bb5859ae851118b618b59 /src/Network/KRPC | |
parent | ca59e5cfac34d8a59203e91fdd9dd432f537c346 (diff) |
Run each handler in separate thread.
This is needed because handler can call query too. The minimal example:
* listener received KQuery(1);
* listener dispatch corresponding handler;
* handler send KQuery(2);
* handler blocked waiting for response;
* listener is unable to receive KQuery(2) because it is blocked on
handler.
So we should run each handler in separated thread otherwise dead lock
can happen.
Diffstat (limited to 'src/Network/KRPC')
-rw-r--r-- | src/Network/KRPC/Manager.hs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/Network/KRPC/Manager.hs b/src/Network/KRPC/Manager.hs index c63967d0..084a8d8d 100644 --- a/src/Network/KRPC/Manager.hs +++ b/src/Network/KRPC/Manager.hs | |||
@@ -192,7 +192,7 @@ dispatchHandler q @ KQuery {..} addr = do | |||
192 | -----------------------------------------------------------------------} | 192 | -----------------------------------------------------------------------} |
193 | 193 | ||
194 | handleQuery :: MonadKRPC h m => KQuery -> SockAddr -> m () | 194 | handleQuery :: MonadKRPC h m => KQuery -> SockAddr -> m () |
195 | handleQuery q addr = do | 195 | handleQuery q addr = void $ fork $ do |
196 | Manager {..} <- getManager | 196 | Manager {..} <- getManager |
197 | res <- dispatchHandler q addr | 197 | res <- dispatchHandler q addr |
198 | sendMessage sock addr $ either toBEncode toBEncode res | 198 | sendMessage sock addr $ either toBEncode toBEncode res |