Commit 05dd9730 authored by Pekka Pessi's avatar Pekka Pessi

su: added su_devpoll_port.c, checks for it in configure and hooks to it.

Added su_root_name() and su_port_name() functions to API.

darcs-hash:20070222210558-88462-e6574b8fce46199f5c03887bad1ee66e9d2fcf9b.gz
parent 3ae8384c
......@@ -81,6 +81,7 @@ libsu_la_SOURCES = \
su_port.c su_port.h \
su_base_port.c su_pthread_port.c su_socket_port.c \
su_poll_port.c su_epoll_port.c su_select_port.c su_kqueue_port.c \
su_devpoll_port.c \
su_localinfo.c \
su_os_nw.c \
su_taglist.c su_tag.c su_tag_io.c \
......
......@@ -4,11 +4,11 @@ rc=0
run=no
for SU_PORT in select epoll poll ; do
for SU_PORT in select kqueue devpoll epoll poll ; do
export SU_PORT
grep -q -i '^#define have_'$SU_PORT ../../config.h ||
egrep -q -i '^#define have_(sys_)?'$SU_PORT ../../config.h ||
continue
run=yes
......
......@@ -54,8 +54,6 @@
#undef SU_HAVE_PTHREADS
/** Define as 1 if you have poll() */
#undef SU_HAVE_POLL
/** Define as 1 if you have kqueue() */
#undef SU_HAVE_KQUEUE
/** Define as 1 if you have IPv6 structures, macros and constants */
#undef SU_HAVE_IN6
......
......@@ -441,6 +441,7 @@ su_socket_t su_wait_socket(su_wait_t *wait)
SOFIAPUBFUN su_root_t *su_root_create(su_root_magic_t *magic)
__attribute__((__malloc__));
SOFIAPUBFUN void su_root_destroy(su_root_t*);
SOFIAPUBFUN char const *su_root_name(su_root_t *self);
SOFIAPUBFUN int su_root_set_magic(su_root_t *self, su_root_magic_t *magic);
SOFIAPUBFUN su_root_magic_t *su_root_magic(su_root_t *root);
SOFIAPUBFUN int su_root_register(su_root_t*, su_wait_t *,
......@@ -569,6 +570,7 @@ SOFIAPUBFUN su_port_create_f su_poll_port_create;
SOFIAPUBFUN su_port_create_f su_wsaevent_port_create;
SOFIAPUBFUN su_port_create_f su_select_port_create;
SOFIAPUBFUN su_port_create_f su_kqueue_port_create;
SOFIAPUBFUN su_port_create_f su_devpoll_port_create;
SOFIAPUBFUN su_clone_start_f su_default_clone_start;
SOFIAPUBFUN su_clone_start_f su_epoll_clone_start;
......@@ -576,7 +578,7 @@ SOFIAPUBFUN su_clone_start_f su_poll_clone_start;
SOFIAPUBFUN su_clone_start_f su_wsaevent_clone_start;
SOFIAPUBFUN su_clone_start_f su_select_clone_start;
SOFIAPUBFUN su_clone_start_f su_kqueue_clone_start;
SOFIAPUBFUN su_clone_start_f su_devpoll_clone_start;
SOFIA_END_DECLS
......
This diff is collapsed.
......@@ -39,7 +39,7 @@
#include "su_port.h"
#if SU_HAVE_KQUEUE
#if HAVE_KQUEUE
#include "sofia-sip/su_alloc.h"
......@@ -708,5 +708,5 @@ int su_kqueue_clone_start(su_root_t *parent,
return su_default_clone_start(parent, return_clone, magic, init, deinit);
}
#endif /* SU_HAVE_KQUEUE */
#endif /* HAVE_KQUEUE */
......@@ -53,10 +53,12 @@ su_port_t *su_default_port_create(void)
{
#if HAVE_EPOLL
return su_epoll_port_create();
#elif HAVE_KQUEUE
return su_kqueue_port_create();
#elif HAVE_SYS_DEVPOLL_H
return su_devpoll_port_create();
#elif HAVE_POLL_PORT
return su_poll_port_create();
#elif SU_HAVE_KQUEUE
return su_kqueue_port_create();
#elif HAVE_WIN32
return su_wsaevent_port_create();
#elif HAVE_SELECT
......@@ -73,22 +75,24 @@ int su_default_clone_start(su_root_t *parent,
su_root_deinit_f deinit)
{
#if HAVE_EPOLL
return su_epoll_clone_start(parent, return_clone, magic, init, deinit);;
#elif SU_HAVE_KQUEUE
return su_kqueue_clone_start(parent, return_clone, magic, init, deinit);;
return su_epoll_clone_start(parent, return_clone, magic, init, deinit);
#elif HAVE_KQUEUE
return su_kqueue_clone_start(parent, return_clone, magic, init, deinit);
#elif HAVE_SYS_DEVPOLL_H
return su_devpoll_clone_start(parent, return_clone, magic, init, deinit);
#elif HAVE_POLL_PORT
return su_poll_clone_start(parent, return_clone, magic, init, deinit);;
return su_poll_clone_start(parent, return_clone, magic, init, deinit);
#elif HAVE_WIN32
return su_wsaevent_clone_start(parent, return_clone, magic, init, deinit);;
return su_wsaevent_clone_start(parent, return_clone, magic, init, deinit);
#elif HAVE_SELECT
return su_select_clone_start(parent, return_clone, magic, init, deinit);;
return su_select_clone_start(parent, return_clone, magic, init, deinit);
#else
errno = ENOSYS;
return -1;
#endif
}
static su_port_create_f *preferred_su_port_create = su_default_port_create;
static su_port_create_f *preferred_su_port_create;
static su_clone_start_f *preferred_su_clone_start;
/** Explicitly set the preferred su_port_t implementation.
......@@ -115,12 +119,18 @@ void su_port_set_system_preferences(char const *name)
start = su_epoll_clone_start;
}
#endif
#if SU_HAVE_KQUEUE
#if HAVE_KQUEUE
else if (strcmp(name, "kqueue") == 0) {
create = su_kqueue_port_create;
start = su_kqueue_clone_start;
}
#endif
#if HAVE_SYS_DEVPOLL_H
else if (strcmp(name, "devpoll") == 0) {
create = su_devpoll_port_create;
start = su_devpoll_clone_start;
}
#endif
#if HAVE_POLL_PORT
else if (strcmp(name, "poll") == 0) {
create = su_poll_port_create;
......@@ -132,8 +142,7 @@ void su_port_set_system_preferences(char const *name)
create = su_wsaevent_port_create;
start = su_wsaevent_clone_start;
}
#endif
#if HAVE_SELECT && !HAVE_WIN32 && !SU_HAVE_KQUEUE
#elif HAVE_SELECT
else if (strcmp(name, "select") == 0) {
create = su_select_port_create;
start = su_select_clone_start;
......@@ -164,6 +173,12 @@ su_port_t *su_port_create(void)
return preferred_su_port_create();
}
/** Return name of the su_port_t instance. */
char const *su_port_name(su_port_t const *port)
{
return port->sup_vtable->su_port_name(port);
}
/* ========================================================================
* su_clone_t
*/
......
......@@ -159,6 +159,10 @@ SOFIAPUBFUN su_root_t *su_root_create_with_port(su_root_magic_t *magic,
su_port_t *port)
__attribute__((__malloc__));
/* Extension from >= 1.12.6 */
SOFIAPUBFUN char const *su_port_name(su_port_t const *port);
/* ---------------------------------------------------------------------- */
/* React to multiple events per one poll() to make sure
......
......@@ -452,6 +452,22 @@ void su_root_destroy(su_root_t *self)
su_port_decref(port, "su_root_destroy");
}
/** Get instance name.
*
* @param self pointer to a root object
*
* @return Instance name (e.g., "epoll", "devpoll", "select").
*
* @NEW_1_12_6
*/
char const *su_root_name(su_root_t *self)
{
if (self && self->sur_task->sut_port)
return su_port_name(self->sur_task->sut_port);
else
return NULL;
}
/** Set the context pointer.
*
* Set the context pointer (magic) of a root object.
......
......@@ -150,34 +150,6 @@ int su_wait_create(su_wait_t *newwait, su_socket_t socket, int events)
*newwait = h;
#elif SU_HAVE_KQUEUE
int mode;
if (newwait == NULL || events == 0 || socket == INVALID_SOCKET) {
su_seterrno(EINVAL);
return -1;
}
mode = fcntl(socket, F_GETFL, 0);
if (mode < 0)
return -1;
mode |= O_NDELAY | O_NONBLOCK;
if (fcntl(socket, F_SETFL, mode) < 0)
return -1;
#if 0
newwait->ident = socket;
newwait->filter = POLL2KQUEUE(events);
newwait->flags = EV_ENABLE;
newwait->fflags = 0;
newwait->data = 0;
newwait->udata = NULL;
#endif
EV_SET(newwait, socket,
events, EV_ADD,
0, 0, 0);
#elif SU_HAVE_POLL || HAVE_SELECT
int mode;
......@@ -216,10 +188,6 @@ int su_wait_destroy(su_wait_t *waitobj)
su_wait_t w0 = NULL;
if (*waitobj)
WSACloseEvent(*waitobj);
#elif SU_HAVE_KQUEUE
su_wait_t w0 = { 0 }; /* { INVALID_SOCKET, 0, EV_DELETE, 0, 0, NULL }; */
EV_SET(&w0, waitobj->ident, EVFILT_READ, EV_DELETE, 0, 0, 0);
/* XXX -- mela: should we EV_SET with EV_DISABLE here? */
#elif SU_HAVE_POLL || HAVE_SELECT
su_wait_t w0 = { INVALID_SOCKET, 0, 0 };
#else
......@@ -266,8 +234,6 @@ int su_wait(su_wait_t waits[], unsigned n, su_duration_t timeout)
else
return i;
#elif SU_HAVE_KQUEUE
return -1;
#elif SU_HAVE_POLL || HAVE_SELECT
for (;;) {
int i = poll(waits, n, timeout);
......@@ -310,9 +276,6 @@ int su_wait_events(su_wait_t *waitobj, su_socket_t s)
return net_events.lNetworkEvents;
#elif SU_HAVE_KQUEUE
return -1;
#elif SU_HAVE_POLL || HAVE_SELECT
/* poll(e, 1, 0); */
return waitobj->revents;
......@@ -342,8 +305,7 @@ int su_wait_mask(su_wait_t *waitobj, su_socket_t s, int events)
WSASetLastError(error);
return -1;
}
#elif SU_HAVE_KQUEUE
return -1;
#elif SU_HAVE_POLL || HAVE_SELECT
waitobj->fd = s;
waitobj->events = events;
......
......@@ -542,6 +542,9 @@ int main(int argc, char *argv[])
root = su_root_create(NULL);
if (!root) perror("su_root_create"), exit(1);
fprintf(stdout, "test_su: testing %s port implementation\n",
su_root_name(root));
su_root_threading(root, !opt_singlethread);
......
......@@ -37,7 +37,7 @@
#include "config.h"
char const *name = "su_root_test";
char const *name = "torture_su_root";
#include <stdio.h>
#include <string.h>
......@@ -104,12 +104,8 @@ int init_test(root_test_t *rt)
BEGIN();
su_init();
su->su_family = rt->rt_family;
TEST_1(rt->rt_root = su_root_create(rt));
for (i = 0; i < 5; i++) {
test_ep_t *ep = rt->rt_ep[i];
ep->i = i;
......@@ -544,10 +540,16 @@ int main(int argc, char *argv[])
} prefer[] =
{
{ NULL, NULL, "default" },
#if HAVE_POLL_PORT
#if HAVE_EPOLL
{ su_epoll_port_create, su_epoll_clone_start, "epoll", },
#endif
#if HAVE_KQUEUE
{ su_kqueue_port_create, su_kqueue_clone_start, "kqueue", },
#endif
#if HAVE_SYS_DEVPOLL_H
{ su_devpoll_port_create, su_devpoll_clone_start, "devpoll", },
#endif
#if HAVE_POLL_PORT
{ su_poll_port_create, su_poll_clone_start, "poll" },
#endif
#if HAVE_SELECT
......@@ -574,10 +576,14 @@ int main(int argc, char *argv[])
do {
rt = rt1, *rt = *rt0;
printf("%s: testing %s implementation\n",
name, prefer[i].preference);
su_port_prefer(prefer[i].create, prefer[i].start);
TEST_1(rt->rt_root = su_root_create(rt));
printf("%s: testing %s (%s) implementation\n",
name, prefer[i].preference, su_root_name(rt->rt_root));
retval |= init_test(rt);
retval |= register_test(rt);
retval |= event_test(rt);
......
......@@ -241,7 +241,7 @@ dnl no winsock2
SAC_SU_DEFINE([SU_HAVE_BSDSOCK], 1, [Define to 1 if you have BSD socket interface])
AC_CHECK_HEADERS([sys/socket.h sys/ioctl.h sys/filio.h sys/sockio.h \
sys/select.h sys/epoll.h])
sys/select.h sys/epoll.h sys/devpoll.h])
AC_CHECK_HEADERS([netinet/in.h arpa/inet.h netdb.h \
net/if.h net/if_types.h ifaddr.h netpacket/packet.h],,,
[
......@@ -445,7 +445,7 @@ AC_FUNC_ALLOCA
AC_CHECK_FUNCS([gettimeofday strerror random initstate tcsetattr flock \
socketpair gethostname gethostbyname getipnodebyname \
poll epoll_create select if_nameindex \
poll epoll_create kqueue select if_nameindex \
signal alarm \
getaddrinfo getnameinfo freeaddrinfo gai_strerror getifaddrs \
getline getdelim getpass])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment