Numerous fixes related to compiling for mingw
authorBrian Aker <brian@tangent.org>
Sun, 28 Oct 2012 19:40:37 +0000 (15:40 -0400)
committerBrian Aker <brian@tangent.org>
Sun, 28 Oct 2012 19:40:37 +0000 (15:40 -0400)
18 files changed:
configure.ac
libhashkit/common.h
libmemcached-1.0/platform.h
libmemcached/behavior.cc
libmemcached/common.h
libmemcached/connect.cc
libmemcached/csl/server.h
libmemcached/do.cc
libmemcached/error.cc
libmemcached/instance.h
libmemcached/io.cc
libmemcached/socket.hpp
libtest/test.hpp
libtest/timer.hpp
libtest/wait.cc
m4/ax_libmemcached.m4
poll/poll.c
win32/wrappers.h

index 9e3f72aca16ec414d409aa08d761ee0fa5181ad7..90d5abdef426bf92f517149251aa36cb00900e3b 100644 (file)
@@ -144,6 +144,7 @@ AC_CHECK_HEADERS([ws2tcpip.h])
 
 AC_CHECK_FUNCS([alarm])
 AC_CHECK_FUNCS([dup2])
+AC_CHECK_FUNCS([fcntl])
 AC_CHECK_FUNCS([getline])
 AC_CHECK_FUNCS([gettimeofday])
 AC_CHECK_FUNCS([memchr])
index e1343971942fbca6eb6d6b5e077aa356679f664a..144235972b7a2f40be0c079ed280e67ec2c038e3 100644 (file)
 #include <stdlib.h>
 #include <math.h>
 
+#ifndef __WORDSIZE
+# ifdef __MINGW32__
+#  define __WORDSIZE 32
+# endif
+#endif
+
 #include <libhashkit-1.0/hashkit.h>
 #include <libhashkit/is.h>
 #include <libhashkit/string.h>
index 6f43ca2cee560dbfe8b167e9e012d1820bc9e1ac..01ce276c876634daaf7ae015de5c7404c5e48eaf 100644 (file)
 #pragma once
 
 
-#ifdef WIN32
+#if defined(WIN32) || defined(__MINGW32__)
+# include <winsock2.h>
+# include <ws2tcpip.h>
 
-#include <winsock2.h>
-#include <ws2tcpip.h>
 typedef short in_port_t;
 typedef SOCKET memcached_socket_t;
-#else
-typedef int memcached_socket_t;
-
-#include <sys/socket.h>
-
-#include <netinet/in.h>
 
-#include <arpa/inet.h>
-
-#include <netdb.h>
-
-#include <sys/un.h>
+#else
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+# include <netdb.h>
+# include <sys/un.h>
+# include <netinet/tcp.h>
 
-#include <netinet/tcp.h>
+typedef int memcached_socket_t;
 
 #endif /* WIN32 */
index c381a513cfbceab5322de4507da5b29698e0403b..d9a7cf6007f614f14a6dd0fa56acee9b37b8b6c2 100644 (file)
@@ -427,7 +427,7 @@ uint64_t memcached_behavior_get(memcached_st *ptr,
           return 0;
         }
 
