Skip to content

Commit b3c8a81

Browse files
committed
Select I/O queue using macro PJ_IOQUEUE_IMP
Currently switching an I/O queue backend need to re-run configure for GNU build system or modify the PJLIB project for Visual Studio.
1 parent 093da33 commit b3c8a81

File tree

17 files changed

+117
-56
lines changed

17 files changed

+117
-56
lines changed

aconfigure

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,6 @@ ac_external_gsm
732732
ac_external_speex
733733
ac_no_pjsua2
734734
ac_shared_libraries
735-
ac_linux_poll
736735
ac_os_objs
737736
ac_std_cpp_lib
738737
ac_target_arch
@@ -6839,32 +6838,33 @@ fi
68396838
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
68406839

68416840

6842-
68436841
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking ioqueue backend" >&5
68446842
printf %s "checking ioqueue backend... " >&6; }
68456843

6846-
ac_os_objs=ioqueue_select.o
6847-
ac_linux_poll=select
6848-
68496844
case $target in
68506845
*darwin* | *bsd*)
68516846
# Check whether --enable-kqueue was given.
68526847
if test ${enable_kqueue+y}
68536848
then :
68546849
enableval=$enable_kqueue;
68556850
if test "$enable_kqueue" = "yes"; then
6856-
ac_os_objs=ioqueue_kqueue.o
68576851
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: kqueue()" >&5
68586852
printf "%s\n" "kqueue()" >&6; }
6853+
printf "%s\n" "#define PJ_IOQUEUE_IMP PJ_IOQUEUE_IMP_KQUEUE" >>confdefs.h
6854+
68596855
else
68606856
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: select()" >&5
68616857
printf "%s\n" "select()" >&6; }
6858+
printf "%s\n" "#define PJ_IOQUEUE_IMP PJ_IOQUEUE_IMP_SELECT" >>confdefs.h
6859+
68626860
fi
68636861

68646862
else case e in #(
68656863
e)
68666864
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: select()" >&5
68676865
printf "%s\n" "select()" >&6; }
6866+
printf "%s\n" "#define PJ_IOQUEUE_IMP PJ_IOQUEUE_IMP_SELECT" >>confdefs.h
6867+
68686868

68696869
;;
68706870
esac
@@ -6877,21 +6877,23 @@ if test ${enable_epoll+y}
68776877
then :
68786878
enableval=$enable_epoll;
68796879
if test "$enable_epoll" = "yes"; then
6880-
ac_os_objs=ioqueue_epoll.o
68816880
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: /dev/epoll" >&5
68826881
printf "%s\n" "/dev/epoll" >&6; }
6883-
printf "%s\n" "#define PJ_HAS_LINUX_EPOLL 1" >>confdefs.h
6882+
printf "%s\n" "#define PJ_IOQUEUE_IMP PJ_IOQUEUE_IMP_EPOLL" >>confdefs.h
68846883

6885-
ac_linux_poll=epoll
68866884
else
68876885
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: select()" >&5
68886886
printf "%s\n" "select()" >&6; }
6887+
printf "%s\n" "#define PJ_IOQUEUE_IMP PJ_IOQUEUE_IMP_SELECT" >>confdefs.h
6888+
68896889
fi
68906890

68916891
else case e in #(
68926892
e)
68936893
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: select()" >&5
68946894
printf "%s\n" "select()" >&6; }
6895+
printf "%s\n" "#define PJ_IOQUEUE_IMP PJ_IOQUEUE_IMP_SELECT" >>confdefs.h
6896+
68956897

68966898
;;
68976899
esac

aconfigure.ac

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -569,26 +569,24 @@ dnl ######################
569569
dnl # ioqueue selection
570570
dnl #
571571
AC_SUBST(ac_os_objs)
572-
AC_SUBST(ac_linux_poll)
573572
AC_MSG_CHECKING([ioqueue backend])
574573

