compiles cleaner on ming32, socketpair compat.

git-svn-id: file:///svn/unbound/trunk@1120 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2008-06-13 15:32:16 +00:00
parent 39e4ba0e78
commit 148e8a69c9
6 changed files with 5165 additions and 6230 deletions

34
compat/socketpair.c Normal file
View file

@ -0,0 +1,34 @@
/* socketpair.c - windows mingw32 replacement for socketpair.
* creates a pipe that works like a socketpair a bit
* Taken from libevent-1.4.3.stable WIN32-Code/misc.c
* License: BSD.
*/
#include "config.h"
#include <stdio.h>
#include <windows.h>
int
socketpair(int d, int type, int protocol, int *sv)
{
static int count;
char buf[64];
HANDLE fd;
DWORD dwMode;
(void)d; (void)type; (void)protocol;
sprintf(buf, "\\\\.\\pipe\\levent-%d", count++);
/* Create a duplex pipe which will behave like a socket pair */
fd = CreateNamedPipe(buf, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_NOWAIT,
PIPE_UNLIMITED_INSTANCES, 4096, 4096, 0, NULL);
if (fd == INVALID_HANDLE_VALUE)
return (-1);
sv[0] = (int)fd;
fd = CreateFile(buf, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (fd == INVALID_HANDLE_VALUE)
return (-1);
dwMode = PIPE_NOWAIT;
SetNamedPipeHandleState(fd, &dwMode, NULL, NULL);
sv[1] = (int)fd;
return (0);
}

View file

@ -127,9 +127,15 @@
/* Define to 1 if you have the `random' function. */
#undef HAVE_RANDOM
/* Define to 1 if you have the `recvmsg' function. */
#undef HAVE_RECVMSG
/* Define to 1 if you have the `sbrk' function. */
#undef HAVE_SBRK
/* Define to 1 if you have the `sendmsg' function. */
#undef HAVE_SENDMSG
/* Define to 1 if you have the `setsid' function. */
#undef HAVE_SETSID
@ -142,6 +148,9 @@
/* Define to 1 if you have the `snprintf' function. */
#undef HAVE_SNPRINTF
/* Define to 1 if you have the `socketpair' function. */
#undef HAVE_SOCKETPAIR
/* Using Solaris threads */
#undef HAVE_SOLARIS_THREADS
@ -214,6 +223,12 @@
/* Define to 1 if you have the <vfork.h> header file. */
#undef HAVE_VFORK_H
/* Define to 1 if you have the <windows.h> header file. */
#undef HAVE_WINDOWS_H
/* Using Windows threads */
#undef HAVE_WINDOWS_THREADS
/* Define to 1 if you have the <winsock2.h> header file. */
#undef HAVE_WINSOCK2_H
@ -223,6 +238,9 @@
/* Define to 1 if `vfork' works. */
#undef HAVE_WORKING_VFORK
/* Define to 1 if you have the `writev' function. */
#undef HAVE_WRITEV
/* Define to 1 if you have the <ws2tcpip.h> header file. */
#undef HAVE_WS2TCPIP_H
@ -307,11 +325,9 @@
/* in_port_t */
#undef in_port_t
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
/* Define as `__inline' if that's what the C compiler calls it, or to nothing
if it is not supported. */
#undef inline
#endif
/* Define to `short' if <sys/types.h> does not define. */
#undef int16_t
@ -328,7 +344,7 @@
/* Define to rpl_malloc if the replacement function should be used. */
#undef malloc
/* Define to `long int' if <sys/types.h> does not define. */
/* Define to `long' if <sys/types.h> does not define. */
#undef off_t
/* Define to `int' if <sys/types.h> does not define. */
@ -337,7 +353,7 @@
/* Define to 'int' if not defined */
#undef rlim_t
/* Define to `unsigned int' if <sys/types.h> does not define. */
/* Define to `unsigned' if <sys/types.h> does not define. */
#undef size_t
/* Define to 'int' if not defined */
@ -528,6 +544,9 @@ struct sockaddr_storage;
#ifndef HAVE_SRANDOM
#define srandom(x) srand(x) /* on win32, for tests only (bad random) */
#endif /* HAVE_SRANDOM */
#ifndef HAVE_SOCKETPAIR
int socketpair(int d, int type, int protocol, int *sv);
#endif
/* detect if we need to cast to unsigned int for FD_SET to avoid warnings */
#ifdef HAVE_WINSOCK2_H

11244
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -541,6 +541,7 @@ fi
# check solaris thread library
AC_ARG_WITH(solaris-threads, AC_HELP_STRING([--with-solaris-threads],
[use solaris native thread library.]), [ ],[ withval="no" ])
ub_have_sol_threads=no
if test x_$withval != x_no; then
if test x_$ub_have_pthreads != x_no; then
AC_WARN([Have pthreads already, ignoring --with-solaris-threads])
@ -551,12 +552,31 @@ if test x_$withval != x_no; then
CHECK_COMPILER_FLAG(mt, [CFLAGS="$CFLAGS -mt"],
[CFLAGS="$CFLAGS -D_REENTRANT"])
ub_have_sol_threads=yes
] , [
AC_ERROR([no solaris threads found.])
])
fi
fi
# check windows threads
if test x_$ub_have_pthreads = x_no -a x_$ub_have_sol_threads = x_no; then
AC_CHECK_HEADERS([windows.h],,, [AC_INCLUDES_DEFAULT])
AC_MSG_CHECKING([for CreateThread])
AC_TRY_COMPILE([
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#endif
], [
HANDLE t = CreateThread(NULL, 0, NULL, NULL, 0, NULL);
],
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_WINDOWS_THREADS, 1, [Using Windows threads])
,
AC_MSG_RESULT(no)
)
fi
# check to see if libraries are needed for these functions.
AC_SEARCH_LIBS([inet_pton], [nsl])
AC_SEARCH_LIBS([socket], [socket])
@ -724,7 +744,7 @@ AC_CHECK_GETADDRINFO_WITH_INCLUDES
if test $ac_cv_func_getaddrinfo = no; then
AC_LIBOBJ([fake-rfc2553])
fi
AC_CHECK_FUNCS([tzset sigprocmask fcntl getpwnam getrlimit setsid sbrk chroot kill sleep usleep random srandom])
AC_CHECK_FUNCS([tzset sigprocmask fcntl getpwnam getrlimit setsid sbrk chroot kill sleep usleep random srandom recvmsg sendmsg writev])
# check mkdir
AC_MSG_CHECKING([whether mkdir has one arg])
@ -766,6 +786,7 @@ AC_REPLACE_FUNCS(snprintf)
AC_REPLACE_FUNCS(strlcpy)
AC_REPLACE_FUNCS(memmove)
AC_REPLACE_FUNCS(gmtime_r)
AC_REPLACE_FUNCS(socketpair) dnl for mingw32
# check this after all other compilation checks, since the linking of the lib
# may break checks after this.
@ -966,6 +987,9 @@ struct sockaddr_storage;
#ifndef HAVE_SRANDOM
#define srandom(x) srand(x) /* on win32, for tests only (bad random) */
#endif /* HAVE_SRANDOM */
#ifndef HAVE_SOCKETPAIR
int socketpair(int d, int type, int protocol, int *sv);
#endif
/* detect if we need to cast to unsigned int for FD_SET to avoid warnings */
#ifdef HAVE_WINSOCK2_H

