Commit 9c8613c6 authored by Pekka Pessi's avatar Pekka Pessi

su_port.c, sofia-sip/su_wait.h: added su_default_port_create() and su_default_clone_start()

su_epoll_port_create() and su_poll_port_create() call
su_default_port_create() if epoll/poll is not available.

Win32 implementation is now created with su_wsaevent_port_create().

darcs-hash:20070209003535-65a35-e02aa5d704fd862c3912bd8e921765aa8ce754f9.gz
parent 4b9903c8
...@@ -524,15 +524,16 @@ typedef int su_clone_start_f(su_root_t *parent, ...@@ -524,15 +524,16 @@ typedef int su_clone_start_f(su_root_t *parent,
SOFIAPUBFUN void su_port_prefer(su_port_create_f *f, su_clone_start_f *); SOFIAPUBFUN void su_port_prefer(su_port_create_f *f, su_clone_start_f *);
SOFIAPUBFUN su_port_t *su_epoll_port_create(void) SOFIAPUBFUN su_port_create_f su_default_port_create;
__attribute__((__malloc__)); SOFIAPUBFUN su_port_create_f su_epoll_port_create;
SOFIAPUBFUN su_port_t *su_poll_port_create(void) SOFIAPUBFUN su_port_create_f su_poll_port_create;
__attribute__((__malloc__)); SOFIAPUBFUN su_port_create_f su_wsaevent_port_create;
SOFIAPUBFUN su_port_t *su_select_port_create(void) SOFIAPUBFUN su_port_create_f su_select_port_create;
__attribute__((__malloc__));
SOFIAPUBFUN su_clone_start_f su_default_clone_start;
SOFIAPUBFUN su_clone_start_f su_epoll_clone_start; SOFIAPUBFUN su_clone_start_f su_epoll_clone_start;
SOFIAPUBFUN su_clone_start_f su_poll_clone_start; 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_select_clone_start;
......
...@@ -36,8 +36,15 @@ ...@@ -36,8 +36,15 @@
#include "config.h" #include "config.h"
#define su_port_s su_epoll_port_s
#include "su_port.h"
#if HAVE_EPOLL #if HAVE_EPOLL
#include "sofia-sip/su.h"
#include "sofia-sip/su_alloc.h"
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <stdarg.h> #include <stdarg.h>
...@@ -46,12 +53,6 @@ ...@@ -46,12 +53,6 @@
#include <limits.h> #include <limits.h>
#include <errno.h> #include <errno.h>
#define su_port_s su_epoll_port_s
#include "sofia-sip/su.h"
#include "su_port.h"
#include "sofia-sip/su_alloc.h"
#include <sys/epoll.h> #include <sys/epoll.h>
#define POLL2EPOLL_NEEDED \ #define POLL2EPOLL_NEEDED \
...@@ -570,18 +571,16 @@ int su_epoll_clone_start(su_root_t *parent, ...@@ -570,18 +571,16 @@ int su_epoll_clone_start(su_root_t *parent,
su_port_t *su_epoll_port_create(void) su_port_t *su_epoll_port_create(void)
{ {
return su_poll_port_create(); return su_default_port_create(void);
} }
int su_epoll_clone_start(su_root_t *parent, int su_epoll_clone_start(su_root_t *parent,
su_clone_r return_clone, su_clone_r return_clone,
su_root_magic_t *magic, su_root_magic_t *magic,
su_root_init_f init, su_root_init_f init,
su_root_deinit_f deinit) su_root_deinit_f deinit)
{ {
return su_pthreaded_port_start(su_poll_port_create, return su_default_clone_start(parent, return_clone, magic, init, deinit);
parent, return_clone, magic, init, deinit);
} }
#endif /* HAVE_EPOLL */ #endif /* HAVE_EPOLL */
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
#include "config.h" #include "config.h"
#if HAVE_POLL || HAVE_SELECT #if HAVE_POLL_PORT
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
...@@ -70,12 +70,7 @@ struct su_poll_port_s { ...@@ -70,12 +70,7 @@ struct su_poll_port_s {
int sup_size_waits; /**< Size of allocated su_waits */ int sup_size_waits; /**< Size of allocated su_waits */
int sup_pri_offset; /**< Offset to prioritized waits */ int sup_pri_offset; /**< Offset to prioritized waits */
#if !SU_HAVE_WINSOCK
#define INDEX_MAX (0x7fffffff) #define INDEX_MAX (0x7fffffff)
#else
/* We use WSAWaitForMultipleEvents() */
#define INDEX_MAX (64)
#endif
/** Indices from index returned by su_root_register() to tables below. /** Indices from index returned by su_root_register() to tables below.
* *
...@@ -676,8 +671,25 @@ int su_poll_clone_start(su_root_t *parent, ...@@ -676,8 +671,25 @@ int su_poll_clone_start(su_root_t *parent,
su_root_init_f init, su_root_init_f init,
su_root_deinit_f deinit) su_root_deinit_f deinit)
{ {
return su_pthreaded_port_start(su_poll_port_create, return su_pthreaded_port_start(su_default_port_create,
parent, return_clone, magic, init, deinit); parent, return_clone, magic, init, deinit);
} }
#endif /* HAVE_POLL || HAVE_SELECT */ #else
su_port_t *su_poll_port_create(void)
{
return su_default_port_create(void);
}
int su_poll_clone_start(su_root_t *parent,
su_clone_r return_clone,
su_root_magic_t *magic,
su_root_init_f init,
su_root_deinit_f deinit)
{
return su_default_clone_start(parent, return_clone, magic, init, deinit);
}
#endif /* HAVE_POLL_PORT */
...@@ -48,7 +48,43 @@ ...@@ -48,7 +48,43 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
static su_port_create_f *preferred_su_port_create; /** Create the default su_port_t implementation. */
su_port_t *su_default_port_create(void)
{
#if HAVE_EPOLL
return su_epoll_port_create();
#elif HAVE_POLL_PORT
return su_poll_port_create();
#elif HAVE_WIN32
return su_wsaevent_port_create();
#elif HAVE_SELECT
return su_select_port_create();
#else
return NULL;
#endif
}
int su_default_clone_start(su_root_t *parent,
su_clone_r return_clone,
su_root_magic_t *magic,
su_root_init_f init,
su_root_deinit_f deinit)
{
#if HAVE_EPOLL
return su_epoll_clone_start(parent, return_clone, magic, init, deinit);;
#elif HAVE_POLL_PORT
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);;
#elif HAVE_SELECT
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_clone_start_f *preferred_su_clone_start; static su_clone_start_f *preferred_su_clone_start;
/** Explicitly set the preferred su_port_t implementation. /** Explicitly set the preferred su_port_t implementation.
...@@ -69,45 +105,44 @@ void su_port_set_system_preferences(char const *name) ...@@ -69,45 +105,44 @@ void su_port_set_system_preferences(char const *name)
if (name == NULL) if (name == NULL)
; ;
#if HAVE_POLL_PORT
#if HAVE_EPOLL #if HAVE_EPOLL
else if (strcmp(name, "epoll") == 0) { else if (strcmp(name, "epoll") == 0) {
create = su_epoll_port_create; create = su_epoll_port_create;
start = su_epoll_clone_start; start = su_epoll_clone_start;
} }
#endif #endif
#if HAVE_POLL_PORT
else if (strcmp(name, "poll") == 0) { else if (strcmp(name, "poll") == 0) {
create = su_poll_port_create; create = su_poll_port_create;
start = su_poll_clone_start; start = su_poll_clone_start;
} }
#else
/* select port does not work yet */
#error no poll!
#endif #endif
#if HAVE_SELECT #if HAVE_WIN32
else if (strcasecmp(name, "wsaevent") == 0) {
create = su_wsaevent_port_create;
start = su_wsaevent_clone_start;
}
#endif
#if HAVE_SELECT && !HAVE_WIN32
else if (strcmp(name, "select") == 0) { else if (strcmp(name, "select") == 0) {
create = su_select_port_create; create = su_select_port_create;
start = su_select_clone_start; start = su_select_clone_start;
} }
#endif #endif
#if HAVE_POLL_PORT if (create == NULL)
#if HAVE_EPOLL create = su_default_port_create;
if (create == NULL) create = su_epoll_port_create;
if (start == NULL) start = su_epoll_clone_start; if (!preferred_su_port_create ||
#else preferred_su_port_create == su_default_port_create)
if (create == NULL) create = su_poll_port_create; preferred_su_port_create = create;
if (start == NULL) start = su_poll_clone_start;
#endif if (start == NULL)
#else start = su_default_clone_start;
#if HAVE_SELECT
if (create == NULL) create = su_select_port_create;
if (start == NULL) start = su_select_clone_start;
#endif
#endif
if (preferred_su_port_create == NULL) preferred_su_port_create = create; if (!preferred_su_clone_start ||
if (preferred_su_clone_start == NULL) preferred_su_clone_start = start; preferred_su_clone_start == su_default_clone_start)
preferred_su_clone_start = start;
} }
/** Create the preferred su_port_t implementation. */ /** Create the preferred su_port_t implementation. */
...@@ -116,10 +151,7 @@ su_port_t *su_port_create(void) ...@@ -116,10 +151,7 @@ su_port_t *su_port_create(void)
if (preferred_su_port_create == NULL) if (preferred_su_port_create == NULL)
su_port_set_system_preferences(getenv("SU_PORT")); su_port_set_system_preferences(getenv("SU_PORT"));
if (preferred_su_port_create) return preferred_su_port_create();
return preferred_su_port_create();
return NULL;
} }
/* ======================================================================== /* ========================================================================
...@@ -244,8 +276,6 @@ int su_clone_start(su_root_t *parent, ...@@ -244,8 +276,6 @@ int su_clone_start(su_root_t *parent,
if (parent == NULL || parent->sur_threading) { if (parent == NULL || parent->sur_threading) {
if (preferred_su_clone_start == NULL) if (preferred_su_clone_start == NULL)
su_port_set_system_preferences(getenv("SU_PORT")); su_port_set_system_preferences(getenv("SU_PORT"));
if (preferred_su_clone_start == NULL)
return -1;
return preferred_su_clone_start(parent, return_clone, magic, init, deinit); return preferred_su_clone_start(parent, return_clone, magic, init, deinit);
} }
......
This diff is collapsed.
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
#undef HAVE_POLL #undef HAVE_POLL
/* Define to 1 if you use poll in su_port. */ /* Define to 1 if you use poll in su_port. */
#define HAVE_POLL_PORT 1 #undef HAVE_POLL_PORT
/* Define to 1 if you have /proc/net/if_inet6 control file */ /* Define to 1 if you have /proc/net/if_inet6 control file */
#undef HAVE_PROC_NET_IF_INET6 #undef HAVE_PROC_NET_IF_INET6
......
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