Commit 367cdcdd authored by Remi Denis-Courmont's avatar Remi Denis-Courmont

Network change without pthread

Make room for network change implementation that would not need pthread.
BSD(AF_ROUTE) and Linux(AF_NETLINK) would typically only need to
register a socket to the root object, which is more lightweight.

Also some cosmetic fixes.

darcs-hash:20070124104255-9301c-583bbbddabbd3dd2add51a8a22accb7b7139c05e.gz
parent 8e6217fa
...@@ -46,10 +46,14 @@ ...@@ -46,10 +46,14 @@
#include "sofia-sip/su_os_nw.h" #include "sofia-sip/su_os_nw.h"
#include "sofia-sip/su_debug.h" #include "sofia-sip/su_debug.h"
/* Works only with pthreads */ #if defined(__APPLE_CC__)
#if SU_HAVE_PTHREADS # define SU_NW_CHANGE_PTHREAD 1
#endif
#include <pthread.h> #if defined (SU_NW_CHANGE_PTHREAD)
# define SU_HAVE_NW_CHANGE 1
# include <pthread.h>
#endif
#if defined(__APPLE_CC__) #if defined(__APPLE_CC__)
#include <AvailabilityMacros.h> #include <AvailabilityMacros.h>
...@@ -68,8 +72,9 @@ struct su_network_changed_s { ...@@ -68,8 +72,9 @@ struct su_network_changed_s {
SCDynamicStoreRef su_storeRef[1]; SCDynamicStoreRef su_storeRef[1];
CFRunLoopSourceRef su_sourceRef[1]; CFRunLoopSourceRef su_sourceRef[1];
#endif #endif
#if defined (SU_NW_CHANGE_PTHREAD)
pthread_t su_os_thread; pthread_t su_os_thread;
#endif
su_network_changed_f *su_network_changed_cb; su_network_changed_f *su_network_changed_cb;
su_network_changed_magic_t *su_network_changed_magic; su_network_changed_magic_t *su_network_changed_magic;
...@@ -109,7 +114,7 @@ void nw_changed_cb(SCDynamicStoreRef store, ...@@ -109,7 +114,7 @@ void nw_changed_cb(SCDynamicStoreRef store,
sizeof *snc) == SU_FAILURE) { sizeof *snc) == SU_FAILURE) {
return; return;
} }
snc2 = su_msg_data(rmsg); assert(snc2); snc2 = su_msg_data(rmsg); assert(snc2);
snc2->su_root = snc->su_root; snc2->su_root = snc->su_root;
...@@ -119,7 +124,7 @@ void nw_changed_cb(SCDynamicStoreRef store, ...@@ -119,7 +124,7 @@ void nw_changed_cb(SCDynamicStoreRef store,
snc2->su_os_thread = snc->su_os_thread; snc2->su_os_thread = snc->su_os_thread;
snc2->su_network_changed_cb = snc->su_network_changed_cb; snc2->su_network_changed_cb = snc->su_network_changed_cb;
snc2->su_network_changed_magic = snc->su_network_changed_magic; snc2->su_network_changed_magic = snc->su_network_changed_magic;
if (su_msg_send(rmsg) == SU_FAILURE) { if (su_msg_send(rmsg) == SU_FAILURE) {
su_msg_destroy(rmsg); su_msg_destroy(rmsg);
return; return;
...@@ -219,10 +224,7 @@ CreateIPAddressListChangeCallbackSCF(SCDynamicStoreCallBack callback, ...@@ -219,10 +224,7 @@ CreateIPAddressListChangeCallbackSCF(SCDynamicStoreCallBack callback,
return err; return err;
} }
#endif /* __APPLE_CC__ */
#if defined(__APPLE_CC__)
static void *su_start_nw_os_thread(void *ptr) static void *su_start_nw_os_thread(void *ptr)
{ {
su_network_changed_t *snc = (su_network_changed_t *) ptr; su_network_changed_t *snc = (su_network_changed_t *) ptr;
...@@ -249,19 +251,13 @@ su_network_changed_t ...@@ -249,19 +251,13 @@ su_network_changed_t
su_network_changed_f *network_changed_cb, su_network_changed_f *network_changed_cb,
su_network_changed_magic_t *magic) su_network_changed_magic_t *magic)
{ {
#if defined (__APPLE_CC__)
su_network_changed_t *snc = NULL; su_network_changed_t *snc = NULL;
#endif
assert(home && root && network_changed_cb && magic); assert(home && root && network_changed_cb && magic);
/* Not implemented for others than OSX */ #if defined (SU_HAVE_NW_CHANGE)
#if !defined (__APPLE_CC__)
return NULL;
#else
snc = su_zalloc(home, sizeof *snc); snc = su_zalloc(home, sizeof *snc);
if (!snc) if (!snc)
return NULL; return NULL;
...@@ -269,15 +265,16 @@ su_network_changed_t ...@@ -269,15 +265,16 @@ su_network_changed_t
snc->su_root = root; snc->su_root = root;
snc->su_network_changed_cb = network_changed_cb; snc->su_network_changed_cb = network_changed_cb;
snc->su_network_changed_magic = magic; snc->su_network_changed_magic = magic;
# if defined (SU_NW_CHANGE_PTHREAD)
if ((pthread_create(&(snc->su_os_thread), NULL, if ((pthread_create(&(snc->su_os_thread), NULL,
su_start_nw_os_thread, su_start_nw_os_thread,
(void *) snc)) != 0) { (void *) snc)) != 0) {
return NULL; return NULL;
} }
# endif
return snc;
#endif #endif
return snc;
} }
/** Remove a callback registered for the network change event. /** Remove a callback registered for the network change event.
...@@ -288,20 +285,3 @@ int su_root_remove_network_changed(su_network_changed_t *snc) ...@@ -288,20 +285,3 @@ int su_root_remove_network_changed(su_network_changed_t *snc)
{ {
return -1; return -1;
} }
#else
su_network_changed_t
*su_root_add_network_changed(su_home_t *home, su_root_t *root,
su_network_changed_f *network_changed_cb,
su_network_changed_magic_t *magic)
{
return NULL;
}
int su_root_remove_network_changed(su_network_changed_t *snc)
{
return -1;
}
#endif /* SU_HAVE_PTHREADS */
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