43
43
#include "socket.h"
47
nice_socket_recv (NiceSocket *sock, NiceAddress *from, guint len, gchar *buf)
49
return sock->recv (sock, from, len, buf);
53
nice_socket_send (NiceSocket *sock, const NiceAddress *to,
54
guint len, const gchar *buf)
56
return sock->send (sock, to, len, buf);
47
* nice_socket_recv_messages:
48
* @sock: a #NiceSocket
49
* @recv_messages: (array length=n_recv_messages) (out caller-allocates):
50
* array of #NiceInputMessages to return received messages in
51
* @n_recv_messages: number of elements in the @recv_messages array
53
* Receive up to @n_recv_messages message on the socket, in a non-reliable,
54
* non-blocking fashion. The total size of the buffers in each #NiceInputMessage
55
* must be big enough to contain an entire message (65536 bytes), or excess
56
* bytes will be silently dropped.
58
* On success, the number of messages received into @recv_messages is returned,
59
* which may be less than @n_recv_messages if the call would have blocked
60
* part-way through. If the socket would have blocked to begin with, or if
61
* @n_recv_messages is zero, zero is returned. On failure, a negative value is
62
* returned, but no further error information is available. Calling this
63
* function on a socket which has closed is an error, and a negative value is
66
* If a positive N is returned, the first N messages in @recv_messages are
67
* valid. Each valid message is guaranteed to have a non-zero
68
* #NiceInputMessage::length, and its buffers are guaranteed to be filled
69
* sequentially up to that number of bytes If #NiceInputMessage::from was
70
* non-%NULL for a valid message, it may be set to the address of the sender of
71
* that received message.
73
* If the return value is zero or negative, the from return address and length
74
* in every #NiceInputMessage in @recv_messages are guaranteed to be unmodified.
75
* The buffers may have been modified.
77
* The base addresses and sizes of the buffers in a #NiceInputMessage are never
78
* modified. Neither is the base address of #NiceInputMessage::from, nor the
79
* base address and length of the #NiceInputMessage::buffers array.
81
* Returns: number of valid messages returned in @recv_messages, or a negative
87
nice_socket_recv_messages (NiceSocket *sock,
88
NiceInputMessage *recv_messages, guint n_recv_messages)
90
g_return_val_if_fail (sock != NULL, -1);
91
g_return_val_if_fail (n_recv_messages == 0 || recv_messages != NULL, -1);
93
return sock->recv_messages (sock, recv_messages, n_recv_messages);
97
* nice_socket_send_messages:
98
* @sock: a #NiceSocket
99
* @messages: (array length=n_messages) (in caller-allocates):
100
* array of #NiceOutputMessages containing the messages to send
101
* @n_messages: number of elements in the @messages array
103
* Send up to @n_messages on the socket, in a non-reliable, non-blocking
104
* fashion. The total size of the buffers in each #NiceOutputMessage
105
* must be at most the maximum UDP payload size (65535 bytes), or excess
106
* bytes will be silently dropped.
108
* On success, the number of messages transmitted from @messages is returned,
109
* which may be less than @n_messages if the call would have blocked
110
* part-way through. If the socket would have blocked to begin with, or if
111
* @n_messages is zero, zero is returned. On failure, a negative value is
112
* returned, but no further error information is available. Calling this
113
* function on a socket which has closed is an error, and a negative value is
116
* If a positive N is returned, the first N messages in @messages have been
117
* sent in full, and the remaining messages have not been sent at all.
119
* If #NiceOutputMessage::to is specified for a message, that will be used as
120
* the destination address for the message. Otherwise, if %NULL, the default
121
* destination for @sock will be used.
123
* Every field of every #NiceOutputMessage is guaranteed to be unmodified when
124
* this function returns.
126
* Returns: number of messages successfully sent from @messages, or a negative
132
nice_socket_send_messages (NiceSocket *sock, const NiceAddress *to,
133
const NiceOutputMessage *messages, guint n_messages)
135
g_return_val_if_fail (sock != NULL, -1);
136
g_return_val_if_fail (n_messages == 0 || messages != NULL, -1);
138
return sock->send_messages (sock, to, messages, n_messages);
141
/* Convenience wrapper around nice_socket_send_messages(). Returns the number of
142
* bytes sent on success (which will be @len), zero if sending would block, or
145
nice_socket_send (NiceSocket *sock, const NiceAddress *to, gsize len,
148
GOutputVector local_buf = { buf, len };
149
NiceOutputMessage local_message = { &local_buf, 1};
152
ret = sock->send_messages (sock, to, &local_message, 1);