Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select I/O queue backend using macro PJ_IOQUEUE_IMP #4260

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions aconfigure
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -6839,32 +6838,33 @@ 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.
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
Expand All @@ -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
Expand Down
14 changes: 6 additions & 8 deletions aconfigure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
)
;;
Expand All @@ -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)
]
)
;;
Expand Down
1 change: 1 addition & 0 deletions pjlib/build/os-auto.mak.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 1 addition & 26 deletions pjlib/build/pjlib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -756,32 +756,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\src\pj\ioqueue_select.c" />
<ClCompile Include="..\src\pj\ioqueue_winnt.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Dynamic|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Dynamic|ARM'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Dynamic|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Dynamic|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Static|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Static|ARM'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Static|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Static|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release-Dynamic|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release-Dynamic|ARM'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release-Dynamic|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release-Dynamic|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release-Static|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release-Static|ARM'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release-Static|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release-Static|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\src\pj\ioqueue_winnt.c" />
<ClCompile Include="..\src\pj\ip_helper_winphone8.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Dynamic|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-Dynamic|ARM'">true</ExcludedFromBuild>
Expand Down
6 changes: 3 additions & 3 deletions pjlib/include/pj/compat/os_auto.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
39 changes: 38 additions & 1 deletion pjlib/include/pj/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) */
Expand Down
7 changes: 7 additions & 0 deletions pjlib/src/pj/ioqueue_dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
#include <pj/sock.h>
#include <pj/errno.h>


/* 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) \
Expand Down Expand Up @@ -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 */
7 changes: 7 additions & 0 deletions pjlib/src/pj/ioqueue_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
#include <pj/compat/socket.h>
#include <pj/rand.h>


/* Only build when the backend is using epoll. */
#if PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_EPOLL


#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <errno.h>
Expand Down Expand Up @@ -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 */
5 changes: 5 additions & 0 deletions pjlib/src/pj/ioqueue_kqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include <pj/sock.h>
#include <pj/string.h>

/* Only build when the backend is using kqueue. */
#if PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_KQUEUE

#include <sys/event.h>

#define os_kqueue_open kqueue
Expand Down Expand Up @@ -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 */
7 changes: 7 additions & 0 deletions pjlib/src/pj/ioqueue_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
#include <pj/errno.h>
#include <pj/rand.h>


/* Only build when the backend is using select(). */
#if PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_SELECT


/* Now that we have access to OS'es <sys/select>, lets check again that
* PJ_IOQUEUE_MAX_HANDLES is not greater than FD_SETSIZE
*/
Expand Down Expand Up @@ -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 */
7 changes: 7 additions & 0 deletions pjlib/src/pj/ioqueue_symbian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
#include <pj/pool.h>
#include <pj/string.h>


/* Only build when the backend is using Symbian. */
#if PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_SYMBIAN


#include "os_symbian.h"

class CIoqueueCallback;
Expand Down Expand Up @@ -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 */
6 changes: 6 additions & 0 deletions pjlib/src/pj/ioqueue_uwp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include <pj/os.h>
#include <pj/pool.h>

/* Only build when the backend is using Windows UWP socket. */
#if PJ_IOQUEUE_IMP == PJ_IOQUEUE_IMP_UWP


#include <ppltasks.h>
#include <string>

Expand Down Expand Up @@ -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 */
9 changes: 9 additions & 0 deletions pjlib/src/pj/ioqueue_winnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
#include <pj/compat/socket.h>


/* 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 <winsock2.h>
#elif defined(PJ_HAS_WINSOCK_H) && PJ_HAS_WINSOCK_H != 0
Expand Down Expand Up @@ -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 */
2 changes: 1 addition & 1 deletion pjlib/src/pjlib-test/ioq_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading
Loading