575-
ac_os_objs=ioqueue_select.o
576-
ac_linux_poll=select
577-
578574
case $target in
579575
*darwin* | *bsd*)
580576
AC_ARG_ENABLE(kqueue,
581577
AS_HELP_STRING([--enable-kqueue], [Use kqueue ioqueue on macos/BSD (experimental)]),
582578
[
583579
if test "$enable_kqueue" = "yes"; then
584-
ac_os_objs=ioqueue_kqueue.o
585580
AC_MSG_RESULT([kqueue()])
581+
AC_DEFINE(PJ_IOQUEUE_IMP, PJ_IOQUEUE_IMP_KQUEUE)
586582
else
587583
AC_MSG_RESULT([select()])
584+
AC_DEFINE(PJ_IOQUEUE_IMP, PJ_IOQUEUE_IMP_SELECT)
588585
fi
589586
],
590587
[
591588
AC_MSG_RESULT([select()])
589+
AC_DEFINE(PJ_IOQUEUE_IMP, PJ_IOQUEUE_IMP_SELECT)
592590
]
593591
)
594592
;;
@@ -597,16 +595,16 @@ case $target in
597595
AS_HELP_STRING([--enable-epoll], [Use /dev/epoll ioqueue on Linux (experimental)]),
598596
[
599597
if test "$enable_epoll" = "yes"; then
600-
ac_os_objs=ioqueue_epoll.o
601598
AC_MSG_RESULT([/dev/epoll])
602-
AC_DEFINE(PJ_HAS_LINUX_EPOLL,1)
603-
ac_linux_poll=epoll
599+
AC_DEFINE(PJ_IOQUEUE_IMP, PJ_IOQUEUE_IMP_EPOLL)
604600
else
605601
AC_MSG_RESULT([select()])
602+
AC_DEFINE(PJ_IOQUEUE_IMP, PJ_IOQUEUE_IMP_SELECT)
606603
fi
607604
],
608605
[
609606
AC_MSG_RESULT([select()])
607+
AC_DEFINE(PJ_IOQUEUE_IMP, PJ_IOQUEUE_IMP_SELECT)
610608
]
611609
)
612610
;;

pjlib/build/os-auto.mak.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ AC_OS_OBJS=@ac_os_objs@
1010
#
1111
export PJLIB_OBJS += $(AC_OS_OBJS) \
1212
addr_resolv_sock.o \
13+
ioqueue_dummy.o ioqueue_epoll.o ioqueue_kqueue.o ioqueue_select.o \
1314
log_writer_stdout.o \
1415
os_timestamp_common.o \
1516
pool_policy_malloc.o sock_bsd.o sock_select.o

pjlib/build/pjlib.vcxproj

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -756,32 +756,7 @@
756756
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
757757
</ClCompile>
758758
<ClCompile Include="..\src\pj\ioqueue_select.c" />
759-
<ClCompile Include="..\src\pj\ioqueue_winnt.c">
760-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Dynamic|Win32'">true</ExcludedFromBuild>
761-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Dynamic|ARM'">true</ExcludedFromBuild>
762-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Dynamic|x64'">true</ExcludedFromBuild>
763-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Dynamic|ARM64'">true</ExcludedFromBuild>
764-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Static|Win32'">true</ExcludedFromBuild>
765-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Static|ARM'">true</ExcludedFromBuild>
766-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Static|x64'">true</ExcludedFromBuild>
767-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Static|ARM64'">true</ExcludedFromBuild>
768-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
769-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
770-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
771-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
772-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release-Dynamic|Win32'">true</ExcludedFromBuild>
773-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release-Dynamic|ARM'">true</ExcludedFromBuild>
774-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release-Dynamic|x64'">true</ExcludedFromBuild>
775-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release-Dynamic|ARM64'">true</ExcludedFromBuild>
776-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release-Static|Win32'">true</ExcludedFromBuild>
777-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release-Static|ARM'">true</ExcludedFromBuild>
778-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release-Static|x64'">true</ExcludedFromBuild>
779-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release-Static|ARM64'">true</ExcludedFromBuild>
780-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
781-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
782-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
783-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
784-
</ClCompile>
759+
<ClCompile Include="..\src\pj\ioqueue_winnt.c" />
785760
<ClCompile Include="..\src\pj\ip_helper_winphone8.c">
786761
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Dynamic|Win32'">true</ExcludedFromBuild>
787762
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Dynamic|ARM'">true</ExcludedFromBuild>

pjlib/include/pj/compat/os_auto.h.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@
122122
typedef int socklen_t;
123123
#endif
124124

125+
/* Select I/O queue backend. */
126+
#undef PJ_IOQUEUE_IMP
127+
125128
/**
126129
* If this macro is set, it tells select I/O Queue that select() needs to
127130
* be given correct value of nfds (i.e. largest fd + 1). This requires
@@ -134,9 +137,6 @@
134137
*/
135138
#undef PJ_SELECT_NEEDS_NFDS
136139

137-
/* Was Linux epoll support enabled */
138-
#undef PJ_HAS_LINUX_EPOLL
139-
140140
/* Is errno a good way to retrieve OS errors?
141141
*/
142142
#undef PJ_HAS_ERRNO_VAR

pjlib/include/pj/config.h

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,43 @@
690690
# define PJ_ACTIVESOCK_MAX_CONSECUTIVE_ACCEPT_ERROR 50
691691
#endif
692692

