AC_CHECK_FUNCS([alarm])
AC_CHECK_FUNCS([dup2])
+AC_CHECK_FUNCS([fcntl])
AC_CHECK_FUNCS([getline])
AC_CHECK_FUNCS([gettimeofday])
AC_CHECK_FUNCS([memchr])
#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>
#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 */
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 */
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 */
# include "poll/poll.h"
#endif
+#ifndef POLLHUP
+# define POLLHUP 0x0010
+#endif
+
+#ifndef POLLNVAL
+# define POLLNVAL 0x0020
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
{
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)
{
{
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)
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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)
{
} while (rval == -1 && (errno == EINTR or errno == EAGAIN));
}
}
+#endif
set_socket_options(server);
#pragma once
#include <cstdlib>
-#include <arpa/inet.h>
+
+#ifdef HAVE_ARPA_INET_H
+# include <arpa/inet.h>
+#endif
struct server_t
{
**/
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,
}
return MEMCACHED_SUCCESS;
+#else
+ return MEMCACHED_FAILURE;
+#endif
}
bool sent_success= memcached_io_writev(instance, vector, count, with_flush);
{
#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
}
#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
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
{
* 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
#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
#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
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);
ts.tv_sec= _mach_timespec.tv_sec;
ts.tv_nsec= _mach_timespec.tv_nsec;
#else
- clock_gettime(CLOCK_REALTIME, &ts);
#endif
}
*
*/
-#include <config.h>
+#include "config.h"
#include <cstdlib>
#include <fcntl.h>
#
# SYNOPSIS
#
-# AX_LIBMEMCACHED, AX_LIBMEMCACHED_UTIL, AX_WITH_LIBMEMCACHED
+# AX_LIBMEMCACHED, AX_LIBMEMCACHED_UTIL, AX_ENABLE_LIBMEMCACHED
#
# DESCRIPTION
#
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])
])
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]) ])
*
*/
#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;
* 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)