-        if (getsockopt(instance->fd, SOL_SOCKET, SO_SNDBUF, &sock_size, &sock_length) < 0)
+        if (getsockopt(instance->fd, SOL_SOCKET, SO_SNDBUF, (char*)&sock_size, &sock_length) < 0)
         {
           memcached_set_errno(*ptr, get_socket_errno(), MEMCACHED_AT);
           return 0; /* Zero means error */
@@ -463,7 +463,7 @@ uint64_t memcached_behavior_get(memcached_st *ptr,
           return 0;
         }
 
-        if (getsockopt(instance->fd, SOL_SOCKET, SO_RCVBUF, &sock_size, &sock_length) < 0)
+        if (getsockopt(instance->fd, SOL_SOCKET, SO_RCVBUF, (char*)&sock_size, &sock_length) < 0)
         {
           memcached_set_errno(*ptr, get_socket_errno(), MEMCACHED_AT);
           return 0; /* Zero means error */
index 5a76faf6da938346e2330f860df5b52b6878ce0e..810886326d1c3842c4d4a85c8ff50bbf4042e6cc 100644 (file)
 # include "poll/poll.h"
 #endif
 
+#ifndef POLLHUP
+# define POLLHUP               0x0010
+#endif
+
+#ifndef POLLNVAL
+# define POLLNVAL      0x0020
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
index 4e7e24bf48c47e9f1d5c4fcdadbf9611c7810742..da6cf80229a38863727dff15539b0c010fcd2122 100644 (file)
@@ -93,7 +93,7 @@ static memcached_return_t connect_poll(org::libmemcached::Instance* server)
           {
             int err;
             socklen_t len= sizeof(err);
-            if (getsockopt(server->fd, SOL_SOCKET, SO_ERROR, &err, &len) == 0)
+            if (getsockopt(server->fd, SOL_SOCKET, SO_ERROR, (char*)&err, &len) == 0)
             {
               if (err == 0)
               {
@@ -124,7 +124,7 @@ static memcached_return_t connect_poll(org::libmemcached::Instance* server)
     {
       int err;
       socklen_t len= sizeof (err);
-      if (getsockopt(fds[0].fd, SOL_SOCKET, SO_ERROR, &err, &len) == 0)
+      if (getsockopt(fds[0].fd, SOL_SOCKET, SO_ERROR, (char*)&err, &len) == 0)
       {
         // We check the value to see what happened wth the socket.
         if (err == 0)
@@ -298,7 +298,7 @@ static void set_socket_options(org::libmemcached::Instance* server)
     waittime.tv_usec= server->root->snd_timeout % 1000000;
 
     int error= setsockopt(server->fd, SOL_SOCKET, SO_SNDTIMEO,
-                          &waittime, (socklen_t)sizeof(struct timeval));
+                          (char*)&waittime, (socklen_t)sizeof(struct timeval));
     (void)error;
     assert(error == 0);
   }
@@ -313,7 +313,7 @@ static void set_socket_options(org::libmemcached::Instance* server)
     waittime.tv_usec= server->root->rcv_timeout % 1000000;
 
     int error= setsockopt(server->fd, SOL_SOCKET, SO_RCVTIMEO,
-                          &waittime, (socklen_t)sizeof(struct timeval));
+                          (char*)&waittime, (socklen_t)sizeof(struct timeval));
     (void)(error);
     assert(error == 0);
   }
@@ -344,7 +344,7 @@ static void set_socket_options(org::libmemcached::Instance* server)
     linger.l_onoff= 1;
     linger.l_linger= 0; /* By default on close() just drop the socket */
     int error= setsockopt(server->fd, SOL_SOCKET, SO_LINGER,
-                          &linger, (socklen_t)sizeof(struct linger));
+                          (char*)&linger, (socklen_t)sizeof(struct linger));
     (void)(error);
     assert(error == 0);
   }
@@ -354,7 +354,7 @@ static void set_socket_options(org::libmemcached::Instance* server)
     int flag= 1;
 
     int error= setsockopt(server->fd, IPPROTO_TCP, TCP_NODELAY,
-                          &flag, (socklen_t)sizeof(int));
+                          (char*)&flag, (socklen_t)sizeof(int));
     (void)(error);
     assert(error == 0);
   }
@@ -364,7 +364,7 @@ static void set_socket_options(org::libmemcached::Instance* server)
     int flag= 1;
 
     int error= setsockopt(server->fd, SOL_SOCKET, SO_KEEPALIVE,
-                      &flag, (socklen_t)sizeof(int));
+                          (char*)&flag, (socklen_t)sizeof(int));
     (void)(error);
     assert(error == 0);
   }
@@ -373,7 +373,7 @@ static void set_socket_options(org::libmemcached::Instance* server)
   if (server->root->tcp_keepidle > 0)
   {
     int error= setsockopt(server->fd, IPPROTO_TCP, TCP_KEEPIDLE,
-                          &server->root->tcp_keepidle, (socklen_t)sizeof(int));
+                          (char*)&server->root->tcp_keepidle, (socklen_t)sizeof(int));
     (void)(error);
     assert(error == 0);
   }
