Commit d40ad7e6 authored by Martti Mela's avatar Martti Mela
Browse files

Support for CygWin's (buggy) pthread implementation. Added SU_HAVE_IN6

for disabling IPv6 support from the environments that do not support IPv6.

darcs-hash:20051130173522-1b897-1672b8dad9d15031db46d9d6dd001241eee5cbe0.gz
parent 2b7a5fc5
...@@ -97,7 +97,11 @@ void usage(void) ...@@ -97,7 +97,11 @@ void usage(void)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
#if SU_HAVE_IN6
char buffer[INET6_ADDRSTRLEN]; char buffer[INET6_ADDRSTRLEN];
#else
char buffer[20];
#endif
su_addrinfo_t hints[1] = {{ 0 }}; su_addrinfo_t hints[1] = {{ 0 }};
su_addrinfo_t *ai, *res = NULL; su_addrinfo_t *ai, *res = NULL;
char const *host, *service; char const *host, *service;
...@@ -106,7 +110,9 @@ int main(int argc, char *argv[]) ...@@ -106,7 +110,9 @@ int main(int argc, char *argv[])
for (;;) { for (;;) {
switch(getopt(argc, argv, "ndp4c")) { switch(getopt(argc, argv, "ndp4c")) {
case '4': hints->ai_family = AF_INET; break; case '4': hints->ai_family = AF_INET; break;
#if SU_HAVE_IN6
case '6': hints->ai_family = AF_INET6; break; case '6': hints->ai_family = AF_INET6; break;
#endif
case 'p': hints->ai_flags |= AI_PASSIVE; break; case 'p': hints->ai_flags |= AI_PASSIVE; break;
case 'n': hints->ai_flags |= AI_NUMERICHOST; break; case 'n': hints->ai_flags |= AI_NUMERICHOST; break;
case 'c': hints->ai_flags |= AI_CANONNAME; break; case 'c': hints->ai_flags |= AI_CANONNAME; break;
...@@ -133,8 +139,13 @@ int main(int argc, char *argv[]) ...@@ -133,8 +139,13 @@ int main(int argc, char *argv[])
su_sockaddr_t const *su = (su_sockaddr_t const *)ai->ai_addr; su_sockaddr_t const *su = (su_sockaddr_t const *)ai->ai_addr;
unsigned port; unsigned port;
#if SU_HAVE_IN6
if (su->su_family != AF_INET6 && su->su_family != AF_INET) if (su->su_family != AF_INET6 && su->su_family != AF_INET)
continue; continue;
#else
if (su->su_family != AF_INET)
continue;
#endif
port = ntohs(su->su_port); port = ntohs(su->su_port);
inet_ntop(ai->ai_family, SU_ADDR(su), buffer, sizeof(buffer)); inet_ntop(ai->ai_family, SU_ADDR(su), buffer, sizeof(buffer));
......
...@@ -124,7 +124,11 @@ void usage(int returncode) ...@@ -124,7 +124,11 @@ void usage(int returncode)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
#if SU_HAVE_IN6
char buffer[INET6_ADDRSTRLEN]; char buffer[INET6_ADDRSTRLEN];
#else
char buffer[20];
#endif
su_localinfo_t hints[1] = {{ LI_CANONNAME }}; su_localinfo_t hints[1] = {{ LI_CANONNAME }};
su_localinfo_t *li, *res = NULL; su_localinfo_t *li, *res = NULL;
int error; int error;
...@@ -140,7 +144,9 @@ int main(int argc, char *argv[]) ...@@ -140,7 +144,9 @@ int main(int argc, char *argv[])
case 'i': hints->li_flags |= LI_IFNAME; ifindex = 1; break; case 'i': hints->li_flags |= LI_IFNAME; ifindex = 1; break;
case 'm': hints->li_flags |= LI_V4MAPPED; break; case 'm': hints->li_flags |= LI_V4MAPPED; break;
case '4': hints->li_family = AF_INET; break; case '4': hints->li_family = AF_INET; break;
#if SU_HAVE_IN6
case '6': hints->li_family = AF_INET6; break; case '6': hints->li_family = AF_INET6; break;
#endif
case 'd': hints->li_flags |= LI_NAMEREQD; break; case 'd': hints->li_flags |= LI_NAMEREQD; break;
case 'n': hints->li_flags |= LI_NUMERIC; break; case 'n': hints->li_flags |= LI_NUMERIC; break;
case 'g': hints->li_scope |= LI_SCOPE_GLOBAL; break; case 'g': hints->li_scope |= LI_SCOPE_GLOBAL; break;
......
...@@ -443,7 +443,8 @@ int localinfo4(su_localinfo_t const *hints, su_localinfo_t **rresult) ...@@ -443,7 +443,8 @@ int localinfo4(su_localinfo_t const *hints, su_localinfo_t **rresult)
#endif #endif
#else #else
#error su_localinfo() cannot map interface name to number #warning su_localinfo() cannot map interface name to number
if_index = 0;
#endif #endif
SU_DEBUG_9(("su_localinfo: if %s with index %d\n", if_name, if_index)); SU_DEBUG_9(("su_localinfo: if %s with index %d\n", if_name, if_index));
...@@ -1186,8 +1187,10 @@ void li_sort(su_localinfo_t *i, su_localinfo_t **rresult) ...@@ -1186,8 +1187,10 @@ void li_sort(su_localinfo_t *i, su_localinfo_t **rresult)
for (lli = rresult; *lli; lli = &(*lli)->li_next) { for (lli = rresult; *lli; lli = &(*lli)->li_next) {
if ((*lli)->li_scope < li->li_scope) if ((*lli)->li_scope < li->li_scope)
break; break;
#if SU_HAVE_IN6
if (LI_MAPPED(*lli) > LI_MAPPED(li)) if (LI_MAPPED(*lli) > LI_MAPPED(li))
break; break;
#endif
} }
li->li_next = *lli; li->li_next = *lli;
*lli = li; *lli = li;
......
...@@ -184,7 +184,12 @@ struct su_port_s { ...@@ -184,7 +184,12 @@ struct su_port_s {
#if SU_HAVE_PTHREADS #if SU_HAVE_PTHREADS
pthread_t sup_tid; pthread_t sup_tid;
pthread_mutex_t sup_mutex[1]; pthread_mutex_t sup_mutex[1];
#if __CYGWIN__
pthread_mutex_t sup_reflock[1];
int sup_ref;
#else
pthread_rwlock_t sup_ref[1]; pthread_rwlock_t sup_ref[1];
#endif
#else #else
int sup_ref; int sup_ref;
#endif #endif
...@@ -235,7 +240,33 @@ struct su_port_s { ...@@ -235,7 +240,33 @@ struct su_port_s {
#if SU_HAVE_PTHREADS #if SU_HAVE_PTHREADS
#define SU_PORT_OWN_THREAD(p) (pthread_equal((p)->sup_tid, pthread_self())) #define SU_PORT_OWN_THREAD(p) (pthread_equal((p)->sup_tid, pthread_self()))
#if 1 #if __CYGWIN__
/* Debugging versions */
#define SU_PORT_INITREF(p) (pthread_mutex_init((p)->sup_reflock, NULL), printf("initref(%p)\n", (p)))
#define SU_PORT_INCREF(p, f) (pthread_mutex_lock(p->sup_reflock), p->sup_ref++, pthread_mutex_unlock(p->sup_reflock), printf("incref(%p) by %s\n", (p), f))
#define SU_PORT_DECREF(p, f) do { \
pthread_mutex_lock(p->sup_reflock); p->sup_ref--; pthread_mutex_unlock(p->sup_reflock); \
if ((p->sup_ref) == 0) { \
printf("decref(%p) to 0 by %s\n", (p), f); su_port_destroy(p); } \
else { printf("decref(%p) to %u by %s\n", (p), p->sup_ref, f); } } while(0)
#define SU_PORT_ZAPREF(p, f) do { printf("zapref(%p) by %s\n", (p), f), \
pthread_mutex_lock(p->sup_reflock); p->sup_ref--; pthread_mutex_unlock(p->sup_reflock); \
if ((p->sup_ref) != 0) { \
assert(!"SU_PORT_ZAPREF"); } \
su_port_destroy(p); } while(0)
#define SU_PORT_INITLOCK(p) \
(pthread_mutex_init((p)->sup_mutex, NULL), printf("init_lock(%p)\n", p))
#define SU_PORT_LOCK(p, f) \
(printf("%ld at %s locking(%p)...", pthread_self(), f, p), pthread_mutex_lock((p)->sup_mutex), printf(" ...%ld at %s locked(%p)...", pthread_self(), f, p))
#define SU_PORT_UNLOCK(p, f) \
(pthread_mutex_unlock((p)->sup_mutex), printf(" ...%ld at %s unlocked(%p)\n", pthread_self(), f, p))
#elif 1
#define SU_PORT_INITREF(p) (pthread_rwlock_init(p->sup_ref, NULL)) #define SU_PORT_INITREF(p) (pthread_rwlock_init(p->sup_ref, NULL))
#define SU_PORT_INCREF(p, f) (pthread_rwlock_rdlock(p->sup_ref)) #define SU_PORT_INCREF(p, f) (pthread_rwlock_rdlock(p->sup_ref))
#define SU_PORT_DECREF(p, f) do { pthread_rwlock_unlock(p->sup_ref); \ #define SU_PORT_DECREF(p, f) do { pthread_rwlock_unlock(p->sup_ref); \
...@@ -432,6 +463,7 @@ void su_port_destroy(su_port_t *self) ...@@ -432,6 +463,7 @@ void su_port_destroy(su_port_t *self)
#if HAVE_SOCKETPAIR #if HAVE_SOCKETPAIR
su_close(self->sup_mbox[1]); self->sup_mbox[1] = INVALID_SOCKET; su_close(self->sup_mbox[1]); self->sup_mbox[1] = INVALID_SOCKET;
#endif #endif
SU_DEBUG_9(("su_port_destroy() close mailbox\n"));
} }
#endif #endif
if (self->sup_waits) if (self->sup_waits)
...@@ -447,7 +479,12 @@ void su_port_destroy(su_port_t *self) ...@@ -447,7 +479,12 @@ void su_port_destroy(su_port_t *self)
if (self->sup_indices) if (self->sup_indices)
free(self->sup_indices), self->sup_indices = NULL; free(self->sup_indices), self->sup_indices = NULL;
SU_DEBUG_9(("su_port_destroy() freed registrations\n"));
su_home_zap(self->sup_home); su_home_zap(self->sup_home);
SU_DEBUG_9(("su_port_destroy() returns\n"));
} }
static void su_port_lock(su_port_t *self, char const *who) static void su_port_lock(su_port_t *self, char const *who)
......
...@@ -178,9 +178,11 @@ int pr_config(proxy_t *pr, int argc, char *argv[]) ...@@ -178,9 +178,11 @@ int pr_config(proxy_t *pr, int argc, char *argv[])
else if (strcmp(option, "-4") == 0) { else if (strcmp(option, "-4") == 0) {
hints->ai_family = AF_INET; hints->ai_family = AF_INET;
} }
#if SU_HAVE_IN6
else if (strcmp(option, "-6") == 0) { else if (strcmp(option, "-6") == 0) {
hints->ai_family = AF_INET6; hints->ai_family = AF_INET6;
} }
#endif
} }
if (argc < 3) if (argc < 3)
......
...@@ -112,7 +112,7 @@ int init_test(root_test_t *rt) ...@@ -112,7 +112,7 @@ int init_test(root_test_t *rt)
if (SU_HAS_INADDR_ANY(ep->addr)) { if (SU_HAS_INADDR_ANY(ep->addr)) {
inet_pton(su->su_family, inet_pton(su->su_family,
su->su_family == AF_INET ? "127.0.0.1" : "::1", su->su_family == AF_INET ? "127.0.0.1" : "::1",
SU_ADDR(su)); SU_ADDR(ep->addr));
} }
} }
...@@ -334,8 +334,10 @@ int main(int argc, char *argv[]) ...@@ -334,8 +334,10 @@ int main(int argc, char *argv[])
for (i = 1; argv[i]; i++) { for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0) if (strcmp(argv[i], "-v") == 0)
rt->rt_flags |= tst_verbatim; rt->rt_flags |= tst_verbatim;
#if SU_HAVE_IN6
else if (strcmp(argv[i], "-6") == 0) else if (strcmp(argv[i], "-6") == 0)
rt->rt_family = AF_INET6; rt->rt_family = AF_INET6;
#endif
else else
usage(); usage();
} }
......
...@@ -434,14 +434,16 @@ int main(int argc, char *argv[]) ...@@ -434,14 +434,16 @@ int main(int argc, char *argv[])
char *argv0 = argv[0]; char *argv0 = argv[0];
while (argv[1]) { while (argv[1]) {
if (strcmp(argv[1], "-6") == 0) { if (strcmp(argv[1], "-v") == 0) {
opt_family = AF_INET6; opt_verbatim = 1;
argv++; argv++;
} }
else if (strcmp(argv[1], "-v") == 0) { #if SU_HAVE_IN6
opt_verbatim = 1; else if (strcmp(argv[1], "-6") == 0) {
opt_family = AF_INET6;
argv++; argv++;
} }
#endif
else if (strcmp(argv[1], "-s") == 0) { else if (strcmp(argv[1], "-s") == 0) {
opt_singlethread = 1; opt_singlethread = 1;
argv++; argv++;
......
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