diff options
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/BitTorrent/Tracker/RPC/UDP.hs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/Tracker/RPC/UDP.hs b/src/Network/BitTorrent/Tracker/RPC/UDP.hs index b0f44ec6..a2099ef0 100644 --- a/src/Network/BitTorrent/Tracker/RPC/UDP.hs +++ b/src/Network/BitTorrent/Tracker/RPC/UDP.hs | |||
@@ -118,6 +118,20 @@ instance Default Options where | |||
118 | , optMultiplier = defMultiplier | 118 | , optMultiplier = defMultiplier |
119 | } | 119 | } |
120 | 120 | ||
121 | checkOptions :: Options -> IO () | ||
122 | checkOptions Options {..} = do | ||
123 | unless (optMaxPacketSize > 0) $ do | ||
124 | throwIO $ userError "optMaxPacketSize must be positive" | ||
125 | |||
126 | unless (optMinTimeout > 0) $ do | ||
127 | throwIO $ userError "optMinTimeout must be positive" | ||
128 | |||
129 | unless (optMaxTimeout > 0) $ do | ||
130 | throwIO $ userError "optMaxTimeout must be greater than optMinTimeout" | ||
131 | |||
132 | unless (optMinTimeout > 0) $ do | ||
133 | throwIO $ userError "optMinTimeout must be positive" | ||
134 | |||
121 | {----------------------------------------------------------------------- | 135 | {----------------------------------------------------------------------- |
122 | -- Manager state | 136 | -- Manager state |
123 | -----------------------------------------------------------------------} | 137 | -----------------------------------------------------------------------} |
@@ -162,8 +176,10 @@ resetState Manager {..} = do | |||
162 | where | 176 | where |
163 | err = error "UDP tracker manager closed" | 177 | err = error "UDP tracker manager closed" |
164 | 178 | ||
179 | -- | This function will throw 'IOException' if or | ||
165 | newManager :: Options -> IO Manager | 180 | newManager :: Options -> IO Manager |
166 | newManager opts = do | 181 | newManager opts = do |
182 | checkOptions opts | ||
167 | mgr <- initManager opts | 183 | mgr <- initManager opts |
168 | tid <- forkIO (listen mgr `finally` resetState mgr) | 184 | tid <- forkIO (listen mgr `finally` resetState mgr) |
169 | putMVar (listenerThread mgr) tid | 185 | putMVar (listenerThread mgr) tid |