[Pkg-telepathy-commits] [libnice] 126/265: Remove the "length" parameter from NiceOutputMessage
Simon McVittie
smcv at debian.org
Wed May 14 12:05:00 UTC 2014
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to branch debian
in repository libnice.
commit 4f456a461b4a36b74683623b9868f803871f254a
Author: Olivier Crête <olivier.crete at collabora.com>
Date: Thu Jan 30 21:21:13 2014 -0500
Remove the "length" parameter from NiceOutputMessage
It was used correctly only half the time anyway
---
agent/agent-priv.h | 6 +++-
agent/agent.c | 91 +++++++++++++++++++++++++++++++-------------------
agent/agent.h | 2 --
agent/outputstream.c | 4 +--
socket/http.c | 11 +++---
socket/pseudossl.c | 14 +++++---
socket/socket.c | 3 +-
socket/socks5.c | 9 ++---
socket/tcp-bsd.c | 39 ++++++++++++----------
socket/tcp-turn.c | 10 +++---
socket/turn.c | 26 ++++++---------
tests/test-bsd.c | 1 -
tests/test-send-recv.c | 28 ++++++++++++----
13 files changed, 142 insertions(+), 102 deletions(-)
diff --git a/agent/agent-priv.h b/agent/agent-priv.h
index cd49489..c35ea5c 100644
--- a/agent/agent-priv.h
+++ b/agent/agent-priv.h
@@ -215,9 +215,13 @@ gsize
memcpy_buffer_to_input_message (NiceInputMessage *message,
const guint8 *buffer, gsize buffer_length);
guint8 *
-compact_input_message (NiceInputMessage *message, gsize *buffer_length);
+compact_input_message (const NiceInputMessage *message, gsize *buffer_length);
guint8 *
compact_output_message (const NiceOutputMessage *message, gsize *buffer_length);
+gsize
+output_message_get_size (const NiceOutputMessage *message);
+
+
#endif /*_NICE_AGENT_PRIV_H */
diff --git a/agent/agent.c b/agent/agent.c
index db88f7e..0c69e33 100644
--- a/agent/agent.c
+++ b/agent/agent.c
@@ -84,7 +84,8 @@
#define MAX_TCP_MTU 1400 /* Use 1400 because of VPNs and we assume IEE 802.3 */
static void
-nice_debug_message_composition (NiceInputMessage *messages, guint n_messages);
+nice_debug_input_message_composition (const NiceInputMessage *messages,
+ guint n_messages);
G_DEFINE_TYPE (NiceAgent, nice_agent, G_TYPE_OBJECT);
@@ -1050,7 +1051,8 @@ pseudo_tcp_socket_send_messages (PseudoTcpSocket *self,
* used in reliable mode, and there is no concept of a ‘message’, but is
* necessary because the calling API has no way of returning to the client
* and indicating that a message was partially sent. */
- if (message->length > pseudo_tcp_socket_get_available_send_space (self)) {
+ if (output_message_get_size (message) >
+ pseudo_tcp_socket_get_available_send_space (self)) {
return i;
}
@@ -1232,7 +1234,7 @@ pseudo_tcp_socket_readable (PseudoTcpSocket *sock, gpointer user_data)
nice_debug ("%s: Client buffers case: Received %d valid messages:",
G_STRFUNC, n_valid_messages);
- nice_debug_message_composition (component->recv_messages,
+ nice_debug_input_message_composition (component->recv_messages,
component->n_recv_messages);
if (n_valid_messages < 0) {
@@ -1292,8 +1294,6 @@ pseudo_tcp_socket_write_packet (PseudoTcpSocket *socket,
if (component->selected_pair.local != NULL) {
NiceSocket *sock;
NiceAddress *addr;
- GOutputVector local_buf;
- NiceOutputMessage local_message;
sock = component->selected_pair.local->sockptr;
@@ -1312,15 +1312,8 @@ pseudo_tcp_socket_write_packet (PseudoTcpSocket *socket,
addr = &component->selected_pair.remote->addr;
- local_buf.buffer = buffer;
- local_buf.size = len;
- local_message.buffers = &local_buf;
- local_message.n_buffers = 1;
- local_message.length = len;
-
- if (nice_socket_send_messages (sock, addr, &local_message, 1)) {
+ if (nice_socket_send (sock, addr, len, buffer))
return WR_SUCCESS;
- }
} else {
nice_debug ("%s: WARNING: Failed to send pseudo-TCP packet from agent %p "
"as no pair has been selected yet.", G_STRFUNC, component->agent);
@@ -2749,13 +2742,14 @@ done:
/* Print the composition of an array of messages. No-op if debugging is
* disabled. */
static void
-nice_debug_message_composition (NiceInputMessage *messages, guint n_messages)
+nice_debug_input_message_composition (const NiceInputMessage *messages,
+ guint n_messages)
{
#ifndef NDEBUG
guint i;
for (i = 0; i < n_messages; i++) {
- NiceInputMessage *message = &messages[i];
+ const NiceInputMessage *message = &messages[i];
guint j;
nice_debug ("Message %p (from: %p, length: %" G_GSIZE_FORMAT ")", message,
@@ -2774,30 +2768,20 @@ nice_debug_message_composition (NiceInputMessage *messages, guint n_messages)
#endif
}
-/* Concatenate all the buffers in the given @recv_message into a single, newly
- * allocated, monolithic buffer which is returned. The length of the new buffer
- * is returned in @buffer_length, and should be equal to the length field of
- * @recv_message.
- *
- * The return value must be freed with g_free(). */
-guint8 *
-compact_input_message (NiceInputMessage *message, gsize *buffer_length)
+static guint8 *
+compact_message (const NiceOutputMessage *message, gsize buffer_length)
{
guint8 *buffer;
gsize offset = 0;
guint i;
- nice_debug ("%s: **WARNING: SLOW PATH**", G_STRFUNC);
- nice_debug_message_composition (message, 1);
-
- *buffer_length = message->length;
- buffer = g_malloc (*buffer_length);
+ buffer = g_malloc (buffer_length);
for (i = 0;
(message->n_buffers >= 0 && i < (guint) message->n_buffers) ||
(message->n_buffers < 0 && message->buffers[i].buffer != NULL);
i++) {
- gsize len = MIN (*buffer_length - offset, message->buffers[i].size);
+ gsize len = MIN (buffer_length - offset, message->buffers[i].size);
memcpy (buffer + offset, message->buffers[i].buffer, len);
offset += len;
}
@@ -2805,6 +2789,25 @@ compact_input_message (NiceInputMessage *message, gsize *buffer_length)
return buffer;
}
+/* Concatenate all the buffers in the given @recv_message into a single, newly
+ * allocated, monolithic buffer which is returned. The length of the new buffer
+ * is returned in @buffer_length, and should be equal to the length field of
+ * @recv_message.
+ *
+ * The return value must be freed with g_free(). */
+guint8 *
+compact_input_message (const NiceInputMessage *message, gsize *buffer_length)
+{
+ nice_debug ("%s: **WARNING: SLOW PATH**", G_STRFUNC);
+ nice_debug_input_message_composition (message, 1);
+
+ /* This works as long as NiceInputMessage is a subset of eNiceOutputMessage */
+
+ *buffer_length = message->length;
+
+ return compact_message ((NiceOutputMessage *) message, *buffer_length);
+}
+
/* Returns the number of bytes copied. Silently drops any data from @buffer
* which doesn’t fit in @message. */
gsize
@@ -2834,7 +2837,7 @@ memcpy_buffer_to_input_message (NiceInputMessage *message,
message->length += len;
}
- nice_debug_message_composition (message, 1);
+ nice_debug_input_message_composition (message, 1);
if (buffer_length > 0) {
g_warning ("Dropped %" G_GSIZE_FORMAT " bytes of data from the end of "
@@ -2855,9 +2858,27 @@ memcpy_buffer_to_input_message (NiceInputMessage *message,
guint8 *
compact_output_message (const NiceOutputMessage *message, gsize *buffer_length)
{
- /* This works as long as NiceInputMessage and NiceOutputMessage are layed out
- * identically. */
- return compact_input_message ((NiceInputMessage *) message, buffer_length);
+ nice_debug ("%s: **WARNING: SLOW PATH**", G_STRFUNC);
+
+ *buffer_length = output_message_get_size (message);
+
+ return compact_message (message, *buffer_length);
+}
+
+gsize
+output_message_get_size (const NiceOutputMessage *message)
+{
+ guint i;
+ gsize message_len = 0;
+
+ /* Find the total size of the message */
+ for (i = 0;
+ (message->n_buffers >= 0 && i < (guint) message->n_buffers) ||
+ (message->n_buffers < 0 && message->buffers[i].buffer != NULL);
+ i++)
+ message_len += message->buffers[i].size;
+
+ return message_len;
}
/**
@@ -3034,7 +3055,7 @@ nice_agent_recv_messages_blocking_or_nonblocking (NiceAgent *agent,
}
nice_debug ("%s: (%s):", G_STRFUNC, blocking ? "blocking" : "non-blocking");
- nice_debug_message_composition (messages, n_messages);
+ nice_debug_input_message_composition (messages, n_messages);
/* Set the component’s receive buffer. */
context = component_dup_io_context (component);
@@ -3320,8 +3341,8 @@ nice_agent_send (
const gchar *buf)
{
GOutputVector local_buf = { buf, len };
- NiceOutputMessage local_message = { &local_buf, 1, len };
gint n_sent_messages;
+ NiceOutputMessage local_message = { &local_buf, 1 };
n_sent_messages = nice_agent_send_messages_nonblocking (agent, stream_id,
component_id, &local_message, 1, NULL, NULL);
diff --git a/agent/agent.h b/agent/agent.h
index cc025ec..bd10bec 100644
--- a/agent/agent.h
+++ b/agent/agent.h
@@ -176,7 +176,6 @@ typedef struct {
* which contain data to transmit for this message
* @n_buffers: number of #GOutputVectors in @buffers, or -1 to indicate @buffers
* is %NULL-terminated
- * @length: total number of valid bytes contiguously stored in @buffers
*
* Represents a single message to transmit on the network. For
* reliable connections, this is essentially just an array of
@@ -197,7 +196,6 @@ typedef struct {
typedef struct {
GOutputVector *buffers;
gint n_buffers;
- gsize length;
} NiceOutputMessage;
diff --git a/agent/outputstream.c b/agent/outputstream.c
index f8109b6..3ffe469 100644
--- a/agent/outputstream.c
+++ b/agent/outputstream.c
@@ -403,7 +403,7 @@ nice_output_stream_write (GOutputStream *stream, const void *buffer, gsize count
do {
GOutputVector local_buf = { (const guint8 *) buffer + len, count - len };
- NiceOutputMessage local_message = {&local_buf, 1, count - len};
+ NiceOutputMessage local_message = {&local_buf, 1};
/* Have to unlock while calling into the agent because
* it will take the agent lock which will cause a deadlock if one of
@@ -523,7 +523,7 @@ nice_output_stream_write_nonblocking (GPollableOutputStream *stream,
NiceOutputStreamPrivate *priv = NICE_OUTPUT_STREAM (stream)->priv;
NiceAgent *agent; /* owned */
GOutputVector local_buf = { buffer, count };
- NiceOutputMessage local_message = { &local_buf, 1, count };
+ NiceOutputMessage local_message = { &local_buf, 1 };
gint n_sent_messages;
/* Closed streams are not writeable. */
diff --git a/socket/http.c b/socket/http.c
index e2cde3e..b5c44f1 100644
--- a/socket/http.c
+++ b/socket/http.c
@@ -43,6 +43,7 @@
#endif
#include "http.h"
+#include "agent-priv.h"
#include <string.h>
#include <stdlib.h>
@@ -165,7 +166,6 @@ nice_http_socket_new (NiceSocket *base_socket,
local_bufs.size = strlen (msg);
local_messages.buffers = &local_bufs;
local_messages.n_buffers = 1;
- local_messages.length = local_bufs.size;
nice_socket_send_messages (priv->base_socket, NULL, &local_messages, 1);
priv->state = HTTP_STATE_INIT;
@@ -266,7 +266,6 @@ memcpy_ring_buffer_to_input_messages (HttpPriv *priv,
message->buffers[j].size =
memcpy_ring_buffer_to_buffer (priv,
message->buffers[j].buffer, message->buffers[j].size);
- message->length += message->buffers[j].size;
}
}
@@ -618,15 +617,15 @@ add_to_be_sent (NiceSocket *sock, const NiceAddress *to,
const NiceOutputMessage *message = &messages[i];
struct to_be_sent *tbs = NULL;
guint j;
- gsize message_len_remaining = message->length;
+ gsize message_len_remaining = output_message_get_size (message);
gsize offset = 0;
- if (message->length == 0)
+ if (message_len_remaining == 0)
continue;
tbs = g_slice_new0 (struct to_be_sent);
- tbs->buf = g_malloc (message->length);
- tbs->length = message->length;
+ tbs->buf = g_malloc (message_len_remaining);
+ tbs->length = message_len_remaining;
if (to)
tbs->to = *to;
g_queue_push_tail (&priv->send_queue, tbs);
diff --git a/socket/pseudossl.c b/socket/pseudossl.c
index 8128719..4b3f7ef 100644
--- a/socket/pseudossl.c
+++ b/socket/pseudossl.c
@@ -43,6 +43,7 @@
#endif
#include "pseudossl.h"
+#include "agent-priv.h"
#include <string.h>
@@ -229,12 +230,15 @@ add_to_be_sent (NiceSocket *sock, const NiceAddress *to,
const NiceOutputMessage *message = &messages[i];
guint j;
gsize offset = 0;
+ gsize message_len;
tbs = g_slice_new0 (struct to_be_sent);
- /* Compact the buffer. */
- tbs->buf = g_malloc (message->length);
- tbs->length = message->length;
+ message_len = output_message_get_size (message);
+
+ /* Compact the buffer. */
+ tbs->buf = g_malloc (message_len);
+ tbs->length = message_len;
if (to != NULL)
tbs->to = *to;
g_queue_push_tail (&priv->send_queue, tbs);
@@ -246,12 +250,12 @@ add_to_be_sent (NiceSocket *sock, const NiceAddress *to,
const GOutputVector *buffer = &message->buffers[j];
gsize len;
- len = MIN (message->length - offset, buffer->size);
+ len = MIN (message_len - offset, buffer->size);
memcpy (tbs->buf + offset, buffer->buffer, len);
offset += len;
}
- g_assert_cmpuint (offset, ==, message->length);
+ g_assert (offset == message_len);
}
}
diff --git a/socket/socket.c b/socket/socket.c
index afd5037..92ee15a 100644
--- a/socket/socket.c
+++ b/socket/socket.c
@@ -146,7 +146,7 @@ nice_socket_send (NiceSocket *sock, const NiceAddress *to, gsize len,
const gchar *buf)
{
GOutputVector local_buf = { buf, len };
- NiceOutputMessage local_message = { &local_buf, 1, len };
+ NiceOutputMessage local_message = { &local_buf, 1};
gint ret;
ret = sock->send_messages (sock, to, &local_message, 1);
@@ -169,4 +169,3 @@ nice_socket_free (NiceSocket *sock)
g_slice_free (NiceSocket,sock);
}
}
-
diff --git a/socket/socks5.c b/socket/socks5.c
index 563ef25..3ecc04a 100644
--- a/socket/socks5.c
+++ b/socket/socks5.c
@@ -43,6 +43,7 @@
#endif
#include "socks5.h"
+#include "agent-priv.h"
#include <string.h>
@@ -463,8 +464,8 @@ add_to_be_sent (NiceSocket *sock, const NiceAddress *to,
tbs = g_slice_new0 (struct to_be_sent);
/* Compact the buffer. */
- tbs->buf = g_malloc (message->length);
- tbs->length = message->length;
+ tbs->length = output_message_get_size (message);
+ tbs->buf = g_malloc (tbs->length);
if (to != NULL)
tbs->to = *to;
g_queue_push_tail (&priv->send_queue, tbs);
@@ -476,12 +477,12 @@ add_to_be_sent (NiceSocket *sock, const NiceAddress *to,
const GOutputVector *buffer = &message->buffers[j];
gsize len;
- len = MIN (message->length - offset, buffer->size);
+ len = MIN (tbs->length - offset, buffer->size);
memcpy (tbs->buf + offset, buffer->buffer, len);
offset += len;
}
- g_assert_cmpuint (offset, ==, message->length);
+ g_assert (offset == tbs->length);
}
}
diff --git a/socket/tcp-bsd.c b/socket/tcp-bsd.c
index 64b2d46..3a08874 100644
--- a/socket/tcp-bsd.c
+++ b/socket/tcp-bsd.c
@@ -78,7 +78,7 @@ static gboolean socket_is_reliable (NiceSocket *sock);
static void add_to_be_sent (NiceSocket *sock, const NiceOutputMessage *message,
- gsize message_offset, gboolean head);
+ gsize message_offset, gsize message_len, gboolean head);
static void free_to_be_sent (struct to_be_sent *tbs);
static gboolean socket_send_more (GSocket *gsocket, GIOCondition condition,
gpointer data);
@@ -258,12 +258,15 @@ socket_send_message (NiceSocket *sock, const NiceOutputMessage *message)
TcpPriv *priv = sock->priv;
gssize ret;
GError *gerr = NULL;
+ gsize message_len;
/* Don't try to access the socket if it had an error, otherwise we risk a
* crash with SIGPIPE (Broken pipe) */
if (priv->error)
return -1;
+ message_len = output_message_get_size (message);
+
/* First try to send the data, don't send it later if it can be sent now
* this way we avoid allocating memory on every send */
if (g_queue_is_empty (&priv->send_queue)) {
@@ -274,15 +277,15 @@ socket_send_message (NiceSocket *sock, const NiceOutputMessage *message)
if (g_error_matches (gerr, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK) ||
g_error_matches (gerr, G_IO_ERROR, G_IO_ERROR_FAILED)) {
/* Queue the message and send it later. */
- add_to_be_sent (sock, message, 0, FALSE);
- ret = message->length;
+ add_to_be_sent (sock, message, 0, message_len, FALSE);
+ ret = message_len;
}
g_error_free (gerr);
- } else if ((gsize) ret < message->length) {
+ } else if ((gsize) ret < message_len) {
/* Partial send. */
- add_to_be_sent (sock, message, ret, TRUE);
- ret = message->length;
+ add_to_be_sent (sock, message, ret, message_len, TRUE);
+ ret = message_len;
}
} else {
/* FIXME: This dropping will break http/socks5/etc
@@ -305,8 +308,8 @@ socket_send_message (NiceSocket *sock, const NiceOutputMessage *message)
}
/* Queue the message and send it later. */
- add_to_be_sent (sock, message, 0, FALSE);
- ret = message->length;
+ add_to_be_sent (sock, message, 0, message_len, FALSE);
+ ret = message_len;
}
return ret;
@@ -389,9 +392,9 @@ socket_send_more (
if (gerr != NULL &&
g_error_matches (gerr, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
GOutputVector local_buf = { tbs->buf, tbs->length };
- NiceOutputMessage local_message = {&local_buf, 1, local_buf.size};
+ NiceOutputMessage local_message = {&local_buf, 1};
- add_to_be_sent (sock, &local_message, 0, TRUE);
+ add_to_be_sent (sock, &local_message, 0, local_buf.size, TRUE);
free_to_be_sent (tbs);
g_error_free (gerr);
break;
@@ -399,9 +402,9 @@ socket_send_more (
g_error_free (gerr);
} else if (ret < (int) tbs->length) {
GOutputVector local_buf = { tbs->buf + ret, tbs->length - ret };
- NiceOutputMessage local_message = {&local_buf, 1, local_buf.size};
+ NiceOutputMessage local_message = {&local_buf, 1};
- add_to_be_sent (sock, &local_message, 0, TRUE);
+ add_to_be_sent (sock, &local_message, 0, local_buf.size, TRUE);
free_to_be_sent (tbs);
break;
}
@@ -424,22 +427,24 @@ socket_send_more (
/* Queue data starting at byte offset @message_offset from @message’s
- * buffers. */
+ * buffers.
+ *
+ * Returns the message's length */
static void
add_to_be_sent (NiceSocket *sock, const NiceOutputMessage *message,
- gsize message_offset, gboolean head)
+ gsize message_offset, gsize message_len, gboolean head)
{
TcpPriv *priv = sock->priv;
struct to_be_sent *tbs;
guint j;
gsize offset = 0;
- if (message_offset >= message->length)
+ if (message_offset >= message_len)
return;
tbs = g_slice_new0 (struct to_be_sent);
- tbs->buf = g_malloc (message->length - message_offset);
- tbs->length = message->length - message_offset;
+ tbs->length = message_len - message_offset;
+ tbs->buf = g_malloc (tbs->length);
tbs->can_drop = !head;
if (head)
diff --git a/socket/tcp-turn.c b/socket/tcp-turn.c
index 58be7b1..8532538 100644
--- a/socket/tcp-turn.c
+++ b/socket/tcp-turn.c
@@ -250,7 +250,6 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
local_bufs = g_malloc_n (n_bufs + 2, sizeof (GOutputVector));
local_message.buffers = local_bufs;
local_message.n_buffers = n_bufs + 2;
- local_message.length = message->length;
/* Copy the existing buffers across. */
for (j = 0; j < n_bufs; j++) {
@@ -260,11 +259,10 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
/* Header buffer. */
if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_GOOGLE) {
- header_buf = htons (message->length);
+ header_buf = htons (output_message_get_size (message));
local_bufs[0].buffer = &header_buf;
local_bufs[0].size = sizeof (header_buf);
- local_message.length += sizeof (header_buf);
} else {
/* Skip over the allocated header buffer. */
local_message.buffers++;
@@ -274,11 +272,11 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
/* Tail buffer. */
if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9 ||
priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_RFC5766) {
- gsize padlen = (message->length % 4) ? 4 - (message->length % 4) : 0;
+ gsize message_len = output_message_get_size (message);
+ gsize padlen = (message_len % 4) ? 4 - (message_len % 4) : 0;
local_bufs[n_bufs].buffer = &padbuf;
local_bufs[n_bufs].size = padlen;
- local_message.length += padlen;
} else {
/* Skip over the allocated tail buffer. */
local_message.n_buffers--;
@@ -289,7 +287,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
g_free (local_bufs);
if (ret == 1)
- return local_message.length;
+ return output_message_get_size (&local_message);
return ret;
}
diff --git a/socket/turn.c b/socket/turn.c
index 46ce895..fc24765 100644
--- a/socket/turn.c
+++ b/socket/turn.c
@@ -576,16 +576,18 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
if (binding) {
if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9 ||
priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_RFC5766) {
- if (message->length + sizeof(uint32_t) <= sizeof(buffer)) {
+ gsize message_len = output_message_get_size (message);
+
+ if (message_len + sizeof(uint32_t) <= sizeof(buffer)) {
guint j;
uint16_t len16, channel16;
gsize message_offset = 0;
- len16 = htons ((uint16_t) message->length);
+ len16 = htons ((uint16_t) message_len);
channel16 = htons (binding->channel);
memcpy (buffer, &channel16, sizeof(uint16_t));
- memcpy (buffer + sizeof(uint16_t), &len16,sizeof(uint16_t));
+ memcpy (buffer + sizeof(uint16_t), &len16, sizeof(uint16_t));
/* FIXME: Slow path! This should be replaced by code which manipulates
* the GOutputVector array, rather than the buffer contents
@@ -597,25 +599,21 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
const GOutputVector *out_buf = &message->buffers[j];
gsize out_len;
- out_len = MIN (message->length - message_offset, out_buf->size);
+ out_len = MIN (message_len - message_offset, out_buf->size);
memcpy (buffer + sizeof (uint32_t) + message_offset,
out_buf->buffer, out_len);
message_offset += out_len;
}
- msg_len = message->length + sizeof(uint32_t);
+ msg_len = message_len + sizeof(uint32_t);
} else {
return 0;
}
} else {
- NiceOutputMessage local_message = {
- message->buffers, message->n_buffers, message->length
- };
-
ret = nice_socket_send_messages (priv->base_socket, &priv->server_addr,
- &local_message, 1);
+ message, 1);
if (ret == 1)
- return message->length;
+ return output_message_get_size (message);
return ret;
}
} else {
@@ -708,7 +706,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
return msg_len;
} else {
GOutputVector local_buf = { buffer, msg_len };
- NiceOutputMessage local_message = {&local_buf, 1, msg_len};
+ NiceOutputMessage local_message = {&local_buf, 1};
ret = nice_socket_send_messages (priv->base_socket, &priv->server_addr,
&local_message, 1);
@@ -722,7 +720,7 @@ send:
/* Error condition pass through to the base socket. */
ret = nice_socket_send_messages (priv->base_socket, to, message, 1);
if (ret == 1)
- return message->length;
+ return output_message_get_size (message);
return ret;
}
@@ -915,8 +913,6 @@ nice_turn_socket_parse_recv_message (NiceSocket *sock, NiceSocket **from_sock,
message->buffers[0].buffer != NULL &&
message->buffers[1].buffer == NULL)) {
/* Fast path. Single massive buffer. */
- g_assert_cmpuint (message->length, <=, message->buffers[0].size);
-
len = nice_turn_socket_parse_recv (sock, from_sock,
message->from, message->length, message->buffers[0].buffer,
message->from, message->buffers[0].buffer, message->length);
diff --git a/tests/test-bsd.c b/tests/test-bsd.c
index 50c2b42..fbb0813 100644
--- a/tests/test-bsd.c
+++ b/tests/test-bsd.c
@@ -273,7 +273,6 @@ test_multi_message_recv (guint n_sends, guint n_receives,
send_messages[i].buffers = send_bufs + i * n_bufs_per_message;
send_messages[i].n_buffers = n_bufs_per_message;
- send_messages[i].length = 0;
}
/* Set up the receive buffers. Yay for dynamic tests! */
diff --git a/tests/test-send-recv.c b/tests/test-send-recv.c
index 8fac9de..917c56e 100644
--- a/tests/test-send-recv.c
+++ b/tests/test-send-recv.c
@@ -549,12 +549,12 @@ generate_messages_to_transmit (TestIOStreamThreadData *data,
NiceOutputMessage *message = &((*messages)[i]);
guint j;
gsize max_message_size;
+ gsize message_len = 0;
message->n_buffers =
generate_buffer_count (test_data->transmit.buffer_count_strategy,
test_data->transmit_size_rand, buffer_offset);
message->buffers = g_malloc_n (message->n_buffers, sizeof (GOutputVector));
- message->length = 0;
/* Limit the overall message size to the smaller of (n_bytes / n_messages)
* and MAX_MESSAGE_SIZE, to ensure each message is non-empty. */
@@ -572,12 +572,12 @@ generate_messages_to_transmit (TestIOStreamThreadData *data,
buf_len =
MIN (buf_len,
test_data->n_bytes - test_data->transmitted_bytes - total_buf_len);
- buf_len = MIN (buf_len, max_message_size - message->length);
+ buf_len = MIN (buf_len, max_message_size - message_len);
buffer->size = buf_len;
buf = g_malloc (buffer->size);
buffer->buffer = buf;
- message->length += buf_len;
+ message_len += buf_len;
total_buf_len += buf_len;
/* Fill it with data. */
@@ -587,13 +587,13 @@ generate_messages_to_transmit (TestIOStreamThreadData *data,
buffer_offset += buf_len;
/* Reached the maximum UDP payload size? */
- if (message->length >= max_message_size) {
+ if (message_len >= max_message_size) {
message->n_buffers = j + 1;
break;
}
}
- g_assert_cmpuint (message->length, <=, max_message_size);
+ g_assert_cmpuint (message_len, <=, max_message_size);
}
}
@@ -613,6 +613,22 @@ notify_transmitted_buffer (TestIOStreamThreadData *data, gsize buffer_offset,
g_free (*buf);
}
+static gsize
+output_message_get_size (const NiceOutputMessage *message)
+{
+ guint i;
+ gsize message_len = 0;
+
+ /* Find the total size of the message */
+ for (i = 0;
+ (message->n_buffers >= 0 && i < (guint) message->n_buffers) ||
+ (message->n_buffers < 0 && message->buffers[i].buffer != NULL);
+ i++)
+ message_len += message->buffers[i].size;
+
+ return message_len;
+}
+
/* Similar to notify_transmitted_buffer(), except it operates on an array of
* messages from generate_messages_to_transmit(). */
static void
@@ -632,7 +648,7 @@ notify_transmitted_messages (TestIOStreamThreadData *data, gsize buffer_offset,
guint j;
if (i < (guint) n_sent_messages)
- test_data->transmitted_bytes += message->length;
+ test_data->transmitted_bytes += output_message_get_size (message);
for (j = 0; j < (guint) message->n_buffers; j++) {
GOutputVector *buffer = &message->buffers[j];
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-telepathy/libnice.git
More information about the Pkg-telepathy-commits
mailing list