AC_CHECK_HEADERS_ONCE([errno.h])
AC_CHECK_HEADERS_ONCE([execinfo.h])
AC_CHECK_HEADERS_ONCE([fcntl.h])
+AC_CHECK_HEADERS_ONCE([features.h])
AC_CHECK_HEADERS_ONCE([fnmatch.h])
AC_CHECK_HEADERS_ONCE([inttypes.h])
AC_CHECK_HEADERS_ONCE([libintl.h])
AC_CHECK_HEADERS_ONCE([sys/socket.h])
AC_CHECK_HEADERS_ONCE([sys/sysctl.h])
AC_CHECK_HEADERS_ONCE([sys/time.h])
+AC_CHECK_HEADERS_ONCE([sys/types.h])
AC_CHECK_HEADERS_ONCE([sys/un.h])
AC_CHECK_HEADERS_ONCE([sys/wait.h])
AC_CHECK_HEADERS_ONCE([syslog.h])
AX_COMPILER_VENDOR
-AC_CHECK_TYPES([in_port_t])
+AC_CHECK_TYPES([in_port_t],,,[[
+ #ifdef HAVE_SYS_TYPES_H
+ # include <sys/types.h>
+ #endif
+ #ifdef HAVE_NETINET_IN_H
+ # include <netinet/in.h>
+ #endif
+ #ifdef HAVE_NETDB_H
+ # include <netdb.h>
+ #endif]])
AC_CHECK_TYPES([ptrdiff_t])
AC_HEADER_STDBOOL
AC_TYPE_INT16_T
*
* libmcachedd client library.
*
- * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2011-2013 Data Differential, http://datadifferential.com/
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
/* Little endian, flip the bytes around until someone makes a faster/better
* way to do this. */
uint64_t rv= 0;
- for (uint8_t x= 0; x < 8; x++)
+ for (uint8_t x= 0; x < 8; ++x)
{
rv= (rv << 8) | (in & 0xff);
in >>= 8;
#endif
#include <libmemcached-1.0/memcached.h>
-#include <libmemcached/watchpoint.h>
-#include <libmemcached/is.h>
+#include "libmemcached/watchpoint.h"
+#include "libmemcached/is.h"
typedef struct memcached_st Memcached;
-#ifdef __cplusplus
-# include "libmemcached/instance.hpp"
-#endif
-#include <libmemcached/server_instance.h>
-
#ifdef HAVE_POLL_H
# include <poll.h>
#else
#endif
#ifdef __cplusplus
-extern "C" {
+org::libmemcached::Instance* memcached_instance_fetch(memcached_st *ptr, uint32_t server_key);
#endif
-typedef memcached_return_t (*memcached_server_execute_fn)(memcached_st *ptr, memcached_server_write_instance_st server, void *context);
-
+/* These are private not to be installed headers */
+#include "libmemcached/error.hpp"
+#include "libmemcached/memory.h"
+#include "libmemcached/io.h"
#ifdef __cplusplus
-} // extern "C"
+# include "libmemcached/string.hpp"
+# include "libmemcached/memcached/protocol_binary.h"
+# include "libmemcached/io.hpp"
+# include "libmemcached/udp.hpp"
+# include "libmemcached/do.hpp"
+# include "libmemcached/socket.hpp"
+# include "libmemcached/connect.hpp"
+# include "libmemcached/allocators.hpp"
+# include "libmemcached/hash.hpp"
+# include "libmemcached/quit.hpp"
+# include "libmemcached/instance.hpp"
+# include "libmemcached/server_instance.h"
+# include "libmemcached/server.hpp"
+# include "libmemcached/flag.hpp"
+# include "libmemcached/behavior.hpp"
+# include "libmemcached/sasl.hpp"
+# include "libmemcached/server_list.hpp"
#endif
+#include "libmemcached/internal.h"
+#include "libmemcached/array.h"
+#include "libmemcached/libmemcached_probes.h"
+#include "libmemcached/byteorder.h"
+#include "libmemcached/initialize_query.h"
#ifdef __cplusplus
-org::libmemcached::Instance* memcached_instance_fetch(memcached_st *ptr, uint32_t server_key);
+# include "libmemcached/response.h"
#endif
-memcached_return_t memcached_server_execute(memcached_st *ptr,
- memcached_server_execute_fn callback,
- void *context);
-/* These are private not to be installed headers */
-#include <libmemcached/error.hpp>
-#include <libmemcached/memory.h>
-#include <libmemcached/io.h>
-#ifdef __cplusplus
-#include <libmemcached/string.hpp>
-#include <libmemcached/memcached/protocol_binary.h>
-#include <libmemcached/io.hpp>
-#include <libmemcached/udp.hpp>
-#include <libmemcached/do.hpp>
-#include <libmemcached/socket.hpp>
-#include <libmemcached/connect.hpp>
-#include <libmemcached/allocators.hpp>
-#include <libmemcached/hash.hpp>
-#include <libmemcached/quit.hpp>
-#include <libmemcached/instance.hpp>
-#include <libmemcached/server.hpp>
-#include <libmemcached/flag.hpp>
-#include <libmemcached/behavior.hpp>
-#include <libmemcached/sasl.hpp>
-#include <libmemcached/server_list.hpp>
-#endif
-#include <libmemcached/internal.h>
-#include <libmemcached/array.h>
-#include <libmemcached/libmemcached_probes.h>
-#include <libmemcached/byteorder.h>
-#include <libmemcached/initialize_query.h>
-#ifdef __cplusplus
-#include <libmemcached/response.h>
-#endif
-#include <libmemcached/namespace.h>
-#include <libmemcached/virtual_bucket.h>
+#include "libmemcached/namespace.h"
+#include "libmemcached/virtual_bucket.h"
#ifdef __cplusplus
-#include <libmemcached/backtrace.hpp>
-#include <libmemcached/assert.hpp>
-#include <libmemcached/server.hpp>
-#include <libmemcached/key.hpp>
-#include <libmemcached/encoding_key.h>
-#include <libmemcached/result.h>
-#include <libmemcached/version.hpp>
+# include "libmemcached/backtrace.hpp"
+# include "libmemcached/assert.hpp"
+# include "libmemcached/server.hpp"
+# include "libmemcached/key.hpp"
+# include "libmemcached/encoding_key.h"
+# include "libmemcached/result.h"
+# include "libmemcached/version.hpp"
#endif
-#include <libmemcached/continuum.hpp>
+#include "libmemcached/continuum.hpp"
#if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
}
assert_msg(server->fd != INVALID_SOCKET, "poll() was passed an invalid file descriptor");
- (void)closesocket(server->fd);
- server->fd= INVALID_SOCKET;
+ server->reset_socket();
server->state= MEMCACHED_SERVER_STATE_NEW;
return memcached_set_errno(*server, local_errno, MEMCACHED_AT);
type|= SOCK_NONBLOCK;
}
- if ((server->fd= socket(AF_UNIX, type, 0)) < 0)
+ if ((server->fd= socket(AF_UNIX, type, 0)) == -1)
{
return memcached_set_errno(*server, errno, NULL);
}
servAddr.sun_family= AF_UNIX;
strncpy(servAddr.sun_path, server->hostname, sizeof(servAddr.sun_path)); /* Copy filename */
- if (connect(server->fd, (struct sockaddr *)&servAddr, sizeof(servAddr)) < 0)
+ if (connect(server->fd, (struct sockaddr *)&servAddr, sizeof(servAddr)) == -1)
{
switch (errno)
{
break;
case EINTR:
- (void)closesocket(server->fd);
- server->fd= INVALID_SOCKET;
+ server->reset_socket();
continue;
case EISCONN: /* We were spinning waiting on connect */
{
assert(0); // Programmer error
- (void)closesocket(server->fd);
- server->fd= INVALID_SOCKET;
+ server->reset_socket();
continue;
}
default:
WATCHPOINT_ERRNO(errno);
- (void)closesocket(server->fd);
- server->fd= INVALID_SOCKET;
+ server->reset_socket();
return memcached_set_errno(*server, errno, MEMCACHED_AT);
}
}
if (set_socket_options(server) == false)
{
- (void)closesocket(server->fd);
+ server->reset_socket();
return MEMCACHED_CONNECTION_FAILURE;
}
case EINTR: // Special case, we retry ai_addr
WATCHPOINT_ASSERT(server->fd != INVALID_SOCKET);
- (void)closesocket(server->fd);
- server->fd= INVALID_SOCKET;
+ server->reset_socket();
continue;
case ECONNREFUSED:
}
WATCHPOINT_ASSERT(server->fd != INVALID_SOCKET);
- (void)closesocket(server->fd);
- server->fd= INVALID_SOCKET;
+ server->reset_socket();
server->address_info_next= server->address_info_next->ai_next;
}
if (timeout_error_occured)
{
- if (server->fd != INVALID_SOCKET)
- {
- (void)closesocket(server->fd);
- server->fd= INVALID_SOCKET;
- }
+ server->reset_socket();
}
WATCHPOINT_STRING("Never got a good file descriptor");
if (memcached_failed(rc) and server->fd != INVALID_SOCKET)
{
WATCHPOINT_ASSERT(server->fd != INVALID_SOCKET);
- (void)closesocket(server->fd);
- server->fd= INVALID_SOCKET;
+ server->reset_socket();
}
}
}
*/
#include <libmemcached/common.h>
+#include <cerrno>
#include <cstdarg>
+#include <cstdio>
#define MAX_ERROR_LENGTH 2048
struct memcached_error_t
if (local_errno)
{
-#ifdef STRERROR_R_CHAR_P
+#if defined(STRERROR_R_CHAR_P) && STRERROR_R_CHAR_P
errmsg_ptr= strerror_r(local_errno, errmsg, sizeof(errmsg));
#elif defined(HAVE_STRERROR_R) && HAVE_STRERROR_R
strerror_r(local_errno, errmsg, sizeof(errmsg));
*
* LibMemcached
*
- * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2011-2013 Data Differential, http://datadifferential.com/
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*
*/
-#include <libmemcached/common.h>
+#include "libmemcached/common.h"
#pragma once
void start_close_socket();
void close_socket();
+ void reset_socket();
uint32_t response_count() const
{
}
}
+void org::libmemcached::Instance::reset_socket()
+{
+ if (fd != INVALID_SOCKET)
+ {
+ (void)closesocket(fd);
+ fd= INVALID_SOCKET;
+ }
+}
+
void org::libmemcached::Instance::close_socket()
{
if (fd != INVALID_SOCKET)
{
+ int shutdown_options= SHUT_RD;
+ if (options.is_shutting_down == false)
+ {
+ shutdown_options= SHUT_RDWR;
+ }
+
/* in case of death shutdown to avoid blocking at close() */
- if (shutdown(fd, SHUT_RD) == SOCKET_ERROR and get_socket_errno() != ENOTCONN)
+ if (shutdown(fd, shutdown_options) == SOCKET_ERROR and get_socket_errno() != ENOTCONN)
{
WATCHPOINT_NUMBER(fd);
WATCHPOINT_ERRNO(get_socket_errno());
WATCHPOINT_ASSERT(get_socket_errno());
}
- if (closesocket(fd) == SOCKET_ERROR)
- {
- WATCHPOINT_ERRNO(get_socket_errno());
- }
+ reset_socket();
state= MEMCACHED_SERVER_STATE_NEW;
- fd= INVALID_SOCKET;
}
state= MEMCACHED_SERVER_STATE_NEW;
#pragma once
#ifdef __cplusplus
+namespace org { namespace libmemcached { struct Instance; } }
typedef struct org::libmemcached::Instance* memcached_server_write_instance_st;
#else
typedef void* memcached_server_write_instance_st;
#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef memcached_return_t (*memcached_server_execute_fn)(memcached_st *ptr, memcached_server_write_instance_st server, void *context);
+
+memcached_return_t memcached_server_execute(memcached_st *ptr,
+ memcached_server_execute_fn callback,
+ void *context);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+
return NULL;
}
- self->options.is_initialized= true;
+ memcached_set_initialized(self, true);
WATCHPOINT_ASSERT(self->string == self->end);
#include <libtest/test.hpp>
#if defined(HAVE_LIBUUID) && HAVE_LIBUUID
-#include <uuid/uuid.h>
+# include <uuid/uuid.h>
#endif
/*
*/
#include <libmemcached-1.0/memcached.h>
-#include <libmemcached/is.h>
-#include <libmemcached/server_instance.h>
+#include "libmemcached/is.h"
+#include "libmemcached/server_instance.h"
#include <libhashkit-1.0/hashkit.h>
test_compare(0, pthread_join(pid[x], NULL));
}
- if (pool)
- {
- memcached_pool_destroy(pool);
- }
+ memcached_pool_destroy(pool);
- if (master)
- {
- memcached_free(master);
- }
+ memcached_free(master);
return TEST_SUCCESS;
}
* to avoid a bunch of ifdefs in the rest of the code
*
*/
-#ifndef WIN32_WRAPPERS_H
-#define WIN32_WRAPPERS_H 1
+#pragma once
#include <inttypes.h>
#define waitpid(a,b,c) (-1)
#define fnmatch(a,b,c) (-1)
#define sleep(a) Sleep(a*1000)
-
-#endif /* WIN32_WRAPPERS_H */