View file

@ -195,7 +195,45 @@ typedef thread_key_t ub_thread_key_t;
#define ub_thread_key_set(key, v) LOCKRET(thr_setspecific(key, v))
void* ub_thread_key_get(ub_thread_key_t key);
#else /* we do not HAVE_SOLARIS_THREADS and no PTHREADS */
/******************* WINDOWS THREADS ************************/
#ifdef HAVE_WINDOWS_THREADS
#include <windows.h>
/* use basic mutex */
typedef HANDLE lock_rw_t;
#define lock_rw_init(lock) windows_lock_init(lock)
#define lock_rw_destroy(lock) LOCKRET(rwlock_destroy(lock))
#define lock_rw_rdlock(lock) LOCKRET(rw_rdlock(lock))
#define lock_rw_wrlock(lock) LOCKRET(rw_wrlock(lock))
#define lock_rw_unlock(lock) LOCKRET(rw_unlock(lock))
/** use mutex */
typedef HANDLE lock_basic_t;
#define lock_basic_init(lock) LOCKRET(mutex_init(lock, USYNC_THREAD, NULL))
#define lock_basic_destroy(lock) LOCKRET(mutex_destroy(lock))
#define lock_basic_lock(lock) LOCKRET(mutex_lock(lock))
#define lock_basic_unlock(lock) LOCKRET(mutex_unlock(lock))
/** Use mutex. */
typedef HANDLE lock_quick_t;
#define lock_quick_init(lock) LOCKRET(mutex_init(lock, USYNC_THREAD, NULL))
#define lock_quick_destroy(lock) LOCKRET(mutex_destroy(lock))
#define lock_quick_lock(lock) LOCKRET(mutex_lock(lock))
#define lock_quick_unlock(lock) LOCKRET(mutex_unlock(lock))
/** Thread creation, create a default thread. */
typedef HANDLE ub_thread_t;
#define ub_thread_create(thr, func, arg) windows_thread_create(thr, func, arg);
#define ub_thread_self() windows_thread_self()
#define ub_thread_join(thread) windows_thread_join(thread)
typedef DWORD ub_thread_key_t;
#define ub_thread_key_create(key, f) windows_thread_key_create(key, f)
#define ub_thread_key_set(key, v) windows_thread_key_set(key, v)
void* ub_thread_key_get(ub_thread_key_t key);
#else /* we do not HAVE_SOLARIS_THREADS, PTHREADS or WINDOWS_THREADS */
/******************* NO THREADS ************************/
/** In case there is no thread support, define locks to do nothing */
@ -235,6 +273,7 @@ typedef void* ub_thread_key_t;
#define ub_thread_key_set(key, v) (key) = (v)
#define ub_thread_key_get(key) (key)
#endif /* HAVE_WINDOWS_THREADS */
#endif /* HAVE_SOLARIS_THREADS */
#endif /* HAVE_PTHREAD */
#endif /* USE_THREAD_DEBUG */

