Detect if available and use poll() instead of select() on sockets.
This save a lot on performance by not FD_ZEROing large sets. git-svn-id: http://voip.null.ro/svn/yate@3797 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
a439e483ce
commit
f359578193
18
configure.in
18
configure.in
|
@ -115,6 +115,19 @@ HAVE_PRCTL="-DHAVE_PRCTL"
|
|||
fi
|
||||
AC_SUBST(HAVE_PRCTL)
|
||||
|
||||
HAVE_POLL=no
|
||||
AC_ARG_ENABLE(poll,AC_HELP_STRING([--enable-poll],[Use poll() on sockets (default: yes)]),want_poll=$enableval,want_poll=yes)
|
||||
if [[ "x$want_poll" = "xyes" ]]; then
|
||||
AC_MSG_CHECKING([for poll])
|
||||
AC_TRY_COMPILE([#include <poll.h>
|
||||
],[
|
||||
struct pollfd fds;
|
||||
poll(&fds,1,1);
|
||||
],HAVE_POLL=yes)
|
||||
AC_MSG_RESULT([$HAVE_POLL])
|
||||
fi
|
||||
AC_SUBST(HAVE_POLL)
|
||||
|
||||
AC_CACHE_SAVE
|
||||
|
||||
SAVE_LIBS="$LIBS"
|
||||
|
@ -266,10 +279,13 @@ AC_TRY_COMPILE([#include <features.h>
|
|||
#error FD_SETSIZE cannot be set
|
||||
#endif],[if (__FD_SETSIZE>10) return 0;],[],[FDSIZE_HACK=""])
|
||||
AC_LANG_RESTORE
|
||||
if [[ "x$FDSIZE_HACK" = "x" ]]; then
|
||||
if [[ "x$FDSIZE_HACK" = "x" -a "x$HAVE_POLL" != "xyes" ]]; then
|
||||
AC_ERROR([Cannot set FD_SETSIZE on this platform, use --without-fdsize])
|
||||
fi
|
||||
fi
|
||||
if [[ "x$HAVE_POLL" = "xyes" ]]; then
|
||||
FDSIZE_HACK="-DHAVE_POLL $FDSIZE_HACK"
|
||||
fi
|
||||
AC_SUBST(FDSIZE_HACK)
|
||||
|
||||
HAVE_SCTP=no
|
||||
|
|
|
@ -35,6 +35,13 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_POLL
|
||||
#include <poll.h>
|
||||
#ifndef POLLRDHUP
|
||||
#define POLLRDHUP 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#undef HAS_AF_UNIX
|
||||
|
||||
#ifndef _WINDOWS
|
||||
|
@ -1502,9 +1509,11 @@ bool Socket::canSelect(SOCKET handle)
|
|||
return false;
|
||||
#ifdef FD_SETSIZE
|
||||
#ifndef _WINDOWS
|
||||
#ifndef HAVE_POLL
|
||||
if (handle >= (SOCKET)FD_SETSIZE)
|
||||
return false;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
@ -1514,6 +1523,33 @@ bool Socket::select(bool* readok, bool* writeok, bool* except, struct timeval* t
|
|||
SOCKET tmp = m_handle;
|
||||
if (!valid())
|
||||
return false;
|
||||
|
||||
#ifdef HAVE_POLL
|
||||
struct pollfd fds;
|
||||
fds.fd = tmp;
|
||||
fds.events = 0;
|
||||
fds.revents = 0;
|
||||
if (readok)
|
||||
fds.events |= POLLIN;
|
||||
if (writeok)
|
||||
fds.events |= POLLOUT;
|
||||
if (except)
|
||||
fds.events |= POLLRDHUP;
|
||||
int tout = -1;
|
||||
if (timeout)
|
||||
tout = (timeout->tv_sec * 1000) + (timeout->tv_usec / 1000);
|
||||
if (checkError(::poll(&fds,1,tout),true)) {
|
||||
if (readok)
|
||||
*readok = (fds.revents & POLLIN) != 0;
|
||||
if (writeok)
|
||||
*writeok = (fds.revents & POLLOUT) != 0;
|
||||
if (except)
|
||||
*except = (fds.revents & (POLLRDHUP|POLLERR|POLLHUP|POLLNVAL)) != 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
#else // HAVE_POLL
|
||||
|
||||
#ifdef FD_SETSIZE
|
||||
#ifndef _WINDOWS
|
||||
static bool localFail = true;
|
||||
|
@ -1555,6 +1591,8 @@ bool Socket::select(bool* readok, bool* writeok, bool* except, struct timeval* t
|
|||
*except = (FD_ISSET(tmp,efds) != 0);
|
||||
return true;
|
||||
}
|
||||
#endif // HAVE_POLL
|
||||
|
||||
if (tmp != m_handle) {
|
||||
if (except)
|
||||
*except = true;
|
||||
|
|
Loading…
Reference in New Issue