summaryrefslogtreecommitdiff
path: root/src/ICE.chs
diff options
context:
space:
mode:
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)