diff options
author | Nanang Izzuddin <nanang@teluu.com> | 2013-06-19 09:06:55 +0000 |
---|---|---|
committer | Nanang Izzuddin <nanang@teluu.com> | 2013-06-19 09:06:55 +0000 |
commit | 1229122bc17bb86b6a10e043aa3505715b797347 (patch) | |
tree | ae8a72fe1f020f77c31514b05fbd98af2fdcd434 /pjlib/src | |
parent | d7aa4332dae06ae890053dd13239ddabee46b86c (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 'pjlib/src')
-rw-r--r-- | pjlib/src/pj/sock_common.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/pjlib/src/pj/sock_common.c b/pjlib/src/pj/sock_common.c index eb338e73..94fa52e4 100644 --- a/pjlib/src/pj/sock_common.c +++ b/pjlib/src/pj/sock_common.c @@ -1079,6 +1079,69 @@ PJ_DEF(pj_status_t) pj_sock_bind_random( pj_sock_t sockfd, } +/* + * Adjust socket send/receive buffer size. + */ +PJ_DEF(pj_status_t) pj_sock_setsockopt_sobuf( pj_sock_t sockfd, + pj_uint16_t optname, + pj_bool_t auto_retry, + unsigned *buf_size) +{ + pj_status_t status; + int try_size, cur_size, i, step, size_len; + enum { MAX_TRY = 20 }; + + PJ_CHECK_STACK(); + + PJ_ASSERT_RETURN(sockfd != PJ_INVALID_SOCKET && + buf_size && + *buf_size > 0 && + (optname == pj_SO_RCVBUF() || + optname == pj_SO_SNDBUF()), + PJ_EINVAL); + + size_len = sizeof(cur_size); + status = pj_sock_getsockopt(sockfd, pj_SOL_SOCKET(), optname, + &cur_size, &size_len); + if (status != PJ_SUCCESS) + return status; + + try_size = *buf_size; + step = (try_size - cur_size) / MAX_TRY; + if (step < 4096) + step = 4096; + + for (i = 0; i < (MAX_TRY-1); ++i) { + if (try_size <= cur_size) { + /* Done, return current size */ + *buf_size = cur_size; + break; + } + + status = pj_sock_setsockopt(sockfd, pj_SOL_SOCKET(), optname, + &try_size, sizeof(try_size)); + if (status == PJ_SUCCESS) { + status = pj_sock_getsockopt(sockfd, pj_SOL_SOCKET(), optname, + &cur_size, &size_len); + if (status != PJ_SUCCESS) { + /* Ops! No info about current size, just return last try size + * and quit. + */ + *buf_size = try_size; + break; + } + } + + if (!auto_retry) + break; + + try_size -= step; + } + + return status; +} + + /* Only need to implement these in DLL build */ #if defined(PJ_DLL) |