summaryrefslogtreecommitdiff
path: root/pjnath
diff options
context:
space:
mode:
authorNanang Izzuddin <nanang@teluu.com>2016-07-18 11:02:02 +0000
committerNanang Izzuddin <nanang@teluu.com>2016-07-18 11:02:02 +0000
commita1099feb5d39f65f94946bdabfd3386d3a2291d5 (patch)
tree3ed9655fd0c37b304f0040c16662cfdd608790dc /pjnath
parent7a699191da6f8484d35646dc48162a91545c875f (diff)
Misc (re #1928): Fixed possible stuck issue in pjnath-test caused by blocking recvfrom() upon concurrent socket events.
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5388 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjnath')
-rw-r--r--pjnath/src/pjnath-test/concur_test.c3
-rw-r--r--pjnath/src/pjnath-test/test.c15
-rw-r--r--pjnath/src/pjnath-test/test.h1
3 files changed, 19 insertions, 0 deletions
diff --git a/pjnath/src/pjnath-test/concur_test.c b/pjnath/src/pjnath-test/concur_test.c
index d30b5ebd..f04cdff9 100644
--- a/pjnath/src/pjnath-test/concur_test.c
+++ b/pjnath/src/pjnath-test/concur_test.c
@@ -263,6 +263,9 @@ static int stun_destroy_test(void)
status = pj_sock_bind(test_sess.server_sock, &bind_addr, pj_sockaddr_get_len(&bind_addr));
pj_assert(status == PJ_SUCCESS);
+ /* Set socket to nonblocking to avoid stuck in recv/recvfrom() on concurrent events */
+ app_set_sock_nb(test_sess.server_sock);
+
addr_len = sizeof(bind_addr);
status = pj_sock_getsockname(test_sess.server_sock, &bind_addr, &addr_len);
pj_assert(status == PJ_SUCCESS);
diff --git a/pjnath/src/pjnath-test/test.c b/pjnath/src/pjnath-test/test.c
index dd3e192d..e3d1a102 100644
--- a/pjnath/src/pjnath-test/test.c
+++ b/pjnath/src/pjnath-test/test.c
@@ -19,6 +19,7 @@
*/
#include "test.h"
#include <pjlib.h>
+#include <pj/compat/socket.h>
void app_perror(const char *msg, pj_status_t rc)
{
@@ -30,6 +31,20 @@ void app_perror(const char *msg, pj_status_t rc)
PJ_LOG(1,("test", "%s: [pj_status_t=%d] %s", msg, rc, errbuf));
}
+/* Set socket to nonblocking. */
+void app_set_sock_nb(pj_sock_t sock)
+{
+#if defined(PJ_WIN32) && PJ_WIN32!=0 || \
+ defined(PJ_WIN64) && PJ_WIN64 != 0 || \
+ defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0
+ u_long value = 1;
+ ioctlsocket(sock, FIONBIO, &value);
+#else
+ pj_uint32_t value = 1;
+ ioctl(sock, FIONBIO, &value);
+#endif
+}
+
pj_status_t create_stun_config(pj_pool_t *pool, pj_stun_config *stun_cfg)
{
pj_ioqueue_t *ioqueue;
diff --git a/pjnath/src/pjnath-test/test.h b/pjnath/src/pjnath-test/test.h
index 71d82315..455c8a94 100644
--- a/pjnath/src/pjnath-test/test.h
+++ b/pjnath/src/pjnath-test/test.h
@@ -44,6 +44,7 @@ int concur_test(void);
int test_main(void);
extern void app_perror(const char *title, pj_status_t rc);
+extern void app_set_sock_nb(pj_sock_t sock);
extern pj_pool_factory *mem;
int ice_one_conc_test(pj_stun_config *stun_cfg, int err_quit);