Commit eaf6341b authored by Olivier Crête's avatar Olivier Crête

agent: Add APIs to set the send and receive buffers of UDP sockets

Adds nice_socket_set_udp_send_buffer() and nice_socket_set_udp_receive_buffer().
These APIs set the SO_SNDBUF and SO_RCVBUF options on UDP sockets.
parent a697e50c
......@@ -2925,6 +2925,25 @@ _priv_set_socket_opts (NiceAgent *agent, NiceSocket *sock, Stream *stream)
stream->tos, g_strerror (errno));
}
#endif
if (stream->sndbuf != 0 &&
g_socket_get_protocol (sock->fileno) == G_SOCKET_PROTOCOL_UDP) {
if (setsockopt (g_socket_get_fd (sock->fileno), SOL_SOCKET,
SO_SNDBUF, (const char *) &stream->sndbuf, sizeof (stream->rcvbuf)) < 0) {
nice_debug ("Agent %p: Could not set socket send buffer to %d: %s", agent,
stream->sndbuf, g_strerror (errno));
}
}
if (stream->rcvbuf != 0 &&
g_socket_get_protocol (sock->fileno) == G_SOCKET_PROTOCOL_UDP) {
if (setsockopt (g_socket_get_fd (sock->fileno), SOL_SOCKET,
SO_RCVBUF, (const char *) &stream->rcvbuf, sizeof (stream->rcvbuf)) < 0) {
nice_debug ("Agent %p: Could not set socket receive buffer to %d: %s",
agent, stream->rcvbuf, g_strerror (errno));
}
}
}
static void
......@@ -2975,3 +2994,43 @@ nice_agent_set_software (NiceAgent *agent, const gchar *software)
agent_unlock ();
}
void
nice_agent_set_stream_udp_recv_buffer (NiceAgent *agent, guint stream_id,
gint rcvbuf)
{
Stream *stream;
agent_lock();
rcvbuf = MAX (1, rcvbuf);
stream = agent_find_stream (agent, stream_id);
if (stream && stream->rcvbuf != rcvbuf) {
stream->rcvbuf = rcvbuf;
priv_update_socket_opts (agent, stream);
}
agent_unlock();
}
void
nice_agent_set_stream_udp_send_buffer (NiceAgent *agent, guint stream_id,
gint sndbuf)
{
Stream *stream;
agent_lock();
sndbuf = MAX (1, sndbuf);
stream = agent_find_stream (agent, stream_id);
if (stream && stream->sndbuf != sndbuf) {
stream->sndbuf = sndbuf;
priv_update_socket_opts (agent, stream);
}
agent_unlock();
}
......@@ -730,7 +730,6 @@ void nice_agent_set_stream_tos (
gint tos);
/**
* nice_agent_set_software:
* @agent: The #NiceAgent Object
......@@ -759,6 +758,40 @@ void nice_agent_set_stream_tos (
*/
void nice_agent_set_software (NiceAgent *agent, const gchar *software);
/**
* nice_agent_set_stream_udp_recv_buffer:
* @agent: The #NiceAgent Object
* @stream_id: The ID of the stream
* @rcvbuf: The size of the receive buffer
*
* Sets the SO_RCVBUF field on the stream's sockets' options. This value may be
* clamped or ignored by the operating system.
*
* Since: 0.1.4
*/
void nice_agent_set_stream_udp_recv_buffer (
NiceAgent *agent,
guint stream_id,
gint rcvbuf);
/**
* nice_agent_set_stream_udp_send_buffer:
* @agent: The #NiceAgent Object
* @stream_id: The ID of the stream
* @sndbuf: The size of the send buffer
*
* Sets the SO_SNDBUF field on the stream's sockets' options. This value may be
* clamped or ignored by the operating system.
*
* Since: 0.1.4
*/
void nice_agent_set_stream_udp_send_buffer (
NiceAgent *agent,
guint stream_id,
gint sndbuf);
G_END_DECLS
#endif /* _AGENT_H */
......
......@@ -72,6 +72,8 @@ struct _Stream
gchar remote_password[NICE_STREAM_MAX_PWD];
gboolean gathering;
gint tos;
gint sndbuf;
gint rcvbuf;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment