...
 
Commits (5)
......@@ -175,6 +175,6 @@ StunUsageIceCompatibility agent_to_ice_compatibility (NiceAgent *agent);
StunUsageTurnCompatibility agent_to_turn_compatibility (NiceAgent *agent);
NiceTurnSocketCompatibility agent_to_turn_socket_compatibility (NiceAgent *agent);
void _priv_set_socket_tos (NiceAgent *agent, NiceSocket *sock, gint tos);
void _priv_set_socket_opts (NiceAgent *agent, NiceSocket *sock, Stream *stream);
#endif /*_NICE_AGENT_PRIV_H */
......@@ -1415,7 +1415,7 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
new_socket = nice_udp_bsd_socket_new (&addr);
if (new_socket) {
_priv_set_socket_tos (agent, new_socket, stream->tos);
_priv_set_socket_opts (agent, new_socket, stream);
agent_attach_stream_component_socket (agent, stream,
component, new_socket);
component->sockets= g_slist_append (component->sockets, new_socket);
......@@ -1434,7 +1434,7 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
socket = nice_tcp_bsd_socket_new (agent->main_context, &proxy_server);
if (socket) {
_priv_set_socket_tos (agent, socket, stream->tos);
_priv_set_socket_opts (agent, socket, stream);
if (agent->proxy_type == NICE_PROXY_TYPE_SOCKS5) {
socket = nice_socks5_socket_new (socket, &turn->server,
agent->proxy_username, agent->proxy_password);
......@@ -1452,7 +1452,7 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
socket = nice_tcp_bsd_socket_new (agent->main_context, &turn->server);
if (socket)
_priv_set_socket_tos (agent, socket, stream->tos);
_priv_set_socket_opts (agent, socket, stream);
}
/* The TURN server may be invalid or not listening */
......@@ -2911,50 +2911,78 @@ nice_agent_set_selected_remote_candidate (
}
void
_priv_set_socket_tos (NiceAgent *agent, NiceSocket *sock, gint tos)
_priv_set_socket_opts (NiceAgent *agent, NiceSocket *sock, Stream *stream)
{
if (setsockopt (g_socket_get_fd (sock->fileno), IPPROTO_IP,
IP_TOS, (const char *) &tos, sizeof (tos)) < 0) {
nice_debug ("Agent %p: Could not set socket ToS", agent,
g_strerror (errno));
IP_TOS, (const char *) &stream->tos, sizeof (stream->tos)) < 0) {
nice_debug ("Agent %p: Could not set socket ToS to 0x%X: %s", agent,
stream->tos, g_strerror (errno));
}
#ifdef IPV6_TCLASS
if (setsockopt (g_socket_get_fd (sock->fileno), IPPROTO_IPV6,
IPV6_TCLASS, (const char *) &tos, sizeof (tos)) < 0) {
nice_debug ("Agent %p: Could not set IPV6 socket ToS", agent,
g_strerror (errno));
IPV6_TCLASS, (const char *) &stream->tos, sizeof (stream->tos)) < 0) {
nice_debug ("Agent %p: Could not set IPV6 socket ToS to 0x%X: %s", agent,
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
priv_update_socket_opts (NiceAgent *agent, Stream *stream)
{
GSList *i, *j;
for (i = stream->components; i; i = i->next) {
Component *component = i->data;
for (j = component->sockets; j; j = j->next) {
NiceSocket *socket = j->data;
_priv_set_socket_opts (agent, socket, stream);
}
}
}
void nice_agent_set_stream_tos (NiceAgent *agent,
void
nice_agent_set_stream_tos (NiceAgent *agent,
guint stream_id, gint tos)
{
GSList *i, *j, *k;
Stream *stream;
agent_lock();
for (i = agent->streams; i; i = i->next) {
Stream *stream = i->data;
if (stream->id == stream_id) {
stream->tos = tos;
for (j = stream->components; j; j = j->next) {
Component *component = j->data;
for (k = component->local_candidates; k; k = k->next) {
NiceCandidate *local_candidate = k->data;
_priv_set_socket_tos (agent, local_candidate->sockptr, tos);
}
}
}
stream = agent_find_stream (agent, stream_id);
if (stream && stream->tos != tos) {
stream->tos = tos;
priv_update_socket_opts (agent, stream);
}
agent_unlock();
}
void nice_agent_set_software (NiceAgent *agent, const gchar *software)
void
nice_agent_set_software (NiceAgent *agent, const gchar *software)
{
agent_lock();
......@@ -2967,3 +2995,43 @@ void 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 */
......
......@@ -482,7 +482,7 @@ NiceCandidate *discovery_add_local_host_candidate (
goto errors;
_priv_set_socket_tos (agent, udp_socket, stream->tos);
_priv_set_socket_opts (agent, udp_socket, stream);
agent_attach_stream_component_socket (agent, stream,
component, udp_socket);
......
......@@ -72,6 +72,8 @@ struct _Stream
gchar remote_password[NICE_STREAM_MAX_PWD];
gboolean gathering;
gint tos;
gint sndbuf;
gint rcvbuf;
};
......