summaryrefslogtreecommitdiff
path: root/src/ICE.chs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2023-04-05 22:03:43 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2023-04-05 22:03:43 +0200
commit7a9ef992afa96ed177ae9a4a67d302017ab73852 (patch)
tree4c53058ce2ae8015db653326996bfc17a906e72e /src/ICE.chs
parenta8893fbcfa06044e7f999916c4dcc6a2dc907f75 (diff)
Fix non-exhaustive pattern match warnings
Diffstat (limited to 'src/ICE.chs')
-rw-r--r--src/ICE.chs20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/ICE.chs b/src/ICE.chs
index 06ad7aa..98584a2 100644
--- a/src/ICE.chs
+++ b/src/ICE.chs
@@ -131,13 +131,19 @@ iceCreate role cb = do
{#fun ice_destroy as ^ { isStrans `IceSession' } -> `()' #}
iceRemoteInfo :: IceSession -> IO IceRemoteInfo
-iceRemoteInfo sess =
- allocaBytes (32*128) $ \bytes ->
- allocaArray 29 $ \carr -> do
- let (ufrag : pass : def : cptrs) = take 32 $ iterate (`plusPtr` 128) bytes
- pokeArray carr cptrs
-
- ncand <- {#call ice_encode_session #} (isStrans sess) ufrag pass def carr 128 29
+iceRemoteInfo sess = do
+ let maxlen = 128
+ maxcand = 29
+
+ allocaBytes maxlen $ \ufrag ->
+ allocaBytes maxlen $ \pass ->
+ allocaBytes maxlen $ \def ->
+ allocaBytes (maxcand*maxlen) $ \bytes ->
+ allocaArray maxcand $ \carr -> do
+ let cptrs = take maxcand $ iterate (`plusPtr` maxlen) bytes
+ pokeArray carr $ take maxcand cptrs
+
+ ncand <- {#call ice_encode_session #} (isStrans sess) ufrag pass def carr (fromIntegral maxlen) (fromIntegral maxcand)
if ncand < 0 then fail "failed to generate ICE remote info"
else IceRemoteInfo
<$> (T.pack <$> peekCString ufrag)