693+
694+
/*
695+
* I/O queue implementation backends.
696+
* Select one of these implementations in PJ_IOQUEUE_IMP.
697+
*/
698+
699+
/** No/dummy I/O queue */
700+
#define PJ_IOQUEUE_IMP_NONE 0
701+
702+
/** Using select() */
703+
#define PJ_IOQUEUE_IMP_SELECT 1
704+
705+
/** Using epoll() (experimental) */
706+
#define PJ_IOQUEUE_IMP_EPOLL 2
707+
708+
/** Using Windows I/O Completion Ports (experimental) */
709+
#define PJ_IOQUEUE_IMP_IOCP 3
710+
711+
/** Using MacOS/BSD kqueue (experimental) */
712+
#define PJ_IOQUEUE_IMP_KQUEUE 4
713+
714+
/** Using Windows UWP socket (deprecated) */
715+
#define PJ_IOQUEUE_IMP_UWP 5
716+
717+
/** Using Symbian (deprecated) */
718+
#define PJ_IOQUEUE_IMP_SYMBIAN 6
719+
720+
/**
721+
* I/O queue implementation backend.
722+
*
723+
* Default: PJ_IOQUEUE_IMP_SELECT
724+
*/
725+
#ifndef PJ_IOQUEUE_IMP
726+
# define PJ_IOQUEUE_IMP PJ_IOQUEUE_IMP_SELECT
727+
#endif
728+
729+
693730
/**
694731
* Constants for declaring the maximum handles that can be supported by
695732
* a single IOQ framework. This constant might not be relevant to the
@@ -1068,7 +1105,7 @@
10681105
/** Using OpenSSL */
10691106
#define PJ_SSL_SOCK_IMP_OPENSSL 1
10701107

1071-
/**< Using GnuTLS */
1108+
/** Using GnuTLS */
10721109
#define PJ_SSL_SOCK_IMP_GNUTLS 2
10731110

10741111
/** Using Apple's Secure Transport (deprecated in MacOS 10.15 & iOS 13.0) */

pjlib/src/pj/ioqueue_dummy.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
#include <pj/sock.h>
2727
#include <pj/errno.h>
2828

29+
30+
/* Only build when the backend is using dummy/none. */
31+
#if PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_NONE
32+
33+
2934
#define THIS_FILE "ioqueue"
3035

3136
#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 )
196201
PJ_UNUSED_ARG(ioqueue);
197202
return NULL;
198203
}
204+
205+
#endif /* PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_NONE */

pjlib/src/pj/ioqueue_epoll.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
#include <pj/compat/socket.h>
3737
#include <pj/rand.h>
3838

39+
40+
/* Only build when the backend is using epoll. */
41+
#if PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_EPOLL
42+
43+
3944
#include <sys/epoll.h>
4045
#include <sys/eventfd.h>
4146
#include <errno.h>
@@ -1082,3 +1087,5 @@ PJ_DEF(pj_oshandle_t) pj_ioqueue_get_os_handle( pj_ioqueue_t *ioqueue )
10821087
{
10831088
return ioqueue ? (pj_oshandle_t)&ioqueue->epfd : NULL;
10841089
}
1090+
1091+
#endif /* PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_EPOLL */

pjlib/src/pj/ioqueue_kqueue.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
#include <pj/sock.h>
3333
#include <pj/string.h>
3434

35+
/* Only build when the backend is using kqueue. */
36+
#if PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_KQUEUE
37+
3538
#include <sys/event.h>
3639

3740
#define os_kqueue_open kqueue
@@ -729,3 +732,5 @@ PJ_DEF(pj_oshandle_t) pj_ioqueue_get_os_handle( pj_ioqueue_t *ioqueue )
729732
{
730733
return ioqueue ? (pj_oshandle_t)&ioqueue->kfd : NULL;
731734
}
735+
736+
#endif /* PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_KQUEUE */

pjlib/src/pj/ioqueue_select.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
#include <pj/errno.h>
4141
#include <pj/rand.h>
4242

43+
44+
/* Only build when the backend is using select(). */
45+
#if PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_SELECT
46+
47+
4348
/* Now that we have access to OS'es <sys/select>, lets check again that
4449
* PJ_IOQUEUE_MAX_HANDLES is not greater than FD_SETSIZE
4550
*/
@@ -1142,3 +1147,5 @@ PJ_DEF(pj_oshandle_t) pj_ioqueue_get_os_handle( pj_ioqueue_t *ioqueue )
11421147
PJ_UNUSED_ARG(ioqueue);
11431148
return NULL;
11441149
}
1150+
1151+
#endif /* PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_SELECT */

0 commit comments

Comments
 (0)