local_buf.size = len;
local_message.buffers = &local_buf;
local_message.n_buffers = 1;
- local_message.to = addr;
local_message.length = len;
- if (nice_socket_send_messages (sock, &local_message, 1)) {
+ if (nice_socket_send_messages (sock, addr, &local_message, 1)) {
return WR_SUCCESS;
}
} else {
} else if (component->selected_pair.local != NULL) {
NiceSocket *sock;
NiceAddress *addr;
- guint i;
#ifndef NDEBUG
gchar tmpbuf[INET6_ADDRSTRLEN];
sock = component->selected_pair.local->sockptr;
addr = &component->selected_pair.remote->addr;
- /* Set the destination address. FIXME: This is ugly. */
- for (i = 0; i < n_messages; i++) {
- NiceOutputMessage *message = (NiceOutputMessage *) &messages[i];
- message->to = addr;
- }
-
- n_sent_messages = nice_socket_send_messages (sock, messages, n_messages);
+ n_sent_messages = nice_socket_send_messages (sock, addr, messages,
+ n_messages);
if (n_sent_messages < 0) {
g_set_error (&child_error, G_IO_ERROR, G_IO_ERROR_FAILED,
const gchar *buf)
{
GOutputVector local_buf = { buf, len };
- NiceOutputMessage local_message = { &local_buf, 1, NULL, len };
+ NiceOutputMessage local_message = { &local_buf, 1, len };
gint n_sent_messages;
n_sent_messages = nice_agent_send_messages_nonblocking (agent, stream_id,
* which contain data to transmit for this message
* @n_buffers: number of #GOutputVectors in @buffers, or -1 to indicate @buffers
* is %NULL-terminated
- * @to: (allow-none): address of the peer to transmit the message to, or %NULL
- * to use the default address for the outbound socket
* @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 buffers (specifically,
- * @to can be ignored). for non-reliable connections, it represents a single
- * packet to send to the OS.
+ * Represents a single message to transmit on the network. For
+ * reliable connections, this is essentially just an array of
+ * buffer. for non-reliable connections, it represents a single packet
+ * to send to the OS.
*
* @n_buffers may be -1 to indicate that @buffers is terminated by a
* #GOutputVector with a %NULL buffer pointer.
typedef struct {
GOutputVector *buffers;
gint n_buffers;
- const NiceAddress *to;
gsize length;
} NiceOutputMessage;
do {
GOutputVector local_buf = { (const guint8 *) buffer + len, count - len };
- NiceOutputMessage local_message = {
- &local_buf, 1, NULL, count - len
- };
+ NiceOutputMessage local_message = {&local_buf, 1, count - len};
/* Have to unlock while calling into the agent because
* it will take the agent lock which will cause a deadlock if one of
NiceOutputStreamPrivate *priv = NICE_OUTPUT_STREAM (stream)->priv;
NiceAgent *agent; /* owned */
GOutputVector local_buf = { buffer, count };
- NiceOutputMessage local_message = { &local_buf, 1, NULL, count };
+ NiceOutputMessage local_message = { &local_buf, 1, count };
gint n_sent_messages;
/* Closed streams are not writeable. */
static void socket_close (NiceSocket *sock);
static gint socket_recv_messages (NiceSocket *sock,
NiceInputMessage *recv_messages, guint n_recv_messages);
-static gint socket_send_messages (NiceSocket *sock,
+static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to,
const NiceOutputMessage *messages, guint n_messages);
static gboolean socket_is_reliable (NiceSocket *sock);
-static void add_to_be_sent (NiceSocket *sock, const NiceOutputMessage *messages,
- guint n_messages);
+static void add_to_be_sent (NiceSocket *sock, const NiceAddress *to,
+ const NiceOutputMessage *messages, guint n_messages);
static void free_to_be_sent (struct to_be_sent *tbs);
local_bufs.size = strlen (msg);
local_messages.buffers = &local_bufs;
local_messages.n_buffers = 1;
- local_messages.to = NULL;
local_messages.length = local_bufs.size;
- nice_socket_send_messages (priv->base_socket, &local_messages, 1);
+ nice_socket_send_messages (priv->base_socket, NULL, &local_messages, 1);
priv->state = HTTP_STATE_INIT;
g_free (msg);
}
/* Send the pending data */
while ((tbs = g_queue_pop_head (&priv->send_queue))) {
- nice_socket_send (priv->base_socket, &tbs->to,
- tbs->length, tbs->buf);
+ nice_socket_send (priv->base_socket, &tbs->to, tbs->length, tbs->buf);
g_free (tbs->buf);
g_slice_free (struct to_be_sent, tbs);
}
}
static gint
-socket_send_messages (NiceSocket *sock, const NiceOutputMessage *messages,
- guint n_messages)
+socket_send_messages (NiceSocket *sock, const NiceAddress *to,
+ const NiceOutputMessage *messages, guint n_messages)
{
HttpPriv *priv = sock->priv;
if (!priv->base_socket)
return -1;
- return nice_socket_send_messages (priv->base_socket, messages, n_messages);
+ return nice_socket_send_messages (priv->base_socket, to, messages,
+ n_messages);
} else if (priv->state == HTTP_STATE_ERROR) {
return -1;
} else {
- add_to_be_sent (sock, messages, n_messages);
+ add_to_be_sent (sock, to, messages, n_messages);
}
return n_messages;
static void
-add_to_be_sent (NiceSocket *sock, const NiceOutputMessage *messages,
- guint n_messages)
+add_to_be_sent (NiceSocket *sock, const NiceAddress *to,
+ const NiceOutputMessage *messages, guint n_messages)
{
HttpPriv *priv = sock->priv;
guint i;
tbs = g_slice_new0 (struct to_be_sent);
tbs->buf = g_malloc (message->length);
tbs->length = message->length;
- if (message->to)
- tbs->to = *message->to;
+ if (to)
+ tbs->to = *to;
g_queue_push_tail (&priv->send_queue, tbs);
for (j = 0;
static void socket_close (NiceSocket *sock);
static gint socket_recv_messages (NiceSocket *sock,
NiceInputMessage *recv_messages, guint n_recv_messages);
-static gint socket_send_messages (NiceSocket *sock,
+static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to,
const NiceOutputMessage *messages, guint n_messages);
static gboolean socket_is_reliable (NiceSocket *sock);
-static void add_to_be_sent (NiceSocket *sock, const NiceOutputMessage *messages,
- guint n_messages);
+static void add_to_be_sent (NiceSocket *sock, const NiceAddress *to,
+ const NiceOutputMessage *messages, guint n_messages);
static void free_to_be_sent (struct to_be_sent *tbs);
}
static gint
-socket_send_messages (NiceSocket *sock, const NiceOutputMessage *messages,
- guint n_messages)
+socket_send_messages (NiceSocket *sock, const NiceAddress *to,
+ const NiceOutputMessage *messages, guint n_messages)
{
PseudoSSLPriv *priv = sock->priv;
if (priv->base_socket == NULL)
return FALSE;
- return nice_socket_send_messages (priv->base_socket, messages, n_messages);
+ return nice_socket_send_messages (priv->base_socket, to, messages,
+ n_messages);
} else {
- add_to_be_sent (sock, messages, n_messages);
+ add_to_be_sent (sock, to, messages, n_messages);
}
return TRUE;
}
static void
-add_to_be_sent (NiceSocket *sock, const NiceOutputMessage *messages,
- guint n_messages)
+add_to_be_sent (NiceSocket *sock, const NiceAddress *to,
+ const NiceOutputMessage *messages, guint n_messages)
{
PseudoSSLPriv *priv = sock->priv;
guint i;
/* Compact the buffer. */
tbs->buf = g_malloc (message->length);
tbs->length = message->length;
- if (message->to != NULL)
- tbs->to = *message->to;
+ if (to != NULL)
+ tbs->to = *to;
g_queue_push_tail (&priv->send_queue, tbs);
for (j = 0;
* Since: 0.1.5
*/
gint
-nice_socket_send_messages (NiceSocket *sock, const NiceOutputMessage *messages,
- guint n_messages)
+nice_socket_send_messages (NiceSocket *sock, const NiceAddress *to,
+ const NiceOutputMessage *messages, guint n_messages)
{
g_return_val_if_fail (sock != NULL, -1);
g_return_val_if_fail (n_messages == 0 || messages != NULL, -1);
- return sock->send_messages (sock, messages, n_messages);
+ return sock->send_messages (sock, to, messages, n_messages);
}
/* Convenience wrapper around nice_socket_send_messages(). Returns the number of
const gchar *buf)
{
GOutputVector local_buf = { buf, len };
- NiceOutputMessage local_message = { &local_buf, 1, to, len };
+ NiceOutputMessage local_message = { &local_buf, 1, len };
gint ret;
- ret = nice_socket_send_messages (sock, &local_message, 1);
+ ret = sock->send_messages (sock, to, &local_message, 1);
if (ret == 1)
return len;
return ret;
gint (*recv_messages) (NiceSocket *sock,
NiceInputMessage *recv_messages, guint n_recv_messages);
/* As above, @n_messages may be zero. Iff so, @messages may be %NULL. */
- gint (*send_messages) (NiceSocket *sock, const NiceOutputMessage *messages,
- guint n_messages);
+ gint (*send_messages) (NiceSocket *sock, const NiceAddress *to,
+ const NiceOutputMessage *messages, guint n_messages);
gboolean (*is_reliable) (NiceSocket *sock);
void (*close) (NiceSocket *sock);
void *priv;
NiceInputMessage *recv_messages, guint n_recv_messages);
gint
-nice_socket_send_messages (NiceSocket *sock, const NiceOutputMessage *messages,
- guint n_messages);
+nice_socket_send_messages (NiceSocket *sock, const NiceAddress *addr,
+ const NiceOutputMessage *messages, guint n_messages);
gssize
nice_socket_send (NiceSocket *sock, const NiceAddress *addr, gsize len,
const gchar *buf);
static void socket_close (NiceSocket *sock);
static gint socket_recv_messages (NiceSocket *sock,
NiceInputMessage *recv_messages, guint n_recv_messages);
-static gint socket_send_messages (NiceSocket *sock,
+static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to,
const NiceOutputMessage *messages, guint n_messages);
static gboolean socket_is_reliable (NiceSocket *sock);
-static void add_to_be_sent (NiceSocket *sock, const NiceOutputMessage *messages,
- guint n_messages);
+static void add_to_be_sent (NiceSocket *sock, const NiceAddress *to,
+ const NiceOutputMessage *messages, guint n_messages);
static void free_to_be_sent (struct to_be_sent *tbs);
}
static gint
-socket_send_messages (NiceSocket *sock, const NiceOutputMessage *messages,
- guint n_messages)
+socket_send_messages (NiceSocket *sock, const NiceAddress *to,
+ const NiceOutputMessage *messages, guint n_messages)
{
Socks5Priv *priv = sock->priv;
if (priv->base_socket == NULL)
return FALSE;
- return nice_socket_send_messages (priv->base_socket, messages, n_messages);
+ return nice_socket_send_messages (priv->base_socket, to, messages,
+ n_messages);
} else if (priv->state == SOCKS_STATE_ERROR) {
return FALSE;
} else {
- add_to_be_sent (sock, messages, n_messages);
+ add_to_be_sent (sock, to, messages, n_messages);
}
return TRUE;
}
static void
-add_to_be_sent (NiceSocket *sock, const NiceOutputMessage *messages,
- guint n_messages)
+add_to_be_sent (NiceSocket *sock, const NiceAddress *to,
+ const NiceOutputMessage *messages, guint n_messages)
{
Socks5Priv *priv = sock->priv;
guint i;
/* Compact the buffer. */
tbs->buf = g_malloc (message->length);
tbs->length = message->length;
- if (message->to != NULL)
- tbs->to = *message->to;
+ if (to != NULL)
+ tbs->to = *to;
g_queue_push_tail (&priv->send_queue, tbs);
for (j = 0;
static void socket_close (NiceSocket *sock);
static gint socket_recv_messages (NiceSocket *sock,
NiceInputMessage *recv_messages, guint n_recv_messages);
-static gint socket_send_messages (NiceSocket *sock,
+static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to,
const NiceOutputMessage *messages, guint n_messages);
static gboolean socket_is_reliable (NiceSocket *sock);
* dropped if the bandwidth isn't fast enough. So do not send a message in
* multiple chunks. */
static gint
-socket_send_messages (NiceSocket *sock, const NiceOutputMessage *messages,
- guint n_messages)
+socket_send_messages (NiceSocket *sock, const NiceAddress *to,
+ const NiceOutputMessage *messages, guint n_messages)
{
guint i;
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, NULL, local_buf.size
- };
+ NiceOutputMessage local_message = {&local_buf, 1, local_buf.size};
add_to_be_sent (sock, &local_message, 0, TRUE);
free_to_be_sent (tbs);
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, NULL, local_buf.size
- };
+ NiceOutputMessage local_message = {&local_buf, 1, local_buf.size};
add_to_be_sent (sock, &local_message, 0, TRUE);
free_to_be_sent (tbs);
static void socket_close (NiceSocket *sock);
static gint socket_recv_messages (NiceSocket *sock,
NiceInputMessage *recv_messages, guint n_recv_messages);
-static gint socket_send_messages (NiceSocket *sock,
+static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to,
const NiceOutputMessage *messages, guint n_messages);
static gboolean socket_is_reliable (NiceSocket *sock);
}
static gssize
-socket_send_message (NiceSocket *sock, const NiceOutputMessage *message)
+socket_send_message (NiceSocket *sock, const NiceAddress *to,
+ const NiceOutputMessage *message)
{
TurnTcpPriv *priv = sock->priv;
guint8 padbuf[3] = {0, 0, 0};
local_bufs = g_malloc_n (n_bufs + 2, sizeof (GOutputVector));
local_message.buffers = local_bufs;
local_message.n_buffers = n_bufs + 2;
- local_message.to = message->to;
local_message.length = message->length;
/* Copy the existing buffers across. */
local_message.n_buffers--;
}
- ret = nice_socket_send_messages (priv->base_socket, &local_message, 1);
+ ret = nice_socket_send_messages (priv->base_socket, to, &local_message, 1);
g_free (local_bufs);
}
static gint
-socket_send_messages (NiceSocket *sock, const NiceOutputMessage *messages,
- guint n_messages)
+socket_send_messages (NiceSocket *sock, const NiceAddress *to,
+ const NiceOutputMessage *messages, guint n_messages)
{
guint i;
const NiceOutputMessage *message = &messages[i];
gssize len;
- len = socket_send_message (sock, message);
+ len = socket_send_message (sock, to, message);
if (len < 0) {
/* Error. */
static void socket_close (NiceSocket *sock);
static gint socket_recv_messages (NiceSocket *sock,
NiceInputMessage *recv_messages, guint n_recv_messages);
-static gint socket_send_messages (NiceSocket *sock,
+static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to,
const NiceOutputMessage *messages, guint n_messages);
static gboolean socket_is_reliable (NiceSocket *sock);
static gssize
-socket_send_message (NiceSocket *sock, const NiceOutputMessage *message)
+socket_send_message (NiceSocket *sock, const NiceAddress *to,
+ const NiceOutputMessage *message)
{
TurnPriv *priv = (TurnPriv *) sock->priv;
StunMessage msg;
for (; i; i = i->next) {
ChannelBinding *b = i->data;
- if (nice_address_equal (&b->peer, message->to)) {
+ if (nice_address_equal (&b->peer, to)) {
binding = b;
break;
}
}
- nice_address_copy_to_sockaddr (message->to, &sa.addr);
+ nice_address_copy_to_sockaddr (to, &sa.addr);
if (binding) {
if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9 ||
}
} else {
NiceOutputMessage local_message = {
- message->buffers, message->n_buffers, &priv->server_addr,
- message->length
+ message->buffers, message->n_buffers, message->length
};
- ret = nice_socket_send_messages (priv->base_socket, &local_message, 1);
+ ret = nice_socket_send_messages (priv->base_socket, &priv->server_addr,
+ &local_message, 1);
if (ret == 1)
return message->length;
return ret;
if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_GOOGLE &&
priv->current_binding &&
- nice_address_equal (&priv->current_binding->peer, message->to)) {
+ nice_address_equal (&priv->current_binding->peer, to)) {
stun_message_append32 (&msg, STUN_ATTRIBUTE_OPTIONS, 1);
}
}
if (msg_len > 0) {
if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_RFC5766 &&
- !priv_has_permission_for_peer (priv, message->to)) {
- if (!priv_has_sent_permission_for_peer (priv, message->to)) {
- priv_send_create_permission (priv, NULL, message->to);
+ !priv_has_permission_for_peer (priv, to)) {
+ if (!priv_has_sent_permission_for_peer (priv, to)) {
+ priv_send_create_permission (priv, NULL, to);
}
/* enque data */
nice_debug ("enqueuing data");
- socket_enqueue_data(priv, message->to, msg_len, (gchar *)buffer);
+ socket_enqueue_data(priv, to, msg_len, (gchar *)buffer);
return msg_len;
} else {
GOutputVector local_buf = { buffer, msg_len };
- NiceOutputMessage local_message = {
- &local_buf, 1, &priv->server_addr, msg_len
- };
+ NiceOutputMessage local_message = {&local_buf, 1, msg_len};
- ret = nice_socket_send_messages (priv->base_socket, &local_message, 1);
+ ret = nice_socket_send_messages (priv->base_socket, &priv->server_addr,
+ &local_message, 1);
if (ret == 1)
return msg_len;
return ret;
send:
/* Error condition pass through to the base socket. */
- ret = nice_socket_send_messages (priv->base_socket, message, 1);
+ ret = nice_socket_send_messages (priv->base_socket, to, message, 1);
if (ret == 1)
return message->length;
return ret;
}
static gint
-socket_send_messages (NiceSocket *sock, const NiceOutputMessage *messages,
- guint n_messages)
+socket_send_messages (NiceSocket *sock, const NiceAddress *to,
+ const NiceOutputMessage *messages, guint n_messages)
{
guint i;
const NiceOutputMessage *message = &messages[i];
gssize len;
- len = socket_send_message (sock, message);
+ len = socket_send_message (sock, to, message);
if (len < 0) {
/* Error. */
static void socket_close (NiceSocket *sock);
static gint socket_recv_messages (NiceSocket *sock,
NiceInputMessage *recv_messages, guint n_recv_messages);
-static gint socket_send_messages (NiceSocket *sock,
+static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to,
const NiceOutputMessage *messages, guint n_messages);
static gboolean socket_is_reliable (NiceSocket *sock);
}
static gssize
-socket_send_message (NiceSocket *sock, const NiceOutputMessage *message)
+socket_send_message (NiceSocket *sock, const NiceAddress *to,
+ const NiceOutputMessage *message)
{
struct UdpBsdSocketPrivate *priv = sock->priv;
GError *child_error = NULL;
gssize len;
if (!nice_address_is_valid (&priv->niceaddr) ||
- !nice_address_equal (&priv->niceaddr, message->to)) {
+ !nice_address_equal (&priv->niceaddr, to)) {
union {
struct sockaddr_storage storage;
struct sockaddr addr;
} sa;
GSocketAddress *gaddr;
- g_assert (message->to != NULL);
-
if (priv->gaddr)
g_object_unref (priv->gaddr);
- nice_address_copy_to_sockaddr (message->to, &sa.addr);
+ nice_address_copy_to_sockaddr (to, &sa.addr);
gaddr = g_socket_address_new_from_native (&sa.addr, sizeof(sa));
priv->gaddr = gaddr;
if (gaddr == NULL)
return -1;
- priv->niceaddr = *message->to;
+ priv->niceaddr = *to;
}
len = g_socket_send_message (sock->fileno, priv->gaddr, message->buffers,
}
static gint
-socket_send_messages (NiceSocket *sock, const NiceOutputMessage *messages,
- guint n_messages)
+socket_send_messages (NiceSocket *sock, const NiceAddress *to,
+ const NiceOutputMessage *messages, guint n_messages)
{
guint i;
const NiceOutputMessage *message = &messages[i];
gssize len;
- len = socket_send_message (sock, message);
+ len = socket_send_message (sock, to, message);
if (len < 0) {
/* Error. */
g_assert_cmpint (socket_recv (sock, &tmp, 0, NULL), ==, 0);
/* And again with messages. */
- g_assert_cmpint (nice_socket_send_messages (sock,
+ g_assert_cmpint (nice_socket_send_messages (sock, &tmp,
&local_out_message, 0), ==, 0);
- g_assert_cmpint (nice_socket_send_messages (sock, NULL, 0), ==, 0);
+ g_assert_cmpint (nice_socket_send_messages (sock, &tmp, NULL, 0), ==, 0);
g_assert_cmpint (nice_socket_recv_messages (sock,
&local_in_message, 0), ==, 0);
send_messages[i].buffers = send_bufs + i * n_bufs_per_message;
send_messages[i].n_buffers = n_bufs_per_message;
- send_messages[i].to = &tmp;
send_messages[i].length = 0;
}
/* Send multiple packets. */
g_assert_cmpint (
- nice_socket_send_messages (client, send_messages, n_sends), ==,
+ nice_socket_send_messages (client, &tmp, send_messages, n_sends), ==,
expected_n_sent_messages);
/* Receive things. */
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->to = NULL;
message->length = 0;
/* Limit the overall message size to the smaller of (n_bytes / n_messages)