View file

@ -238,7 +238,7 @@ comm_point_send_udp_msg(struct comm_point *c, ldns_buffer* packet,
/** print debug ancillary info */
void p_ancil(const char* str, struct comm_reply* r)
{
#if defined(AF_INET6) && defined(IPV6_PKTINFO)
#if defined(AF_INET6) && defined(IPV6_PKTINFO) && (defined(HAVE_RECVMSG) || defined(HAVE_SENDMSG))
if(r->srctype != 4 && r->srctype != 6) {
log_info("%s: unknown srctype %d", str, r->srctype);
return;
@ -287,7 +287,7 @@ int
comm_point_send_udp_msg_if(struct comm_point *c, ldns_buffer* packet,
struct sockaddr* addr, socklen_t addrlen, struct comm_reply* r)
{
#if defined(AF_INET6) && defined(IPV6_PKTINFO)
#if defined(AF_INET6) && defined(IPV6_PKTINFO) && defined(HAVE_SENDMSG)
ssize_t sent;
struct msghdr msg;
struct iovec iov[1];
@ -372,7 +372,7 @@ comm_point_send_udp_msg_if(struct comm_point *c, ldns_buffer* packet,
void
comm_point_udp_ancil_callback(int fd, short event, void* arg)
{
#if defined(AF_INET6) && defined(IPV6_PKTINFO)
#if defined(AF_INET6) && defined(IPV6_PKTINFO) && defined(HAVE_RECVMSG)
struct comm_reply rep;
struct msghdr msg;
struct iovec iov[1];
@ -543,8 +543,12 @@ comm_point_tcp_accept_callback(int fd, short event, void* arg)
if(new_fd == -1) {
/* EINTR is signal interrupt. others are closed connection. */
if( errno != EINTR
#ifdef EWOULDBLOCK
&& errno != EWOULDBLOCK
#endif
#ifdef ECONNABORTED
&& errno != ECONNABORTED
#endif
#ifdef EPROTO
&& errno != EPROTO
#endif /* EPROTO */
@ -636,8 +640,10 @@ comm_point_tcp_handle_read(int fd, struct comm_point* c, int short_ok)
else if(r == -1) {
if(errno == EINTR || errno == EAGAIN)
return 1;
#ifdef ECONNRESET
if(errno == ECONNRESET && verbosity < 2)
return 0; /* silence reset by peer */
#endif
log_err("read (in tcp s): %s", strerror(errno));
log_addr(0, "remote address is", &c->repinfo.addr,
c->repinfo.addrlen);
@ -701,11 +707,14 @@ comm_point_tcp_handle_write(int fd, struct comm_point* c)
/* from Stevens, unix network programming, vol1, 3rd ed, p450*/
int error = 0;
socklen_t len = (socklen_t)sizeof(error);
if(getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0){
if(getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)&error,
&len) < 0){
error = errno; /* on solaris errno is error */
}
#if defined(EINPROGRESS) && defined(EWOULDBLOCK)
if(error == EINPROGRESS || error == EWOULDBLOCK)
return 1; /* try again later */
#endif
#ifdef ECONNREFUSED
else if(error == ECONNREFUSED && verbosity < 2)
return 0; /* silence 'connection refused' */
@ -724,6 +733,7 @@ comm_point_tcp_handle_write(int fd, struct comm_point* c)
if(c->tcp_byte_count < sizeof(uint16_t)) {
uint16_t len = htons(ldns_buffer_limit(c->buffer));
#ifdef HAVE_WRITEV
struct iovec iov[2];
iov[0].iov_base = (uint8_t*)&len + c->tcp_byte_count;
iov[0].iov_len = sizeof(uint16_t) - c->tcp_byte_count;
@ -732,6 +742,9 @@ comm_point_tcp_handle_write(int fd, struct comm_point* c)
log_assert(iov[0].iov_len > 0);
log_assert(iov[1].iov_len > 0);
r = writev(fd, iov, 2);
#else /* HAVE_WRITEV */
r = write(fd, &len, sizeof(uint16_t));
#endif /* HAVE_WRITEV */
if(r == -1) {
if(errno == EINTR || errno == EAGAIN)
return 1;