@@ -382,7 +382,7 @@ static void set_socket_options(org::libmemcached::Instance* server)
   if (server->root->send_size > 0)
   {
     int error= setsockopt(server->fd, SOL_SOCKET, SO_SNDBUF,
-                          &server->root->send_size, (socklen_t)sizeof(int));
+                          (char*)&server->root->send_size, (socklen_t)sizeof(int));
     (void)(error);
     assert(error == 0);
   }
@@ -390,7 +390,7 @@ static void set_socket_options(org::libmemcached::Instance* server)
   if (server->root->recv_size > 0)
   {
     int error= setsockopt(server->fd, SOL_SOCKET, SO_RCVBUF,
-                          &server->root->recv_size, (socklen_t)sizeof(int));
+                          (char*)&server->root->recv_size, (socklen_t)sizeof(int));
     (void)(error);
     assert(error == 0);
   }
@@ -510,13 +510,16 @@ static memcached_return_t network_connect(org::libmemcached::Instance* server)
       type|= SOCK_NONBLOCK;
     }
 
-    if ((server->fd= socket(server->address_info_next->ai_family,
-                            type,
-                            server->address_info_next->ai_protocol)) < 0)
+    server->fd= socket(server->address_info_next->ai_family,
+                       type,
+                       server->address_info_next->ai_protocol);
+
+    if (int(server->fd) == SOCKET_ERROR)
     {
       return memcached_set_errno(*server, get_socket_errno(), NULL);
     }
 
+#ifdef HAVE_FCNTL
     // If SOCK_CLOEXEC exists then we don't need to call the following
     if (SOCK_CLOEXEC == 0)
     {
@@ -529,6 +532,7 @@ static memcached_return_t network_connect(org::libmemcached::Instance* server)
         } while (rval == -1 && (errno == EINTR or errno == EAGAIN));
       }
     }
+#endif
 
     set_socket_options(server);
 
index fe97eb916a748d84886912804f6cd359fea61aed..21915d64624b64db6b3b114f2bc616a879f0a34a 100644 (file)
 #pragma once
 
 #include <cstdlib>
