diff --git a/aconfigure b/aconfigure index b5d3446319..cf7ece6db5 100755 --- a/aconfigure +++ b/aconfigure @@ -732,7 +732,6 @@ ac_external_gsm ac_external_speex ac_no_pjsua2 ac_shared_libraries -ac_linux_poll ac_os_objs ac_std_cpp_lib ac_target_arch @@ -6839,13 +6838,9 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking ioqueue backend" >&5 printf %s "checking ioqueue backend... " >&6; } -ac_os_objs=ioqueue_select.o -ac_linux_poll=select - case $target in *darwin* | *bsd*) # Check whether --enable-kqueue was given. @@ -6853,18 +6848,23 @@ if test ${enable_kqueue+y} then : enableval=$enable_kqueue; if test "$enable_kqueue" = "yes"; then - ac_os_objs=ioqueue_kqueue.o { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: kqueue()" >&5 printf "%s\n" "kqueue()" >&6; } + printf "%s\n" "#define PJ_IOQUEUE_IMP PJ_IOQUEUE_IMP_KQUEUE" >>confdefs.h + else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: select()" >&5 printf "%s\n" "select()" >&6; } + printf "%s\n" "#define PJ_IOQUEUE_IMP PJ_IOQUEUE_IMP_SELECT" >>confdefs.h + fi else case e in #( e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: select()" >&5 printf "%s\n" "select()" >&6; } + printf "%s\n" "#define PJ_IOQUEUE_IMP PJ_IOQUEUE_IMP_SELECT" >>confdefs.h + ;; esac @@ -6877,21 +6877,23 @@ if test ${enable_epoll+y} then : enableval=$enable_epoll; if test "$enable_epoll" = "yes"; then - ac_os_objs=ioqueue_epoll.o { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: /dev/epoll" >&5 printf "%s\n" "/dev/epoll" >&6; } - printf "%s\n" "#define PJ_HAS_LINUX_EPOLL 1" >>confdefs.h + printf "%s\n" "#define PJ_IOQUEUE_IMP PJ_IOQUEUE_IMP_EPOLL" >>confdefs.h - ac_linux_poll=epoll else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: select()" >&5 printf "%s\n" "select()" >&6; } + printf "%s\n" "#define PJ_IOQUEUE_IMP PJ_IOQUEUE_IMP_SELECT" >>confdefs.h + fi else case e in #( e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: select()" >&5 printf "%s\n" "select()" >&6; } + printf "%s\n" "#define PJ_IOQUEUE_IMP PJ_IOQUEUE_IMP_SELECT" >>confdefs.h + ;; esac diff --git a/aconfigure.ac b/aconfigure.ac index 279870e9d6..7d304595e2 100644 --- a/aconfigure.ac +++ b/aconfigure.ac @@ -569,26 +569,24 @@ dnl ###################### dnl # ioqueue selection dnl # AC_SUBST(ac_os_objs) -AC_SUBST(ac_linux_poll) AC_MSG_CHECKING([ioqueue backend]) -ac_os_objs=ioqueue_select.o -ac_linux_poll=select - case $target in *darwin* | *bsd*) AC_ARG_ENABLE(kqueue, AS_HELP_STRING([--enable-kqueue], [Use kqueue ioqueue on macos/BSD (experimental)]), [ if test "$enable_kqueue" = "yes"; then - ac_os_objs=ioqueue_kqueue.o AC_MSG_RESULT([kqueue()]) + AC_DEFINE(PJ_IOQUEUE_IMP, PJ_IOQUEUE_IMP_KQUEUE) else AC_MSG_RESULT([select()]) + AC_DEFINE(PJ_IOQUEUE_IMP, PJ_IOQUEUE_IMP_SELECT) fi ], [ AC_MSG_RESULT([select()]) + AC_DEFINE(PJ_IOQUEUE_IMP, PJ_IOQUEUE_IMP_SELECT) ] ) ;; @@ -597,16 +595,16 @@ case $target in AS_HELP_STRING([--enable-epoll], [Use /dev/epoll ioqueue on Linux (experimental)]), [ if test "$enable_epoll" = "yes"; then - ac_os_objs=ioqueue_epoll.o AC_MSG_RESULT([/dev/epoll]) - AC_DEFINE(PJ_HAS_LINUX_EPOLL,1) - ac_linux_poll=epoll + AC_DEFINE(PJ_IOQUEUE_IMP, PJ_IOQUEUE_IMP_EPOLL) else AC_MSG_RESULT([select()]) + AC_DEFINE(PJ_IOQUEUE_IMP, PJ_IOQUEUE_IMP_SELECT) fi ], [ AC_MSG_RESULT([select()]) + AC_DEFINE(PJ_IOQUEUE_IMP, PJ_IOQUEUE_IMP_SELECT) ] ) ;; diff --git a/pjlib/build/os-auto.mak.in b/pjlib/build/os-auto.mak.in index 4d3724c3e7..11890d31e3 100644 --- a/pjlib/build/os-auto.mak.in +++ b/pjlib/build/os-auto.mak.in @@ -10,6 +10,7 @@ AC_OS_OBJS=@ac_os_objs@ # export PJLIB_OBJS += $(AC_OS_OBJS) \ addr_resolv_sock.o \ + ioqueue_dummy.o ioqueue_epoll.o ioqueue_kqueue.o ioqueue_select.o \ log_writer_stdout.o \ os_timestamp_common.o \ pool_policy_malloc.o sock_bsd.o sock_select.o diff --git a/pjlib/build/pjlib.vcxproj b/pjlib/build/pjlib.vcxproj index 6074880f6f..b0b109189d 100644 --- a/pjlib/build/pjlib.vcxproj +++ b/pjlib/build/pjlib.vcxproj @@ -756,32 +756,7 @@ true - - true - true - true - true - true - true - true - true - true - true - true - true - true - true - true - true - true - true - true - true - true - true - true - true - + true true diff --git a/pjlib/include/pj/compat/os_auto.h.in b/pjlib/include/pj/compat/os_auto.h.in index b8ff5769a2..217a8b6e6e 100644 --- a/pjlib/include/pj/compat/os_auto.h.in +++ b/pjlib/include/pj/compat/os_auto.h.in @@ -122,6 +122,9 @@ typedef int socklen_t; #endif +/* Select I/O queue backend. */ +#undef PJ_IOQUEUE_IMP + /** * If this macro is set, it tells select I/O Queue that select() needs to * be given correct value of nfds (i.e. largest fd + 1). This requires @@ -134,9 +137,6 @@ */ #undef PJ_SELECT_NEEDS_NFDS -/* Was Linux epoll support enabled */ -#undef PJ_HAS_LINUX_EPOLL - /* Is errno a good way to retrieve OS errors? */ #undef PJ_HAS_ERRNO_VAR diff --git a/pjlib/include/pj/config.h b/pjlib/include/pj/config.h index 49ff05ba32..f4809ce788 100644 --- a/pjlib/include/pj/config.h +++ b/pjlib/include/pj/config.h @@ -690,6 +690,43 @@ # define PJ_ACTIVESOCK_MAX_CONSECUTIVE_ACCEPT_ERROR 50 #endif + +/* + * I/O queue implementation backends. + * Select one of these implementations in PJ_IOQUEUE_IMP. + */ + +/** No/dummy I/O queue */ +#define PJ_IOQUEUE_IMP_NONE 0 + +/** Using select() */ +#define PJ_IOQUEUE_IMP_SELECT 1 + +/** Using epoll() (experimental) */ +#define PJ_IOQUEUE_IMP_EPOLL 2 + +/** Using Windows I/O Completion Ports (experimental) */ +#define PJ_IOQUEUE_IMP_IOCP 3 + +/** Using MacOS/BSD kqueue (experimental) */ +#define PJ_IOQUEUE_IMP_KQUEUE 4 + +/** Using Windows UWP socket (deprecated) */ +#define PJ_IOQUEUE_IMP_UWP 5 + +/** Using Symbian (deprecated) */ +#define PJ_IOQUEUE_IMP_SYMBIAN 6 + +/** + * I/O queue implementation backend. + * + * Default: PJ_IOQUEUE_IMP_SELECT + */ +#ifndef PJ_IOQUEUE_IMP +# define PJ_IOQUEUE_IMP PJ_IOQUEUE_IMP_SELECT +#endif + + /** * Constants for declaring the maximum handles that can be supported by * a single IOQ framework. This constant might not be relevant to the @@ -1068,7 +1105,7 @@ /** Using OpenSSL */ #define PJ_SSL_SOCK_IMP_OPENSSL 1 -/**< Using GnuTLS */ +/** Using GnuTLS */ #define PJ_SSL_SOCK_IMP_GNUTLS 2 /** Using Apple's Secure Transport (deprecated in MacOS 10.15 & iOS 13.0) */ diff --git a/pjlib/src/pj/ioqueue_dummy.c b/pjlib/src/pj/ioqueue_dummy.c index 5e7c2a3519..cf3b1f1f11 100644 --- a/pjlib/src/pj/ioqueue_dummy.c +++ b/pjlib/src/pj/ioqueue_dummy.c @@ -26,6 +26,11 @@ #include #include + +/* Only build when the backend is using dummy/none. */ +#if PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_NONE + + #define THIS_FILE "ioqueue" #define PJ_IOQUEUE_IS_READ_OP(op) \ @@ -196,3 +201,5 @@ PJ_DEF(pj_oshandle_t) pj_ioqueue_get_os_handle( pj_ioqueue_t *ioqueue ) PJ_UNUSED_ARG(ioqueue); return NULL; } + +#endif /* PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_NONE */ diff --git a/pjlib/src/pj/ioqueue_epoll.c b/pjlib/src/pj/ioqueue_epoll.c index 2845a23eaf..4f81391c1b 100644 --- a/pjlib/src/pj/ioqueue_epoll.c +++ b/pjlib/src/pj/ioqueue_epoll.c @@ -36,6 +36,11 @@ #include #include + +/* Only build when the backend is using epoll. */ +#if PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_EPOLL + + #include #include #include @@ -1082,3 +1087,5 @@ PJ_DEF(pj_oshandle_t) pj_ioqueue_get_os_handle( pj_ioqueue_t *ioqueue ) { return ioqueue ? (pj_oshandle_t)&ioqueue->epfd : NULL; } + +#endif /* PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_EPOLL */ diff --git a/pjlib/src/pj/ioqueue_kqueue.c b/pjlib/src/pj/ioqueue_kqueue.c index bd319f70b5..e3937e4a0a 100644 --- a/pjlib/src/pj/ioqueue_kqueue.c +++ b/pjlib/src/pj/ioqueue_kqueue.c @@ -32,6 +32,9 @@ #include #include +/* Only build when the backend is using kqueue. */ +#if PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_KQUEUE + #include #define os_kqueue_open kqueue @@ -729,3 +732,5 @@ PJ_DEF(pj_oshandle_t) pj_ioqueue_get_os_handle( pj_ioqueue_t *ioqueue ) { return ioqueue ? (pj_oshandle_t)&ioqueue->kfd : NULL; } + +#endif /* PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_KQUEUE */ diff --git a/pjlib/src/pj/ioqueue_select.c b/pjlib/src/pj/ioqueue_select.c index 5641cf8cbb..9409616108 100644 --- a/pjlib/src/pj/ioqueue_select.c +++ b/pjlib/src/pj/ioqueue_select.c @@ -40,6 +40,11 @@ #include #include + +/* Only build when the backend is using select(). */ +#if PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_SELECT + + /* Now that we have access to OS'es , lets check again that * PJ_IOQUEUE_MAX_HANDLES is not greater than FD_SETSIZE */ @@ -1142,3 +1147,5 @@ PJ_DEF(pj_oshandle_t) pj_ioqueue_get_os_handle( pj_ioqueue_t *ioqueue ) PJ_UNUSED_ARG(ioqueue); return NULL; } + +#endif /* PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_SELECT */ diff --git a/pjlib/src/pj/ioqueue_symbian.cpp b/pjlib/src/pj/ioqueue_symbian.cpp index 9673f0b2f3..82c749c2e6 100644 --- a/pjlib/src/pj/ioqueue_symbian.cpp +++ b/pjlib/src/pj/ioqueue_symbian.cpp @@ -24,6 +24,11 @@ #include #include + +/* Only build when the backend is using Symbian. */ +#if PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_SYMBIAN + + #include "os_symbian.h" class CIoqueueCallback; @@ -869,3 +874,5 @@ PJ_DEF(pj_oshandle_t) pj_ioqueue_get_os_handle( pj_ioqueue_t *ioqueue ) PJ_UNUSED_ARG(ioqueue); return NULL; } + +#endif /* PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_SYMBIAN */ diff --git a/pjlib/src/pj/ioqueue_uwp.cpp b/pjlib/src/pj/ioqueue_uwp.cpp index a261ef0850..66da7ef896 100644 --- a/pjlib/src/pj/ioqueue_uwp.cpp +++ b/pjlib/src/pj/ioqueue_uwp.cpp @@ -22,6 +22,10 @@ #include #include +/* Only build when the backend is using Windows UWP socket. */ +#if PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_UWP + + #include #include @@ -367,3 +371,5 @@ PJ_DEF(pj_oshandle_t) pj_ioqueue_get_os_handle( pj_ioqueue_t *ioqueue ) PJ_UNUSED_ARG(ioqueue); return NULL; } + +#endif /* PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_UWP */ diff --git a/pjlib/src/pj/ioqueue_winnt.c b/pjlib/src/pj/ioqueue_winnt.c index 19e568cbc5..bbaf87322d 100644 --- a/pjlib/src/pj/ioqueue_winnt.c +++ b/pjlib/src/pj/ioqueue_winnt.c @@ -29,6 +29,12 @@ #include +/* Only build when the backend is Windows I/O Completion Ports. */ +#if PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_IOCP + + +#define THIS_FILE "ioq_winnt" + #if defined(PJ_HAS_WINSOCK2_H) && PJ_HAS_WINSOCK2_H != 0 # include #elif defined(PJ_HAS_WINSOCK_H) && PJ_HAS_WINSOCK_H != 0 @@ -1513,3 +1519,6 @@ PJ_DEF(pj_oshandle_t) pj_ioqueue_get_os_handle( pj_ioqueue_t *ioqueue ) { return ioqueue ? (pj_oshandle_t)ioqueue->iocp : NULL; } + + +#endif /* PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_IOCP */ diff --git a/pjlib/src/pjlib-test/ioq_perf.c b/pjlib/src/pjlib-test/ioq_perf.c index a4405abbba..9383028f92 100644 --- a/pjlib/src/pjlib-test/ioq_perf.c +++ b/pjlib/src/pjlib-test/ioq_perf.c @@ -565,7 +565,7 @@ static int ioqueue_perf_test_imp(const pj_ioqueue_cfg *cfg) } static pj_ioqueue_epoll_flag epoll_flags[] = { -#if PJ_HAS_LINUX_EPOLL +#if PJ_IOQUEUE_IMP==PJ_IOQUEUE_IMP_EPOLL PJ_IOQUEUE_EPOLL_EXCLUSIVE, PJ_IOQUEUE_EPOLL_ONESHOT, 0, diff --git a/pjlib/src/pjlib-test/ioq_stress_test.c b/pjlib/src/pjlib-test/ioq_stress_test.c index ed27ef1217..61f22fc4e2 100644 --- a/pjlib/src/pjlib-test/ioq_stress_test.c +++ b/pjlib/src/pjlib-test/ioq_stress_test.c @@ -769,7 +769,7 @@ static test_desc tests[128] = { .cfg.n_clients = 1, .cfg.repeat = 4 }, - #if PJ_HAS_LINUX_EPOLL + #if PJ_IOQUEUE_IMP==PJ_IOQUEUE_IMP_EPOLL { .cfg.title = "basic udp (single thread, EPOLLEXCLUSIVE)", .cfg.max_fd = 4, @@ -831,7 +831,7 @@ static test_desc tests[128] = { .cfg.n_clients = 1, .cfg.repeat = 4 }, - #if PJ_HAS_LINUX_EPOLL + #if PJ_IOQUEUE_IMP==PJ_IOQUEUE_IMP_EPOLL { .cfg.title = "basic tcp (single thread, EPOLLEXCLUSIVE)", .cfg.max_fd = 6, @@ -893,7 +893,7 @@ static test_desc tests[128] = { .cfg.n_clients = 1, .cfg.repeat = 2 }, - #if PJ_HAS_LINUX_EPOLL + #if PJ_IOQUEUE_IMP==PJ_IOQUEUE_IMP_EPOLL { .cfg.title = "failed tcp connect (EPOLLEXCLUSIVE)", .cfg.expected_ret_code = RETCODE_CONNECT_FAILED, @@ -980,7 +980,7 @@ static test_desc tests[128] = { .cfg.n_clients = MAX_ASYNC, .cfg.repeat = 4 }, - #if PJ_HAS_LINUX_EPOLL + #if PJ_IOQUEUE_IMP==PJ_IOQUEUE_IMP_EPOLL /* EPOLLEXCLUSIVE (udp). */ { @@ -1051,7 +1051,7 @@ static test_desc tests[128] = { .cfg.n_clients = MAX_ASYNC, .cfg.repeat = 4 }, - #if PJ_HAS_LINUX_EPOLL + #if PJ_IOQUEUE_IMP==PJ_IOQUEUE_IMP_EPOLL { .cfg.title = "tcp (multithreads, EPOLLEXCLUSIVE)", .cfg.max_fd = 6, @@ -1121,7 +1121,7 @@ static test_desc tests[128] = { .cfg.n_clients = MAX_ASYNC, .cfg.repeat = 4 }, - #if PJ_HAS_LINUX_EPOLL + #if PJ_IOQUEUE_IMP==PJ_IOQUEUE_IMP_EPOLL { .cfg.title = "tcp (multithreads, sequenced, concur=0, EPOLLEXCLUSIVE)", .cfg.max_fd = 6, diff --git a/pjlib/src/pjlib-test/ioq_tcp.c b/pjlib/src/pjlib-test/ioq_tcp.c index 3f665b4cc2..06b56a9518 100644 --- a/pjlib/src/pjlib-test/ioq_tcp.c +++ b/pjlib/src/pjlib-test/ioq_tcp.c @@ -946,7 +946,7 @@ int tcp_ioqueue_test() { pj_ioqueue_epoll_flag epoll_flags[] = { PJ_IOQUEUE_EPOLL_AUTO, -#if PJ_HAS_LINUX_EPOLL +#if PJ_IOQUEUE_IMP==PJ_IOQUEUE_IMP_EPOLL PJ_IOQUEUE_EPOLL_EXCLUSIVE, PJ_IOQUEUE_EPOLL_ONESHOT, 0 diff --git a/pjlib/src/pjlib-test/ioq_udp.c b/pjlib/src/pjlib-test/ioq_udp.c index 6c696dd1dc..cb038ffe42 100644 --- a/pjlib/src/pjlib-test/ioq_udp.c +++ b/pjlib/src/pjlib-test/ioq_udp.c @@ -1241,7 +1241,7 @@ static int udp_ioqueue_test_imp(const pj_ioqueue_cfg *cfg) int udp_ioqueue_test() { pj_ioqueue_epoll_flag epoll_flags[] = { -#if PJ_HAS_LINUX_EPOLL +#if PJ_IOQUEUE_IMP==PJ_IOQUEUE_IMP_EPOLL PJ_IOQUEUE_EPOLL_AUTO, PJ_IOQUEUE_EPOLL_EXCLUSIVE, PJ_IOQUEUE_EPOLL_ONESHOT,