From 65cafbe1095ade9d5632188a058f321372a77d55 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 13 Nov 2008 18:56:56 +0000 Subject: Refactor configure script detection of functions used to set sockets into non-blocking mode, and decouple function detection from function capability. --- ares_process.c | 53 ++++++++++++++++++----------------------------------- 1 file changed, 18 insertions(+), 35 deletions(-) (limited to 'ares_process.c') diff --git a/ares_process.c b/ares_process.c index b7f375e..05341aa 100644 --- a/ares_process.c +++ b/ares_process.c @@ -805,68 +805,51 @@ void ares__send_query(ares_channel channel, struct query *query, static int setsocknonblock(ares_socket_t sockfd, /* operate on this */ int nonblock /* TRUE or FALSE */) { -#undef SETBLOCK -#define SETBLOCK 0 -#ifdef HAVE_O_NONBLOCK +#if defined(USE_BLOCKING_SOCKETS) + + return 0; /* returns success */ + +#elif defined(HAVE_FCNTL_O_NONBLOCK) + /* most recent unix versions */ int flags; - flags = fcntl(sockfd, F_GETFL, 0); if (FALSE != nonblock) return fcntl(sockfd, F_SETFL, flags | O_NONBLOCK); else return fcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK)); -#undef SETBLOCK -#define SETBLOCK 1 -#endif -#if defined(HAVE_FIONBIO) && (SETBLOCK == 0) +#elif defined(HAVE_IOCTL_FIONBIO) + /* older unix versions */ int flags; - flags = nonblock; return ioctl(sockfd, FIONBIO, &flags); -#undef SETBLOCK -#define SETBLOCK 2 -#endif -#if defined(HAVE_IOCTLSOCKET) && (SETBLOCK == 0) +#elif defined(HAVE_IOCTLSOCKET_FIONBIO) + #ifdef WATT32 char flags; #else - /* Windows? */ + /* Windows */ unsigned long flags; #endif flags = nonblock; - return ioctlsocket(sockfd, FIONBIO, &flags); -#undef SETBLOCK -#define SETBLOCK 3 -#endif -#if defined(HAVE_IOCTLSOCKET_CASE) && (SETBLOCK == 0) - /* presumably for Amiga */ +#elif defined(HAVE_IOCTLSOCKET_CAMEL_FIONBIO) + + /* Amiga */ return IoctlSocket(sockfd, FIONBIO, (long)nonblock); -#undef SETBLOCK -#define SETBLOCK 4 -#endif -#if defined(HAVE_SO_NONBLOCK) && (SETBLOCK == 0) +#elif defined(HAVE_SETSOCKOPT_SO_NONBLOCK) + /* BeOS */ long b = nonblock ? 1 : 0; return setsockopt(sockfd, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b)); -#undef SETBLOCK -#define SETBLOCK 5 -#endif -#ifdef HAVE_DISABLED_NONBLOCKING - return 0; /* returns success */ -#undef SETBLOCK -#define SETBLOCK 6 -#endif - -#if (SETBLOCK == 0) -#error "no non-blocking method was found/used/set" +#else +# error "no non-blocking method was found/used/set" #endif } -- cgit v1.2.3