diff options
author | Jakub Adam <jakub.adam@ktknet.cz> | 2018-10-27 01:10:22 +0200 |
---|---|---|
committer | Jakub Adam <jakub.adam@ktknet.cz> | 2018-10-31 12:45:16 +0100 |
commit | 5aa499206cec322f918d51d157da9b8af5beed22 (patch) | |
tree | e31851f6e1e24293b06b90e60ad365f15fa3cdfd /socket | |
parent | 67771ba2a30ae7247262c252df052468809711eb (diff) | |
download | libnice-5aa499206cec322f918d51d157da9b8af5beed22.tar.gz |
udp-turn: don't re-iterate incoming TURN control messages
After being parsed, a TURN control message turns into a NiceInputMessage
with zero length. Such message doesn't increment the iteration counter i
and so is re-processed in the next iteration, which detects right away
that message->length == 0 and continues to the next element in
recv_messages.
Thus, n_valid_messages variable serves no real purpose and to achieve
the same result we can simply increment the iteration counter after each
message.
Diffstat (limited to 'socket')
-rw-r--r-- | socket/udp-turn.c | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/socket/udp-turn.c b/socket/udp-turn.c index 15b41f2..d2c2cb5 100644 --- a/socket/udp-turn.c +++ b/socket/udp-turn.c @@ -340,7 +340,6 @@ socket_recv_messages (NiceSocket *sock, gint n_messages; guint i; gboolean error = FALSE; - guint n_valid_messages; /* Make sure socket has not been freed: */ g_assert (sock->priv != NULL); @@ -360,7 +359,7 @@ socket_recv_messages (NiceSocket *sock, * Implementing such a path means rewriting the TURN parser (and hence the * STUN message code) to operate on vectors of buffers, rather than a * monolithic buffer. */ - for (i = 0; i < (guint) n_messages; i += n_valid_messages) { + for (i = 0; i < (guint) n_messages; ++i) { NiceInputMessage *message = &recv_messages[i]; NiceSocket *dummy; NiceAddress from; @@ -369,8 +368,6 @@ socket_recv_messages (NiceSocket *sock, gint parsed_buffer_length; gboolean allocated_buffer = FALSE; - n_valid_messages = 1; - if (message->length == 0) continue; @@ -397,13 +394,11 @@ socket_recv_messages (NiceSocket *sock, if (parsed_buffer_length < 0) { error = TRUE; - } else if (parsed_buffer_length == 0) { - /* A TURN control message which needs ignoring. Re-use this - * NiceInputMessage in the next loop iteration. */ - n_valid_messages = 0; - } else { + } else if (parsed_buffer_length > 0) { *message->from = from; } + /* parsed_buffer_length == 0 means this is a TURN control message which + * needs ignoring. */ /* Split up the monolithic buffer again into the caller-provided buffers. */ if (parsed_buffer_length > 0 && allocated_buffer) { |