-#include <arpa/inet.h>
+
+#ifdef HAVE_ARPA_INET_H
+# include <arpa/inet.h>
+#endif
 
 struct server_t
 {
index db533680f77193f80ea3dd6ce37eb65bcb1f3639..ffb9a48b54d792f0a8daff1d80e3fff4dc60700a 100644 (file)
@@ -34,6 +34,7 @@ memcached_return_t memcached_vdo(org::libmemcached::Instance* instance,
   **/
   if (memcached_is_udp(instance->root))
   {
+#ifndef __MINGW32__
     if (vector[0].buffer or vector[0].length)
     {
       return memcached_set_error(*instance->root, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT, 
@@ -74,6 +75,9 @@ memcached_return_t memcached_vdo(org::libmemcached::Instance* instance,
     }
 
     return MEMCACHED_SUCCESS;
+#else
+    return MEMCACHED_FAILURE;
+#endif
   }
 
   bool sent_success= memcached_io_writev(instance, vector, count, with_flush);
index d15f9843d295cbec9afe9e951f9309cd1a142f60..f963e12446d42e2570733eea36aaae4187f1adbb 100644 (file)
@@ -141,9 +141,12 @@ static void _set(memcached_st& memc, memcached_string_t *str, memcached_return_t
   {
 #ifdef STRERROR_R_CHAR_P
     errmsg_ptr= strerror_r(local_errno, errmsg, sizeof(errmsg));
-#else
+#elif defined(HAVE_STRERROR_R) && HAVE_STRERROR_R
     strerror_r(local_errno, errmsg, sizeof(errmsg));
     errmsg_ptr= errmsg;
+#elif defined(HAVE_STRERROR) && HAVE_STRERROR
+    snprintf(errmsg, sizeof(errmsg), "%s", strerror(local_errno));
+    errmsg_ptr= errmsg;
 #endif
   }
 
index dc9e45ede805939f62cac8fbb352259c96e1d1f3..e564afaaa3871cf0d9b44c676380c1ef6c354bee 100644 (file)
 #pragma once
 
 #ifndef WIN32
-#include <netdb.h>
+# ifdef HAVE_NETDB_H
+#  include <netdb.h>
+# endif
 #endif
 
 #ifdef NI_MAXHOST
-#define MEMCACHED_NI_MAXHOST NI_MAXHOST
+# define MEMCACHED_NI_MAXHOST NI_MAXHOST
 #else
-#define MEMCACHED_NI_MAXHOST 1025
+# define MEMCACHED_NI_MAXHOST 1025
 #endif
 
 #ifdef NI_MAXSERV
-#define MEMCACHED_NI_MAXSERV NI_MAXSERV
+# define MEMCACHED_NI_MAXSERV NI_MAXSERV
 #else
-#define MEMCACHED_NI_MAXSERV 32
+# define MEMCACHED_NI_MAXSERV 32
 #endif
 
 #ifdef __cplusplus
index 019eafb6e5c9104771f95885d89786d65fda1e2c..886476f6b353301f88f76725357486e38434a431 100644 (file)
@@ -240,7 +240,7 @@ static memcached_return_t io_wait(org::libmemcached::Instance* ptr,
         int local_errno= EINVAL;
         int err;
         socklen_t len= sizeof (err);
-        if (getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &err, &len) == 0)
+        if (getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, (char*)&err, &len) == 0)
         {
           if (err == 0) // treat this as EINTR
           {
index fb589931eff09c5071f1313b08e288448b92ef02..30e296ff61b4d8129dc9372f4a8a02c6e2122dca 100644 (file)
  * a lot easier to map back to the unix way with macros than going the other
  * way without side effect ;-)
  */
-#ifdef WIN32
-#include "win32/wrappers.h"
-#define get_socket_errno() WSAGetLastError()
+#if defined(WIN32) || defined(__MINGW32__)
+# include "win32/wrappers.h"
+# define get_socket_errno() WSAGetLastError()
 #else
-#include <unistd.h>
-#define INVALID_SOCKET -1
-#define SOCKET_ERROR -1
-#define closesocket(a) close(a)
-#define get_socket_errno() errno
+# include <unistd.h>
+# define INVALID_SOCKET -1
+# define SOCKET_ERROR -1
+# define closesocket(a) close(a)
+# define get_socket_errno() errno
 #endif
 
 #ifdef __cplusplus
@@ -66,15 +66,15 @@ static inline void memcached_close_socket(int& socket_fd)
 #endif
 
 #ifndef HAVE_MSG_NOSIGNAL
-#define MSG_NOSIGNAL 0
+# define MSG_NOSIGNAL 0
 #endif
 
 #ifndef HAVE_MSG_DONTWAIT
-#define MSG_DONTWAIT 0
+# define MSG_DONTWAIT 0
 #endif
 
 #ifndef HAVE_MSG_MORE
-#define MSG_MORE 0
+# define MSG_MORE 0
 #endif
 
 
index 576f3014990deedfd78ab27308f3d51f91d3dff7..864552fbb00904bd9a7d53dd937d8dbfdb8ffcb7 100644 (file)
 #include <cstdio>
 #include <cstdlib>
 
+#if defined(WIN32) || defined(__MINGW32__)
+# include <winsock2.h>
+# include <ws2tcpip.h>
+
+typedef short in_port_t;
+
+#endif
+
 #ifdef HAVE_ARPA_INET_H
 # include <arpa/inet.h>
 #endif
index 28ec47416766c3eb917447d527a57ef1e0e47e97..73de26c6ac2361168cdf7974180cd32d4fa3c5e1 100644 (file)
@@ -114,7 +114,9 @@ public:
 private:
   void _time(struct timespec& ts)
   {
-#ifdef __MACH__ // OSX lacks clock_gettime()
+#if defined(HAVE_CLOCK_GETTIME) && HAVE_CLOCK_GETTIME
+    clock_gettime(CLOCK_REALTIME, &ts);
+#elif defined(__MACH__) && __MACH__ // OSX lacks clock_gettime()
     clock_serv_t _clock_serv;
     mach_timespec_t _mach_timespec;
     host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &_clock_serv);
@@ -123,7 +125,6 @@ private:
     ts.tv_sec= _mach_timespec.tv_sec;
     ts.tv_nsec= _mach_timespec.tv_nsec;
 #else
-    clock_gettime(CLOCK_REALTIME, &ts);
 #endif
   }
 
index f934f5b388860f2f583c0d14e31e40385c3d9778..a0d60d1f29c64f7040f66cd09c954bce26bf1bbe 100644 (file)
@@ -34,7 +34,7 @@
  *
  */
 
-#include <config.h>
+#include "config.h"
 
 #include <cstdlib>
 #include <fcntl.h>
index ea385d0f82b2073ec6cd804591ef487c67fdbfa4..95e5c9f7fbbd282b7a6152b8058e77107592c6dc 100644 (file)
@@ -4,7 +4,7 @@
 #
 # SYNOPSIS
 #
-#   AX_LIBMEMCACHED, AX_LIBMEMCACHED_UTIL, AX_WITH_LIBMEMCACHED
+#   AX_LIBMEMCACHED, AX_LIBMEMCACHED_UTIL, AX_ENABLE_LIBMEMCACHED
 #
 # DESCRIPTION
 #
@@ -73,10 +73,6 @@ AC_DEFUN([AX_LIBMEMCACHED], [
 
   AS_IF([test "x$ax_cv_libmemcached" = "xyes"], [
       AC_DEFINE([HAVE_LIBMEMCACHED_MEMCACHED_H], [1], [Have libmemcached-1.0/memcached.h])
-      LIBMEMCACHED_CFLAGS=
-      AC_SUBST([LIBMEMCACHED_CFLAGS])
-      LIBMEMCACHED_LDFLAGS="-lmemcached"
-      AC_SUBST([LIBMEMCACHED_LDFLAGS], [-lmemcached])
       ],[
       AC_DEFINE([HAVE_LIBMEMCACHED_MEMCACHED_H], [0], [Have libmemcached-1.0/memcached.h])
       ])
@@ -106,34 +102,37 @@ AC_DEFUN([AX_LIBMEMCACHED], [
 
       AS_IF([test "x$ax_cv_libmemcached_util" = "xyes"], [
         AC_DEFINE([HAVE_LIBMEMCACHED_UTIL_H], [1], [Have libmemcachedutil-1.0/util.h])
-        LIBMEMCACHED_UTIL_LDFLAGS="-lmemcached -lmemcachedutil"
-        AC_SUBST([LIBMEMCACHED_UTIL_LDFLAGS])
         ],[
         AC_DEFINE([HAVE_LIBMEMCACHED_UTIL_H], [0], [Have libmemcachedutil-1.0/util.h])
         ])
       ])
 
-  AC_DEFUN([_WITH_LIBMEMCACHED], [
-      AC_REQUIRE([AX_LIBMEMCACHED_UTIL])
-      AC_ARG_ENABLE([libmemcached],
-        [AS_HELP_STRING([--disable-libmemcached],
-          [Build with libmemcached support @<:@default=on@:>@])],
-        [ac_enable_libmemcached="$enableval"],
-        [ac_enable_libmemcached="yes"])
+AC_DEFUN([_ENABLE_LIBMEMCACHED], [
+         AC_REQUIRE([AX_LIBMEMCACHED_UTIL])
+         AC_ARG_ENABLE([libmemcached],
+                       [AS_HELP_STRING([--disable-libmemcached],
+                                       [Build with libmemcached support @<:@default=on@:>@])],
+                       [ax_enable_libmemcached="$enableval"],
+                       [ax_enable_libmemcached="yes"])
 
-      ac_with_libmemcached="no"
-      AS_IF([test "x$ac_enable_libmemcached" = "xyes"], [
-        AS_IF([test "x$ax_cv_libmemcached" = "xyes"], [
-          ac_with_libmemcached="yes"
-          ])
-        ])
+         AS_IF([test "x$ax_cv_libmemcached" != "xyes"], [
+               ax_enable_libmemcached="not found"
+               ])
 
-      AS_IF([test "x$ac_with_libmemcached" = "xyes"], [
-        AC_DEFINE([HAVE_LIBMEMCACHED], [1], [Enable libmemcached support])
-        ],[
-        AC_DEFINE([HAVE_LIBMEMCACHED], [0], [Enable libmemcached support])
-        ])
-      AM_CONDITIONAL(HAVE_LIBMEMCACHED, test "x${ac_with_libmemcached}" = "xyes")
-      ])
+         AS_IF([test "x$ax_enable_libmemcached" = "xyes"], [
+               AC_DEFINE([HAVE_LIBMEMCACHED], [1], [Enable libmemcached support])
+               LIBMEMCACHED_CFLAGS=
+               AC_SUBST([LIBMEMCACHED_CFLAGS])
+               LIBMEMCACHED_LDFLAGS="-lmemcached"
+               AC_SUBST([LIBMEMCACHED_LDFLAGS])
+               AS_IF([test "x$ax_cv_libmemcached_util" = "xyes"], [
+                     LIBMEMCACHED_UTIL_LDFLAGS="-lmemcached -lmemcachedutil"
+                     AC_SUBST([LIBMEMCACHED_UTIL_LDFLAGS])
+                     ])
+               ],[
+               AC_DEFINE([HAVE_LIBMEMCACHED], [0], [Enable libmemcached support])
+               ])
+         AM_CONDITIONAL(HAVE_LIBMEMCACHED, test "x${ax_enable_libmemcached}" = "xyes")
+         ])
 
-AC_DEFUN([AX_WITH_LIBMEMCACHED], [ AC_REQUIRE([_WITH_LIBMEMCACHED]) ])
+AC_DEFUN([AX_ENABLE_LIBMEMCACHED], [ AC_REQUIRE([_ENABLE_LIBMEMCACHED]) ])
index c5aa1115918a999bb2cd0810450bf2a5d2917bbf..d7a7d9c7d73710cb7580e40a8f4c2bf1d792e1d2 100644 (file)
@@ -9,9 +9,17 @@
  *
  */
 #include "config.h"
+
+#if defined(WIN32) || defined(__MINGW32__)
+# include <winsock2.h>
+# include <ws2tcpip.h>
+#endif
+
 #include <sys/time.h>
 #include <strings.h>
 
+#include "poll/poll.h"
+
 int poll(struct pollfd fds[], nfds_t nfds, int tmo)
 {
   fd_set readfds, writefds, errorfds;
index 80b44651c4b29aa8162f8d48a3f982a442077c41..976303cb32ef00b85f3c37bf2accf405f097cab5 100644 (file)
  * WinSock use a separate range for error codes. Let's just map to the
  * WinSock ones.
  */
-#define EADDRINUSE WSAEADDRINUSE
-#define EWOULDBLOCK WSAEWOULDBLOCK
-#define EINPROGRESS WSAEINPROGRESS
-#define EALREADY WSAEALREADY
-#define EISCONN WSAEISCONN
-#define ENOTCONN WSAENOTCONN
-#define ENOBUFS WSAENOBUFS
-#define SHUT_RDWR SD_BOTH
+#ifndef EADDRINUSE
+# define EADDRINUSE WSAEADDRINUSE
+#endif
+
+#ifndef EWOULDBLOCK
+# define EWOULDBLOCK WSAEWOULDBLOCK
+#endif
+
+#ifndef EINPROGRESS
+# define EINPROGRESS WSAEINPROGRESS
+#endif
+
+#ifndef EALREADY
+# define EALREADY WSAEALREADY
+#endif
+
+#ifndef EISCONN
+# define EISCONN WSAEISCONN
+#endif
+
+#ifndef ENOTCONN
+# define ENOTCONN WSAENOTCONN
+#endif
+
+#ifndef ENOBUFS
+# define ENOBUFS WSAENOBUFS
+#endif
+
+#ifndef SHUT_RDWR
+# define SHUT_RDWR SD_BOTH
+#endif
 
 /* EAI_SYSTEM isn't defined anywhere... just set it to... 11? */
-#define EAI_SYSTEM 11
+#ifndef EAI_SYSTEM
+# define EAI_SYSTEM 11
+#endif
 
 /* Best effort mapping of functions to alternative functions */
 #define index(a,b) strchr(a,b)