summaryrefslogtreecommitdiff
path: root/pjnath
diff options
context:
space:
mode:
authorNanang Izzuddin <nanang@teluu.com>2013-06-19 09:06:55 +0000
committerNanang Izzuddin <nanang@teluu.com>2013-06-19 09:06:55 +0000
commit1229122bc17bb86b6a10e043aa3505715b797347 (patch)
treeae8a72fe1f020f77c31514b05fbd98af2fdcd434 /pjnath
parentd7aa4332dae06ae890053dd13239ddabee46b86c (diff)
Close #1681:
- Added compile-time settings PJMEDIA_TRANSPORT_SO_RCVBUF_SIZE and PJMEDIA_TRANSPORT_SO_SNDBUF_SIZE. The default values are both 64 KB when PJMEDIA_HAS_VIDEO is set, otherwise just zero (socket buffer size uses OS default). The settings will be applied to media transport UDP and ICE. - Also added run-time settings so_sndbuf_size and so_rcvbuf_size into ICE stream transport, STUN socket, and TURN socket. Default values are all zero. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4538 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjnath')
-rw-r--r--pjnath/include/pjnath/ice_strans.h34
-rw-r--r--pjnath/include/pjnath/stun_sock.h20
-rw-r--r--pjnath/include/pjnath/turn_sock.h20
-rw-r--r--pjnath/src/pjnath/ice_strans.c20
-rw-r--r--pjnath/src/pjnath/stun_sock.c40
-rw-r--r--pjnath/src/pjnath/turn_sock.c40
6 files changed, 174 insertions, 0 deletions
diff --git a/pjnath/include/pjnath/ice_strans.h b/pjnath/include/pjnath/ice_strans.h
index 11cfc5db..fe38ff58 100644
--- a/pjnath/include/pjnath/ice_strans.h
+++ b/pjnath/include/pjnath/ice_strans.h
@@ -370,6 +370,40 @@ typedef struct pj_ice_strans_cfg
*/
pj_qos_params qos_params;
+ /**
+ * Specify target value for socket receive buffer size. It will be
+ * applied using setsockopt(). When it fails to set the specified
+ * size, it will try with lower value until the highest possible is
+ * successfully set.
+ *
+ * When this is set to zero, this component will apply socket receive
+ * buffer size settings specified in STUN and TURN socket config
+ * above, i.e: \a stun::cfg::so_rcvbuf_size and
+ * \a turn::cfg::so_rcvbuf_size. Otherwise, this setting will be
+ * applied to STUN and TURN sockets for this component, overriding
+ * the setting specified in STUN/TURN socket config.
+ *
+ * Default: 0
+ */
+ unsigned so_rcvbuf_size;
+
+ /**
+ * Specify target value for socket send buffer size. It will be
+ * applied using setsockopt(). When it fails to set the specified
+ * size, it will try with lower value until the highest possible is
+ * successfully set.
+ *
+ * When this is set to zero, this component will apply socket send
+ * buffer size settings specified in STUN and TURN socket config
+ * above, i.e: \a stun::cfg::so_sndbuf_size and
+ * \a turn::cfg::so_sndbuf_size. Otherwise, this setting will be
+ * applied to STUN and TURN sockets for this component, overriding
+ * the setting specified in STUN/TURN socket config.
+ *
+ * Default: 0
+ */
+ unsigned so_sndbuf_size;
+
} comp[PJ_ICE_MAX_COMP];
} pj_ice_strans_cfg;
diff --git a/pjnath/include/pjnath/stun_sock.h b/pjnath/include/pjnath/stun_sock.h
index 30e94a2d..081f36d5 100644
--- a/pjnath/include/pjnath/stun_sock.h
+++ b/pjnath/include/pjnath/stun_sock.h
@@ -295,6 +295,26 @@ typedef struct pj_stun_sock_cfg
*/
pj_bool_t qos_ignore_error;
+ /**
+ * Specify target value for socket receive buffer size. It will be
+ * applied using setsockopt(). When it fails to set the specified size,
+ * it will try with lower value until the highest possible is
+ * successfully set.
+ *
+ * Default: 0 (OS default)
+ */
+ unsigned so_rcvbuf_size;
+
+ /**
+ * Specify target value for socket send buffer size. It will be
+ * applied using setsockopt(). When it fails to set the specified size,
+ * it will try with lower value until the highest possible is
+ * successfully set.
+ *
+ * Default: 0 (OS default)
+ */
+ unsigned so_sndbuf_size;
+
} pj_stun_sock_cfg;
diff --git a/pjnath/include/pjnath/turn_sock.h b/pjnath/include/pjnath/turn_sock.h
index 96990baa..eddac515 100644
--- a/pjnath/include/pjnath/turn_sock.h
+++ b/pjnath/include/pjnath/turn_sock.h
@@ -166,6 +166,26 @@ typedef struct pj_turn_sock_cfg
*/
pj_uint16_t port_range;
+ /**
+ * Specify target value for socket receive buffer size. It will be
+ * applied using setsockopt(). When it fails to set the specified size,
+ * it will try with lower value until the highest possible has been
+ * successfully set.
+ *
+ * Default: 0 (OS default)
+ */
+ unsigned so_rcvbuf_size;
+
+ /**
+ * Specify target value for socket send buffer size. It will be
+ * applied using setsockopt(). When it fails to set the specified size,
+ * it will try with lower value until the highest possible has been
+ * successfully set.
+ *
+ * Default: 0 (OS default)
+ */
+ unsigned so_sndbuf_size;
+
} pj_turn_sock_cfg;
diff --git a/pjnath/src/pjnath/ice_strans.c b/pjnath/src/pjnath/ice_strans.c
index 84dc2bb4..95ca9571 100644
--- a/pjnath/src/pjnath/ice_strans.c
+++ b/pjnath/src/pjnath/ice_strans.c
@@ -296,6 +296,16 @@ static pj_status_t add_update_turn(pj_ice_strans *ice_st,
sizeof(ice_st->cfg.turn.cfg.qos_params));
}
+ /* Override with component specific socket buffer size settings, if any */
+ if (ice_st->cfg.comp[comp->comp_id-1].so_rcvbuf_size > 0) {
+ ice_st->cfg.turn.cfg.so_rcvbuf_size =
+ ice_st->cfg.comp[comp->comp_id-1].so_rcvbuf_size;
+ }
+ if (ice_st->cfg.comp[comp->comp_id-1].so_sndbuf_size > 0) {
+ ice_st->cfg.turn.cfg.so_sndbuf_size =
+ ice_st->cfg.comp[comp->comp_id-1].so_sndbuf_size;
+ }
+
/* Create the TURN transport */
status = pj_turn_sock_create(&ice_st->cfg.stun_cfg, ice_st->cfg.af,
ice_st->cfg.turn.conn_type,
@@ -383,6 +393,16 @@ static pj_status_t create_comp(pj_ice_strans *ice_st, unsigned comp_id)
sizeof(ice_st->cfg.stun.cfg.qos_params));
}
+ /* Override component specific socket buffer size settings, if any */
+ if (ice_st->cfg.comp[comp_id-1].so_rcvbuf_size > 0) {
+ ice_st->cfg.stun.cfg.so_rcvbuf_size =
+ ice_st->cfg.comp[comp_id-1].so_rcvbuf_size;
+ }
+ if (ice_st->cfg.comp[comp_id-1].so_sndbuf_size > 0) {
+ ice_st->cfg.stun.cfg.so_sndbuf_size =
+ ice_st->cfg.comp[comp_id-1].so_sndbuf_size;
+ }
+
/* Create the STUN transport */
status = pj_stun_sock_create(&ice_st->cfg.stun_cfg, NULL,
ice_st->cfg.af, &stun_sock_cb,
diff --git a/pjnath/src/pjnath/stun_sock.c b/pjnath/src/pjnath/stun_sock.c
index b0bad9e3..eadec9cb 100644
--- a/pjnath/src/pjnath/stun_sock.c
+++ b/pjnath/src/pjnath/stun_sock.c
@@ -237,6 +237,46 @@ PJ_DEF(pj_status_t) pj_stun_sock_create( pj_stun_config *stun_cfg,
if (status != PJ_SUCCESS && !cfg->qos_ignore_error)
goto on_error;
+ /* Apply socket buffer size */
+ if (cfg->so_rcvbuf_size > 0) {
+ unsigned sobuf_size = cfg->so_rcvbuf_size;
+ status = pj_sock_setsockopt_sobuf(stun_sock->sock_fd, pj_SO_RCVBUF(),
+ PJ_TRUE, &sobuf_size);
+ if (status != PJ_SUCCESS) {
+ pj_perror(3, stun_sock->obj_name, status,
+ "Failed setting SO_RCVBUF");
+ } else {
+ if (sobuf_size < cfg->so_rcvbuf_size) {
+ PJ_LOG(4, (stun_sock->obj_name,
+ "Warning! Cannot set SO_RCVBUF as configured, "
+ "now=%d, configured=%d",
+ sobuf_size, cfg->so_rcvbuf_size));
+ } else {
+ PJ_LOG(5, (stun_sock->obj_name, "SO_RCVBUF set to %d",
+ sobuf_size));
+ }
+ }
+ }
+ if (cfg->so_sndbuf_size > 0) {
+ unsigned sobuf_size = cfg->so_sndbuf_size;
+ status = pj_sock_setsockopt_sobuf(stun_sock->sock_fd, pj_SO_SNDBUF(),
+ PJ_TRUE, &sobuf_size);
+ if (status != PJ_SUCCESS) {
+ pj_perror(3, stun_sock->obj_name, status,
+ "Failed setting SO_SNDBUF");
+ } else {
+ if (sobuf_size < cfg->so_sndbuf_size) {
+ PJ_LOG(4, (stun_sock->obj_name,
+ "Warning! Cannot set SO_SNDBUF as configured, "
+ "now=%d, configured=%d",
+ sobuf_size, cfg->so_sndbuf_size));
+ } else {
+ PJ_LOG(5, (stun_sock->obj_name, "SO_SNDBUF set to %d",
+ sobuf_size));
+ }
+ }
+ }
+
/* Bind socket */
max_bind_retry = MAX_BIND_RETRY;
if (cfg->port_range && cfg->port_range < max_bind_retry)
diff --git a/pjnath/src/pjnath/turn_sock.c b/pjnath/src/pjnath/turn_sock.c
index 7dde5a5e..42beb225 100644
--- a/pjnath/src/pjnath/turn_sock.c
+++ b/pjnath/src/pjnath/turn_sock.c
@@ -810,6 +810,46 @@ static void turn_on_state(pj_turn_session *sess,
return;
}
+ /* Apply socket buffer size */
+ if (turn_sock->setting.so_rcvbuf_size > 0) {
+ unsigned sobuf_size = turn_sock->setting.so_rcvbuf_size;
+ status = pj_sock_setsockopt_sobuf(sock, pj_SO_RCVBUF(),
+ PJ_TRUE, &sobuf_size);
+ if (status != PJ_SUCCESS) {
+ pj_perror(3, turn_sock->obj_name, status,
+ "Failed setting SO_RCVBUF");
+ } else {
+ if (sobuf_size < turn_sock->setting.so_rcvbuf_size) {
+ PJ_LOG(4, (turn_sock->obj_name,
+ "Warning! Cannot set SO_RCVBUF as configured,"
+ " now=%d, configured=%d", sobuf_size,
+ turn_sock->setting.so_rcvbuf_size));
+ } else {
+ PJ_LOG(5, (turn_sock->obj_name, "SO_RCVBUF set to %d",
+ sobuf_size));
+ }
+ }
+ }
+ if (turn_sock->setting.so_sndbuf_size > 0) {
+ unsigned sobuf_size = turn_sock->setting.so_sndbuf_size;
+ status = pj_sock_setsockopt_sobuf(sock, pj_SO_SNDBUF(),
+ PJ_TRUE, &sobuf_size);
+ if (status != PJ_SUCCESS) {
+ pj_perror(3, turn_sock->obj_name, status,
+ "Failed setting SO_SNDBUF");
+ } else {
+ if (sobuf_size < turn_sock->setting.so_sndbuf_size) {
+ PJ_LOG(4, (turn_sock->obj_name,
+ "Warning! Cannot set SO_SNDBUF as configured,"
+ " now=%d, configured=%d", sobuf_size,
+ turn_sock->setting.so_sndbuf_size));
+ } else {
+ PJ_LOG(5, (turn_sock->obj_name, "SO_SNDBUF set to %d",
+ sobuf_size));
+ }
+ }
+ }
+
/* Create active socket */
pj_activesock_cfg_default(&asock_cfg);
asock_cfg.grp_lock = turn_sock->grp_lock;