summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rwxr-xr-xbootstrap.sh136
-rw-r--r--configure.ac13
-rw-r--r--libmemcached/assert.hpp2
-rw-r--r--libmemcached/byteorder.cc2
-rw-r--r--libmemcached/common.h96
-rw-r--r--libmemcached/connect.cc222
-rw-r--r--libmemcached/error.cc31
-rw-r--r--libmemcached/error.hpp4
-rw-r--r--libmemcached/get.cc1
-rw-r--r--libmemcached/hosts.cc14
-rw-r--r--libmemcached/instance.cc14
-rw-r--r--libmemcached/instance.hpp38
-rw-r--r--libmemcached/io.cc25
-rw-r--r--libmemcached/sasl.cc2
-rw-r--r--libmemcached/server.cc2
-rw-r--r--libmemcached/server_instance.h17
-rw-r--r--libmemcached/string.cc2
-rw-r--r--libtest/alarm.cc2
-rw-r--r--libtest/blobslap_worker.cc16
-rw-r--r--libtest/client.cc2
-rw-r--r--libtest/cmdline.cc41
-rw-r--r--libtest/cmdline.h17
-rw-r--r--libtest/collection.cc6
-rw-r--r--libtest/collection.h4
-rw-r--r--libtest/comparison.hpp2
-rw-r--r--libtest/dns.cc38
-rw-r--r--libtest/drizzled.cc41
-rw-r--r--libtest/fatal.cc54
-rw-r--r--libtest/fatal.hpp16
-rw-r--r--libtest/framework.cc4
-rw-r--r--libtest/framework.h6
-rw-r--r--libtest/gearmand.cc14
-rw-r--r--libtest/http.cc6
-rw-r--r--libtest/include.am23
-rw-r--r--libtest/killpid.cc2
-rw-r--r--libtest/main.cc12
-rw-r--r--libtest/memcached.cc17
-rw-r--r--libtest/port.cc8
-rw-r--r--libtest/result.cc111
-rw-r--r--libtest/result.hpp18
-rw-r--r--libtest/result/base.hpp28
-rw-r--r--libtest/result/fail.hpp12
-rw-r--r--libtest/result/fatal.hpp19
-rw-r--r--libtest/result/skip.hpp11
-rw-r--r--libtest/runner.cc30
-rw-r--r--libtest/runner.h4
-rw-r--r--libtest/server.cc22
-rw-r--r--libtest/server.h7
-rw-r--r--libtest/server_container.cc32
-rw-r--r--libtest/server_container.h11
-rw-r--r--libtest/signal.cc5
-rw-r--r--libtest/stream.h23
-rw-r--r--libtest/strerror.cc2
-rw-r--r--libtest/thread.hpp20
-rw-r--r--libtest/timer.cc83
-rw-r--r--libtest/timer.hpp95
-rw-r--r--libtest/unittest.cc29
-rw-r--r--libtest/vchar.cc2
-rw-r--r--libtest/wait.h3
-rw-r--r--tests/cycle.cc6
-rw-r--r--tests/failure.cc2
-rw-r--r--tests/include.am1
-rw-r--r--tests/libmemcached-1.0/mem_functions.cc6
-rw-r--r--tests/libmemcached-1.0/pool.cc35
-rw-r--r--tests/libmemcached_world.h4
-rw-r--r--tests/libmemcached_world_socket.h4
-rw-r--r--tests/memcapable.cc2
-rw-r--r--tests/memcat.cc2
-rw-r--r--tests/memcp.cc2
-rw-r--r--tests/memdump.cc2
-rw-r--r--tests/memexist.cc2
-rw-r--r--tests/memflush.cc2
-rw-r--r--tests/memrm.cc2
-rw-r--r--tests/memslap.cc4
-rw-r--r--tests/memstat.cc2
-rw-r--r--tests/memtouch.cc2
-rw-r--r--util/string.hpp2
-rw-r--r--win32/wrappers.h5
79 files changed, 870 insertions, 740 deletions
diff --git a/ChangeLog b/ChangeLog
index 39426bd7..196f8dbe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,8 @@
1.1.0
* Enable MEMCACHED_BEHAVIOR_VERIFY_KEY by default
-* Added support to do two part shutdown of socket.
-
+1.0.16
+* Added support to do two part shutdown of socket.
1.0.15 Mon Dec 17 07:25:44 EST 2012
* Added support for Murmur3 (HASHKIT_HASH_MURMUR3)
diff --git a/bootstrap.sh b/bootstrap.sh
index ca36e37c..fdc43f99 100755
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -1,6 +1,6 @@
#!/bin/bash
#
-# Copyright (C) 2012 Brian Aker
+# Copyright (C) 2012-2013 Brian Aker
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -414,7 +414,8 @@ function restore_BUILD ()
OLD_CONFIGURE_ARG=
OLD_MAKE=
OLD_TESTS_ENVIRONMENT=
- echo "reset happened"
+
+ export -n CC CXX
}
function push_PREFIX_ARG ()
@@ -625,7 +626,29 @@ function check_mingw ()
return 0
}
-function make_skeleton_mingw ()
+function check_clang ()
+{
+ command_exists 'clang'
+ ret=$?
+ if [ "$ret" -ne 0 ]; then
+ return 1
+ fi
+
+ return 0
+}
+
+function check_clang_analyzer ()
+{
+ command_exists 'scan-build'
+ ret=$?
+ if [ "$ret" -ne 0 ]; then
+ return 1
+ fi
+
+ return 0
+}
+
+function make_skeleton ()
{
run_configure
ret=$?
@@ -642,8 +665,6 @@ function make_skeleton_mingw ()
if command_exists 'wine'; then
TESTS_ENVIRONMENT='wine'
fi
- elif command_exists 'wineconsole'; then
- TESTS_ENVIRONMENT='wineconsole --backend=curses'
fi
if [[ -n "$TESTS_ENVIRONMENT" ]]; then
@@ -662,9 +683,8 @@ function make_skeleton_mingw ()
function make_for_mingw ()
{
- check_mingw
if ! check_mingw; then
- die 'mingw64 tools were not found'
+ return 1
fi
# Make sure it is clean
@@ -678,11 +698,74 @@ function make_for_mingw ()
CONFIGURE='mingw64-configure'
MAKE='mingw64-make'
- CONFIGURE_ARGS='--enable-static'
+ CONFIGURE_ARGS='--enable-static --disable-shared'
+
+ make_skeleton
+ ret=$?
+
+ restore_BUILD
+
+ return $ret
+}
+
+function make_for_clang ()
+{
+ if ! check_clang; then
+ return 1
+ fi
+
+ # Make sure it is clean
+ if [ -f Makefile -o -f configure ]; then
+ make_maintainer_clean
+ fi
+
+ run_autoreconf
+
+ save_BUILD
- make_skeleton_mingw
+ CC=clang CXX=clang++
+ export CC CXX
+
+ make_skeleton
+ ret=$?
+
+ make_target 'check'
+
+ restore_BUILD
+
+ return $ret
+}
+
+function make_for_clang_analyzer ()
+{
+ if ! check_clang; then
+ return 1
+ fi
+
+ if ! check_clang_analyzer; then
+ die 'clang-analyzer was not found'
+ fi
+
+ # Make sure it is clean
+ if [ -f Makefile -o -f configure ]; then
+ make_maintainer_clean
+ fi
+
+ run_autoreconf
+
+ save_BUILD
+
+ CC=clang CXX=clang++
+ export CC CXX
+ CONFIGURE_ARGS='--enable-debug'
+
+ make_skeleton
ret=$?
+ make_target 'clean' 'warn'
+
+ scan-build -o clang-html make -j4 -k
+
restore_BUILD
return $ret
@@ -710,6 +793,8 @@ function make_universe ()
make_valgrind
make_gdb
make_rpm
+ make_for_clang
+ make_for_clang_analyzer
if [ check_mingw -eq 0 ]; then
make_for_mingw
@@ -883,9 +968,9 @@ function make_target ()
if [ $ret -ne 0 ]; then
if [ -n "$2" ]; then
- warn "Cannot execute $MAKE $1: $ret"
+ warn "Failed to execute $MAKE $1: $ret"
else
- die "Cannot execute $MAKE $1: $ret"
+ die "Failed to execute $MAKE $1: $ret"
fi
fi
@@ -1333,6 +1418,10 @@ function check_make_target()
;;
'make_default')
;;
+ 'clang')
+ ;;
+ 'clang-analyzer')
+ ;;
'test-*')
;;
'valgrind-*')
@@ -1417,15 +1506,32 @@ function bootstrap ()
'make_default')
make_default
;;
+ 'clang')
+ if ! check_clang; then
+ die "clang was not found"
+ fi
+
+ if ! make_for_clang; then
+ die "Failed to build clang: $?"
+ fi
+ ;;
+ 'clang-analyzer')
+ if ! check_clang_analyzer; then
+ die "clang-analyzer was not found"
+ fi
+ if ! check_clang; then
+ die "clang was not found"
+ fi
+
+ if ! make_for_clang_analyzer; then
+ die "Failed to build clang-analyzer: $?"
+ fi
+ ;;
'mingw')
- check_mingw
if ! check_mingw; then
die "mingw was not found"
fi
- make_for_mingw
- check_ret=$?
-
if ! make_for_mingw; then
die "Failed to build mingw: $?"
fi
diff --git a/configure.ac b/configure.ac
index e5a060c8..724ad251 100644
--- a/configure.ac
+++ b/configure.ac
@@ -113,6 +113,7 @@ AC_CHECK_HEADERS_ONCE([arpa/inet.h])
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])
@@ -133,6 +134,7 @@ AC_CHECK_HEADERS_ONCE([stdlib.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])
@@ -189,7 +191,16 @@ AM_CONDITIONAL([BUILD_CACHE],[test "x$build_cache" = "xyes"])
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
diff --git a/libmemcached/assert.hpp b/libmemcached/assert.hpp
index d66b096f..cd4a194b 100644
--- a/libmemcached/assert.hpp
+++ b/libmemcached/assert.hpp
@@ -2,7 +2,7 @@
*
* 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
diff --git a/libmemcached/byteorder.cc b/libmemcached/byteorder.cc
index eb37fda8..9f11aa84 100644
--- a/libmemcached/byteorder.cc
+++ b/libmemcached/byteorder.cc
@@ -46,7 +46,7 @@ static inline uint64_t swap64(uint64_t in)
/* 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;
diff --git a/libmemcached/common.h b/libmemcached/common.h
index 92fdb2f8..05b73213 100644
--- a/libmemcached/common.h
+++ b/libmemcached/common.h
@@ -112,14 +112,10 @@
#endif
#include <libmemcached-1.2/memcached.h>
-#include <libmemcached/watchpoint.h>
-#include <libmemcached/is.h>
-typedef struct memcached_st Memcached;
+#include "libmemcached/watchpoint.h"
+#include "libmemcached/is.h"
-#ifdef __cplusplus
-# include "libmemcached/instance.hpp"
-#endif
-#include <libmemcached/server_instance.h>
+typedef struct memcached_st Memcached;
#ifdef HAVE_POLL_H
# include <poll.h>
@@ -128,67 +124,57 @@ typedef struct memcached_st Memcached;
#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)
diff --git a/libmemcached/connect.cc b/libmemcached/connect.cc
index d2580b5e..2ec9975c 100644
--- a/libmemcached/connect.cc
+++ b/libmemcached/connect.cc
@@ -64,7 +64,7 @@
# define TCP_KEEPIDLE 0
#endif
-static memcached_return_t connect_poll(org::libmemcached::Instance* server)
+static memcached_return_t connect_poll(org::libmemcached::Instance* server, const int connection_error)
{
struct pollfd fds[1];
fds[0].fd= server->fd;
@@ -75,102 +75,136 @@ static memcached_return_t connect_poll(org::libmemcached::Instance* server)
if (server->root->poll_timeout == 0)
{
- return memcached_set_error(*server, MEMCACHED_TIMEOUT, MEMCACHED_AT);
+ return memcached_set_error(*server, MEMCACHED_TIMEOUT, MEMCACHED_AT,
+ memcached_literal_param("The time to wait for a connection to be established was set to zero, which means it will always timeout (MEMCACHED_TIMEOUT)."));
}
while (--loop_max) // Should only loop on cases of ERESTART or EINTR
{
int number_of;
- if ((number_of= poll(fds, 1, server->root->connect_timeout)) <= 0)
+ if ((number_of= poll(fds, 1, server->root->connect_timeout)) == -1)
{
- if (number_of == -1)
+ int local_errno= get_socket_errno(); // We cache in case closesocket() modifies errno
+ switch (local_errno)
{
- int local_errno= get_socket_errno(); // We cache in case closesocket() modifies errno
- switch (local_errno)
- {
#ifdef TARGET_OS_LINUX
- case ERESTART:
+ case ERESTART:
#endif
- case EINTR:
- continue;
+ case EINTR:
+ continue;
- case EFAULT:
- case ENOMEM:
- return memcached_set_error(*server, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
+ case EFAULT:
+ case ENOMEM:
+ return memcached_set_error(*server, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
- case EINVAL:
- return memcached_set_error(*server, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, memcached_literal_param("RLIMIT_NOFILE exceeded, or if OSX the timeout value was invalid"));
+ case EINVAL:
+ return memcached_set_error(*server, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT,
+ memcached_literal_param("RLIMIT_NOFILE exceeded, or if OSX the timeout value was invalid"));
- default: // This should not happen
- if (fds[0].revents & POLLERR)
+ default: // This should not happen
+ break;
+#if 0
+ if (fds[0].revents & POLLERR)
+ {
+ int err;
+ socklen_t len= sizeof(err);
+ if (getsockopt(server->fd, SOL_SOCKET, SO_ERROR, (char*)&err, &len) == 0)
{
- int err;
- socklen_t len= sizeof(err);
- if (getsockopt(server->fd, SOL_SOCKET, SO_ERROR, (char*)&err, &len) == 0)
+ if (err == 0)
{
- if (err == 0)
- {
- // This should never happen, if it does? Punt.
- continue;
- }
- local_errno= err;
+ // This should never happen, if it does? Punt.
+ continue;
}
+ local_errno= err;
}
+ }
+#endif
+ }
+
+ assert_msg(server->fd != INVALID_SOCKET, "poll() was passed an invalid file descriptor");
+ server->reset_socket();
+ server->state= MEMCACHED_SERVER_STATE_NEW;
+
+ return memcached_set_errno(*server, local_errno, MEMCACHED_AT);
+ }
- assert_msg(server->fd != INVALID_SOCKET, "poll() was passed an invalid file descriptor");
- (void)closesocket(server->fd);
- server->fd= INVALID_SOCKET;
- server->state= MEMCACHED_SERVER_STATE_NEW;
+ if (number_of == 0)
+ {
+ if (connection_error == EINPROGRESS)
+ {
+ int err;
+ socklen_t len= sizeof(err);
+ if (getsockopt(server->fd, SOL_SOCKET, SO_ERROR, (char*)&err, &len) == -1)
+ {
+ return memcached_set_errno(*server, errno, MEMCACHED_AT, memcached_literal_param("getsockopt() error'ed while looking for error connect_poll(EINPROGRESS)"));
+ }
- return memcached_set_errno(*server, local_errno, MEMCACHED_AT);
+ // If Zero, my hero, we just fail to a generic MEMCACHED_TIMEOUT error
+ if (err != 0)
+ {
+ return memcached_set_errno(*server, err, MEMCACHED_AT, memcached_literal_param("getsockopt() found the error from poll() after connect() returned EINPROGRESS."));
}
}
- assert(number_of == 0);
- server->io_wait_count.timeouts++;
- return memcached_set_error(*server, MEMCACHED_TIMEOUT, MEMCACHED_AT);
+ return memcached_set_error(*server, MEMCACHED_TIMEOUT, MEMCACHED_AT);
}
#if 0
server->revents(fds[0].revents);
#endif
+ assert (number_of == 1);
+
if (fds[0].revents & POLLERR or
fds[0].revents & POLLHUP or
fds[0].revents & POLLNVAL)
{
int err;
socklen_t len= sizeof (err);
- if (getsockopt(fds[0].fd, SOL_SOCKET, SO_ERROR, (char*)&err, &len) == 0)
+ if (getsockopt(fds[0].fd, SOL_SOCKET, SO_ERROR, (char*)&err, &len) == -1)
{
- // We check the value to see what happened wth the socket.
- if (err == 0)
- {
- return MEMCACHED_SUCCESS;
- }
- errno= err;
+ return memcached_set_errno(*server, errno, MEMCACHED_AT, memcached_literal_param("getsockopt() errored while looking up error state from poll()"));
+ }
+
+ // We check the value to see what happened wth the socket.
+ if (err == 0) // Should not happen
+ {
+ return MEMCACHED_SUCCESS;
}
+ errno= err;
- return memcached_set_errno(*server, err, MEMCACHED_AT);
+ return memcached_set_errno(*server, err, MEMCACHED_AT, memcached_literal_param("getsockopt() found the error from poll() during connect."));
}
- assert(fds[0].revents & POLLIN or fds[0].revents & POLLOUT);
+ assert(fds[0].revents & POLLOUT);
- return MEMCACHED_SUCCESS;
+ if (fds[0].revents & POLLOUT and connection_error == EINPROGRESS)
+ {
+ int err;
+ socklen_t len= sizeof(err);
+ if (getsockopt(server->fd, SOL_SOCKET, SO_ERROR, (char*)&err, &len) == -1)
+ {
+ return memcached_set_errno(*server, errno, MEMCACHED_AT);
+ }
+
+ if (err == 0)
+ {
+ return MEMCACHED_SUCCESS;
+ }
+
+ return memcached_set_errno(*server, err, MEMCACHED_AT, memcached_literal_param("getsockopt() found the error from poll() after connect() returned EINPROGRESS."));
+ }
+
+ break; // We only have the loop setup for errno types that require restart
}
// This should only be possible from ERESTART or EINTR;
- return memcached_set_errno(*server, get_socket_errno(), MEMCACHED_AT);
+ return memcached_set_errno(*server, connection_error, MEMCACHED_AT, memcached_literal_param("connect_poll() was exhausted"));
}
static memcached_return_t set_hostinfo(org::libmemcached::Instance* server)
{
assert(server->type != MEMCACHED_CONNECTION_UNIX_SOCKET);
- if (server->address_info)
- {
- freeaddrinfo(server->address_info);
- server->address_info= NULL;
- server->address_info_next= NULL;
- }
+ server->clear_addrinfo();
char str_port[MEMCACHED_NI_MAXSERV];
int length= snprintf(str_port, MEMCACHED_NI_MAXSERV, "%u", uint32_t(server->port()));
@@ -183,9 +217,7 @@ static memcached_return_t set_hostinfo(org::libmemcached::Instance* server)
struct addrinfo hints;
memset(&hints, 0, sizeof(struct addrinfo));
-#if 0
hints.ai_family= AF_INET;
-#endif
if (memcached_is_udp(server->root))
{
hints.ai_protocol= IPPROTO_UDP;
@@ -200,54 +232,35 @@ static memcached_return_t set_hostinfo(org::libmemcached::Instance* server)
assert(server->address_info == NULL);
assert(server->address_info_next == NULL);
int errcode;
- switch(errcode= getaddrinfo(server->hostname, str_port, &hints, &server->address_info))
+ assert(server->hostname());
+ switch(errcode= getaddrinfo(server->hostname(), str_port, &hints, &server->address_info))
{
case 0:
+ server->address_info_next= server->address_info;
+ server->state= MEMCACHED_SERVER_STATE_ADDRINFO;
break;
case EAI_AGAIN:
return memcached_set_error(*server, MEMCACHED_TIMEOUT, MEMCACHED_AT, memcached_string_make_from_cstr(gai_strerror(errcode)));
case EAI_SYSTEM:
- if (server->address_info)
- {
- freeaddrinfo(server->address_info);
- server->address_info= NULL;
- server->address_info_next= NULL;
- }
+ server->clear_addrinfo();
return memcached_set_errno(*server, errno, MEMCACHED_AT, memcached_literal_param("getaddrinfo(EAI_SYSTEM)"));
case EAI_BADFLAGS:
- if (server->address_info)
- {
- freeaddrinfo(server->address_info);
- server->address_info= NULL;
- server->address_info_next= NULL;
- }
+ server->clear_addrinfo();
return memcached_set_error(*server, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("getaddrinfo(EAI_BADFLAGS)"));
case EAI_MEMORY:
- if (server->address_info)
- {
- freeaddrinfo(server->address_info);
- server->address_info= NULL;
- server->address_info_next= NULL;
- }
+ server->clear_addrinfo();
return memcached_set_error(*server, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, memcached_literal_param("getaddrinfo(EAI_MEMORY)"));
default:
{
- if (server->address_info)
- {
- freeaddrinfo(server->address_info);
- server->address_info= NULL;
- server->address_info_next= NULL;
- }
+ server->clear_addrinfo();
return memcached_set_error(*server, MEMCACHED_HOST_LOOKUP_FAILURE, MEMCACHED_AT, memcached_string_make_from_cstr(gai_strerror(errcode)));
}
}
- server->address_info_next= server->address_info;
- server->state= MEMCACHED_SERVER_STATE_ADDRINFO;
return MEMCACHED_SUCCESS;
}
@@ -463,7 +476,7 @@ static memcached_return_t unix_socket_connect(org::libmemcached::Instance* serve
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);
}
@@ -472,9 +485,9 @@ static memcached_return_t unix_socket_connect(org::libmemcached::Instance* serve
memset(&servAddr, 0, sizeof (struct sockaddr_un));
servAddr.sun_family= AF_UNIX;
- strncpy(servAddr.sun_path, server->hostname, sizeof(servAddr.sun_path)); /* Copy filename */
+ 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)
{
@@ -484,22 +497,19 @@ static memcached_return_t unix_socket_connect(org::libmemcached::Instance* serve
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);
}
}
@@ -537,11 +547,8 @@ static memcached_return_t network_connect(org::libmemcached::Instance* server)
}
}
- if (server->address_info_next == NULL)
- {
- server->address_info_next= server->address_info;
- server->state= MEMCACHED_SERVER_STATE_ADDRINFO;
- }
+ assert(server->address_info_next);
+ assert(server->address_info);
/* Create the socket */
while (server->address_info_next and server->fd == INVALID_SOCKET)
@@ -575,7 +582,7 @@ static memcached_return_t network_connect(org::libmemcached::Instance* server)
if (set_socket_options(server) == false)
{
- (void)closesocket(server->fd);
+ server->reset_socket();
return MEMCACHED_CONNECTION_FAILURE;
}
@@ -587,7 +594,8 @@ static memcached_return_t network_connect(org::libmemcached::Instance* server)
}
/* An error occurred */
- switch (get_socket_errno())
+ int local_error= get_socket_errno();
+ switch (local_error)
{
case ETIMEDOUT:
timeout_error_occured= true;
@@ -602,7 +610,7 @@ static memcached_return_t network_connect(org::libmemcached::Instance* server)
{
server->events(POLLOUT);
server->state= MEMCACHED_SERVER_STATE_IN_PROGRESS;
- memcached_return_t rc= connect_poll(server);
+ memcached_return_t rc= connect_poll(server, local_error);
if (memcached_success(rc))
{
@@ -624,8 +632,7 @@ static memcached_return_t network_connect(org::libmemcached::Instance* server)
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:
@@ -636,8 +643,7 @@ static memcached_return_t network_connect(org::libmemcached::Instance* server)
}
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;
}
@@ -645,11 +651,7 @@ static memcached_return_t network_connect(org::libmemcached::Instance* server)
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");
@@ -764,7 +766,7 @@ static memcached_return_t _memcached_connect(org::libmemcached::Instance* server
return memcached_set_error(*server, MEMCACHED_INVALID_HOST_PROTOCOL, MEMCACHED_AT, memcached_literal_param("SASL is not supported for UDP connections"));
}
- if (server->hostname[0] == '/')
+ if (server->hostname()[0] == '/')
{
server->type= MEMCACHED_CONNECTION_UNIX_SOCKET;
}
@@ -781,12 +783,10 @@ static memcached_return_t _memcached_connect(org::libmemcached::Instance* server
if (server->fd != INVALID_SOCKET and server->root->sasl.callbacks)
{
rc= memcached_sasl_authenticate_connection(server);
- fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, rc));
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();
}
}
}
@@ -822,7 +822,7 @@ static memcached_return_t _memcached_connect(org::libmemcached::Instance* server
if (in_timeout)
{
char buffer[1024];
- int snprintf_length= snprintf(buffer, sizeof(buffer), "%s:%d", server->hostname, int(server->port()));
+ int snprintf_length= snprintf(buffer, sizeof(buffer), "%s:%d", server->hostname(), int(server->port()));
return memcached_set_error(*server, MEMCACHED_SERVER_TEMPORARILY_DISABLED, MEMCACHED_AT, buffer, snprintf_length);
}
}
diff --git a/libmemcached/error.cc b/libmemcached/error.cc
index 85326780..314f3623 100644
--- a/libmemcached/error.cc
+++ b/libmemcached/error.cc
@@ -36,7 +36,9 @@
*/
#include <libmemcached/common.h>
+#include <cerrno>
#include <cstdarg>
+#include <cstdio>
#define MAX_ERROR_LENGTH 2048
struct memcached_error_t
@@ -57,20 +59,21 @@ static void _set(org::libmemcached::Instance& server, Memcached& memc)
memcached_error_free(server);
}
- if (memc.error_messages == NULL)
+ if (memc.error_messages)
{
- return;
- }
+ if (memc.error_messages->rc == MEMCACHED_TIMEOUT)
+ {
+ server.io_wait_count.timeouts++;
+ }
- memcached_error_t *error= libmemcached_xmalloc(&memc, memcached_error_t);
- if (error == NULL) // Bad business if this happens
- {
- return;
+ memcached_error_t *error= libmemcached_xmalloc(&memc, memcached_error_t);
+ if (error)
+ {
+ memcpy(error, memc.error_messages, sizeof(memcached_error_t));
+ error->next= server.error_messages;
+ server.error_messages= error;
+ }
}
-
- memcpy(error, memc.error_messages, sizeof(memcached_error_t));
- error->next= server.error_messages;
- server.error_messages= error;
}
#if 0
@@ -139,7 +142,7 @@ static void _set(memcached_st& memc, memcached_string_t *str, memcached_return_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));
@@ -260,12 +263,12 @@ static inline size_t append_host_to_string(org::libmemcached::Instance& self, ch
case MEMCACHED_CONNECTION_TCP:
case MEMCACHED_CONNECTION_UDP:
size+= snprintf(buffer, buffer_length, " host: %s:%d",
- self.hostname, int(self.port()));
+ self.hostname(), int(self.port()));
break;
case MEMCACHED_CONNECTION_UNIX_SOCKET:
size+= snprintf(buffer, buffer_length, " socket: %s",
- self.hostname);
+ self.hostname());
break;
}
diff --git a/libmemcached/error.hpp b/libmemcached/error.hpp
index 5b82d13a..cdbc6ab1 100644
--- a/libmemcached/error.hpp
+++ b/libmemcached/error.hpp
@@ -2,7 +2,7 @@
*
* 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
@@ -35,7 +35,7 @@
*
*/
-#include <libmemcached/common.h>
+#include "libmemcached/common.h"
#pragma once
diff --git a/libmemcached/get.cc b/libmemcached/get.cc
index d20d4f17..79e1d832 100644
--- a/libmemcached/get.cc
+++ b/libmemcached/get.cc
@@ -57,7 +57,6 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr,
const size_t *key_length,
size_t number_of_keys,
bool mget_mode);
-
char *memcached_get_by_key(memcached_st *shell,
const char *group_key,
size_t group_key_length,
diff --git a/libmemcached/hosts.cc b/libmemcached/hosts.cc
index 20677694..747245f9 100644
--- a/libmemcached/hosts.cc
+++ b/libmemcached/hosts.cc
@@ -49,7 +49,7 @@ static int compare_servers(const void *p1, const void *p2)
memcached_server_instance_st a= (memcached_server_instance_st)p1;
memcached_server_instance_st b= (memcached_server_instance_st)p2;
- int return_value= strcmp(a->hostname, b->hostname);
+ int return_value= strcmp(a->_hostname, b->_hostname);
if (return_value == 0)
{
@@ -224,7 +224,7 @@ static memcached_return_t update_continuum(Memcached *ptr)
if (DEBUG)
{
printf("ketama_weighted:%s|%d|%llu|%u\n",
- list[host_index].hostname,
+ list[host_index]._hostname,
list[host_index].port(),
(unsigned long long)list[host_index].weight,
pointer_per_server);
@@ -245,7 +245,7 @@ static memcached_return_t update_continuum(Memcached *ptr)
// If hostname is not available then: /ip:port-index
sort_host_length= snprintf(sort_host, sizeof(sort_host),
"/%s:%u-%u",
- list[host_index].hostname,
+ list[host_index]._hostname,
(uint32_t)list[host_index].port(),
pointer_index);
@@ -290,14 +290,14 @@ static memcached_return_t update_continuum(Memcached *ptr)
{
sort_host_length= snprintf(sort_host, sizeof(sort_host),
"%s-%u",
- list[host_index].hostname,
+ list[host_index]._hostname,
pointer_index - 1);
}
else
{
sort_host_length= snprintf(sort_host, sizeof(sort_host),
"%s:%u-%u",
- list[host_index].hostname,
+ list[host_index]._hostname,
(uint32_t)list[host_index].port(),
pointer_index - 1);
}
@@ -474,13 +474,13 @@ memcached_return_t memcached_instance_push(memcached_st *ptr, const struct org::
// instance allocated.
for (uint32_t x= 0; x < number_of_hosts; ++x, ++original_host_size)
{
- WATCHPOINT_ASSERT(list[x].hostname[0] != 0);
+ WATCHPOINT_ASSERT(list[x]._hostname[0] != 0);
// We have extended the array, and now we will find it, and use it.
org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, original_host_size);
WATCHPOINT_ASSERT(instance);
- memcached_string_t hostname= { memcached_string_make_from_cstr(list[x].hostname) };
+ memcached_string_t hostname= { memcached_string_make_from_cstr(list[x]._hostname) };
if (__instance_create_with(ptr, instance,
hostname,
list[x].port(), list[x].weight, list[x].type) == NULL)
diff --git a/libmemcached/instance.cc b/libmemcached/instance.cc
index 593465d8..ca3a30d8 100644
--- a/libmemcached/instance.cc
+++ b/libmemcached/instance.cc
@@ -84,8 +84,7 @@ static inline void _server_init(org::libmemcached::Instance* self, Memcached *ro
self->version= UINT_MAX;
}
self->limit_maxbytes= 0;
- memcpy(self->hostname, hostname.c_str, hostname.size);
- self->hostname[hostname.size]= 0;
+ self->hostname(hostname);
}
static org::libmemcached::Instance* _server_create(org::libmemcached::Instance* self, const memcached_st *memc)
@@ -167,12 +166,7 @@ void __instance_free(org::libmemcached::Instance* self)
{
memcached_quit_server(self, false);
- if (self->address_info)
- {
- freeaddrinfo(self->address_info);
- self->address_info= NULL;
- self->address_info_next= NULL;
- }
+ self->clear_addrinfo();
assert(self->address_info_next == NULL);
memcached_error_free(*self);
@@ -297,10 +291,10 @@ static org::libmemcached::Instance* memcached_instance_clone(org::libmemcached::
return NULL;
}
- memcached_string_t hostname= { memcached_string_make_from_cstr(source->hostname) };
+ memcached_string_t hostname_= { memcached_string_make_from_cstr(source->hostname()) };
return __instance_create_with(source->root,
NULL,
- hostname,
+ hostname_,
source->port(), source->weight,
source->type);
}
diff --git a/libmemcached/instance.hpp b/libmemcached/instance.hpp
index 8f66e96d..d0a772b9 100644
--- a/libmemcached/instance.hpp
+++ b/libmemcached/instance.hpp
@@ -2,7 +2,7 @@
*
* Libmemcached library
*
- * Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -56,6 +56,8 @@
# define MEMCACHED_NI_MAXSERV 32
#endif
+#include "libmemcached/string.hpp"
+
namespace org {
namespace libmemcached {
@@ -91,6 +93,7 @@ struct Instance {
void start_close_socket();
void close_socket();
+ void reset_socket();
uint32_t response_count() const
{
@@ -118,6 +121,25 @@ struct Instance {
return _revents;
}
+ const char* hostname()
+ {
+ return _hostname;
+ }
+
+ void hostname(const memcached_string_t& hostname_)
+ {
+ if (hostname_.size)
+ {
+ memcpy(_hostname, hostname_.c_str, hostname_.size);
+ _hostname[hostname_.size]= 0;
+ }
+ else
+ {
+ memcpy(_hostname, memcached_literal_param("localhost"));
+ _hostname[memcached_literal_param_size("localhost")]= 0;
+ }
+ }
+
void events(short);
void revents(short);
@@ -153,7 +175,17 @@ struct Instance {
struct memcached_error_t *error_messages;
char read_buffer[MEMCACHED_MAX_BUFFER];
char write_buffer[MEMCACHED_MAX_BUFFER];
- char hostname[MEMCACHED_NI_MAXHOST];
+ char _hostname[MEMCACHED_NI_MAXHOST];
+
+ void clear_addrinfo()
+ {
+ if (address_info)
+ {
+ freeaddrinfo(address_info);
+ address_info= NULL;
+ address_info_next= NULL;
+ }
+ }
};
} // namespace libmemcached
@@ -161,7 +193,7 @@ struct Instance {
org::libmemcached::Instance* __instance_create_with(memcached_st *memc,
org::libmemcached::Instance* self,
- const memcached_string_t& hostname,
+ const memcached_string_t& _hostname,
const in_port_t port,
uint32_t weight,
const memcached_connection_t type);
diff --git a/libmemcached/io.cc b/libmemcached/io.cc
index 20233c7d..f6cc3696 100644
--- a/libmemcached/io.cc
+++ b/libmemcached/io.cc
@@ -212,7 +212,6 @@ static memcached_return_t io_wait(org::libmemcached::Instance* instance,
if (instance->root->poll_timeout == 0) // Mimic 0 causes timeout behavior (not all platforms do this)
{
- instance->io_wait_count.timeouts++;
return memcached_set_error(*instance, MEMCACHED_TIMEOUT, MEMCACHED_AT);
}
@@ -258,7 +257,6 @@ static memcached_return_t io_wait(org::libmemcached::Instance* instance,
if (active_fd == 0)
{
- instance->io_wait_count.timeouts++;
return memcached_set_error(*instance, MEMCACHED_TIMEOUT, MEMCACHED_AT);
}
@@ -712,24 +710,35 @@ void org::libmemcached::Instance::start_close_socket()
}
}
+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;
diff --git a/libmemcached/sasl.cc b/libmemcached/sasl.cc
index 69d6223d..8e180d6f 100644
--- a/libmemcached/sasl.cc
+++ b/libmemcached/sasl.cc
@@ -215,7 +215,7 @@ memcached_return_t memcached_sasl_authenticate_connection(org::libmemcached::Ins
sasl_conn_t *conn;
int ret;
- if ((ret= sasl_client_new("memcached", server->hostname, laddr, raddr, server->root->sasl.callbacks, 0, &conn) ) != SASL_OK)
+ if ((ret= sasl_client_new("memcached", server->_hostname, laddr, raddr, server->root->sasl.callbacks, 0, &conn) ) != SASL_OK)
{
const char *sasl_error_msg= sasl_errstring(ret, NULL, NULL);
diff --git a/libmemcached/server.cc b/libmemcached/server.cc
index 27e51e96..ba40a6ee 100644
--- a/libmemcached/server.cc
+++ b/libmemcached/server.cc
@@ -196,7 +196,7 @@ const char *memcached_server_name(const memcached_server_instance_st self)
WATCHPOINT_ASSERT(self);
if (self)
{
- return self->hostname;
+ return self->_hostname;
}
return NULL;
diff --git a/libmemcached/server_instance.h b/libmemcached/server_instance.h
index c840384a..3b69b77b 100644
--- a/libmemcached/server_instance.h
+++ b/libmemcached/server_instance.h
@@ -38,7 +38,24 @@
#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
+
+
diff --git a/libmemcached/string.cc b/libmemcached/string.cc
index 7826bd10..ce96b98c 100644
--- a/libmemcached/string.cc
+++ b/libmemcached/string.cc
@@ -115,7 +115,7 @@ memcached_string_st *memcached_string_create(Memcached *memc, memcached_string_s
return NULL;
}
- self->options.is_initialized= true;
+ memcached_set_initialized(self, true);
WATCHPOINT_ASSERT(self->string == self->end);
diff --git a/libtest/alarm.cc b/libtest/alarm.cc
index 80d7b2f6..a8bf17e8 100644
--- a/libtest/alarm.cc
+++ b/libtest/alarm.cc
@@ -68,7 +68,7 @@ void set_alarm(long tv_sec, long tv_usec)
if (errno != 0)
{
- fatal_message("Bad value for YATL_ALARM");
+ FATAL("Bad value for YATL_ALARM");
}
else if (tv_sec == 0)
{
diff --git a/libtest/blobslap_worker.cc b/libtest/blobslap_worker.cc
index 612847e5..5100a388 100644
--- a/libtest/blobslap_worker.cc
+++ b/libtest/blobslap_worker.cc
@@ -146,26 +146,14 @@ public:
return true;
}
- bool build(size_t argc, const char *argv[]);
+ bool build();
};
#include <sstream>
-bool BlobslapWorker::build(size_t argc, const char *argv[])
+bool BlobslapWorker::build()
{
- std::stringstream arg_buffer;
-
- for (size_t x= 0 ; x < argc ; x++)
- {
- if (argv[x] == NULL)
- {
- break;
- }
-
- add_option(argv[x]);
- }
-
return true;
}
diff --git a/libtest/client.cc b/libtest/client.cc
index f3409cc8..c536e9dd 100644
--- a/libtest/client.cc
+++ b/libtest/client.cc
@@ -198,7 +198,7 @@ bool SimpleClient::instance_connect()
}
else
{
- fatal_message(strerror(errno));
+ FATAL(strerror(errno));
}
address_info_next= address_info_next->ai_next;
}
diff --git a/libtest/cmdline.cc b/libtest/cmdline.cc
index c8b63eec..741d18d7 100644
--- a/libtest/cmdline.cc
+++ b/libtest/cmdline.cc
@@ -138,7 +138,7 @@ Application::Application(const std::string& arg, const bool _use_libtool_arg) :
{
if (libtool() == NULL)
{
- fatal_message("libtool requested, but know libtool was found");
+ FATAL("libtool requested, but know libtool was found");
}
}
@@ -366,15 +366,15 @@ bool Application::slurp()
case EFAULT:
case ENOMEM:
- fatal_message(strerror(error));
+ FATAL(strerror(error));
break;
case EINVAL:
- fatal_message("RLIMIT_NOFILE exceeded, or if OSX the timeout value was invalid");
+ FATAL("RLIMIT_NOFILE exceeded, or if OSX the timeout value was invalid");
break;
default:
- fatal_message(strerror(error));
+ FATAL(strerror(error));
break;
}
@@ -409,8 +409,10 @@ bool Application::slurp()
Application::error_t Application::join()
{
pid_t waited_pid= waitpid(_pid, &_status, 0);
+ slurp();
if (waited_pid == _pid and WIFEXITED(_status) == false)
{
+
/*
What we are looking for here is how the exit status happened.
- 127 means that posix_spawn() itself had an error.
@@ -423,7 +425,12 @@ Application::error_t Application::join()
std::string error_string("posix_spawn() failed pid:");
error_string+= _pid;
error_string+= " name:";
- error_string+= built_argv[0];
+ error_string+= print_argv(built_argv);
+ if (stderr_result_length())
+ {
+ error_string+= " stderr: ";
+ error_string+= stderr_c_str();
+ }
throw std::logic_error(error_string);
}
else if (WIFSIGNALED(_status))
@@ -431,9 +438,20 @@ Application::error_t Application::join()
if (WTERMSIG(_status) != SIGTERM and WTERMSIG(_status) != SIGHUP)
{
_app_exit_state= Application::INVALID_POSIX_SPAWN;
- std::string error_string(built_argv[0]);
+ std::string error_string(print_argv(built_argv));
error_string+= " was killed by signal ";
error_string+= strsignal(WTERMSIG(_status));
+ if (stdout_result_length())
+ {
+ error_string+= " stdout: ";
+ error_string+= stdout_c_str();
+ }
+ if (stderr_result_length())
+ {
+ error_string+= " stderr: ";
+ error_string+= stderr_c_str();
+ }
+
throw std::runtime_error(error_string);
}
@@ -589,18 +607,17 @@ void Application::Pipe::reset()
if (pipe(_pipe_fd) == -1)
#endif
{
- fatal_message(strerror(errno));
+ FATAL(strerror(errno));
}
_open[0]= true;
_open[1]= true;
#if defined(HAVE_PIPE2) && HAVE_PIPE2
- return;
-#endif
{
nonblock();
cloexec();
}
+#endif
}
void Application::Pipe::cloexec()
@@ -656,14 +673,12 @@ void Application::Pipe::dup_for_spawn(posix_spawn_file_actions_t& file_actions)
int ret;
if ((ret= posix_spawn_file_actions_adddup2(&file_actions, _pipe_fd[type], _std_fd )) < 0)
{
- Error << "posix_spawn_file_actions_adddup2(" << strerror(ret) << ")";
- fatal_message(strerror(ret));
+ FATAL("posix_spawn_file_actions_adddup2(%s)", strerror(ret));
}
if ((ret= posix_spawn_file_actions_addclose(&file_actions, _pipe_fd[type])) < 0)
{
- Error << "posix_spawn_file_actions_adddup2(" << strerror(ret) << ")";
- fatal_message(strerror(ret));
+ FATAL("posix_spawn_file_actions_addclose(%s)", strerror(ret));
}
}
diff --git a/libtest/cmdline.h b/libtest/cmdline.h
index d150ff59..6bf71b64 100644
--- a/libtest/cmdline.h
+++ b/libtest/cmdline.h
@@ -36,13 +36,7 @@
#pragma once
-#ifdef _WIN32
-typedef int posix_spawn_file_actions_t;
-#else
-# include <spawn.h>
-#endif
-
-#include <pthread.h>
+#include <spawn.h>
// http://www.gnu.org/software/automake/manual/automake.html#Using-the-TAP-test-protocol
#ifndef EXIT_SKIP
@@ -54,11 +48,11 @@ typedef int posix_spawn_file_actions_t;
#endif
#ifndef EX_NOEXEC
-# define EX_NOEXEC 126
+# define EX_NOEXEC 126
#endif
#ifndef EX_NOTFOUND
-# define EX_NOTFOUND 127
+# define EX_NOTFOUND 127
#endif
namespace libtest {
@@ -156,6 +150,11 @@ public:
return _stdout_buffer.size();
}
+ const char* stdout_c_str() const
+ {
+ return &_stdout_buffer[0];
+ }
+
libtest::vchar_t stderr_result() const
{
return _stderr_buffer;
diff --git a/libtest/collection.cc b/libtest/collection.cc
index 1b4915e1..86e7f864 100644
--- a/libtest/collection.cc
+++ b/libtest/collection.cc
@@ -55,7 +55,7 @@ static test_return_t runner_code(libtest::Framework* frame,
}
// Special case where check for the testing of the exception
// system.
- catch (libtest::fatal &e)
+ catch (const libtest::fatal& e)
{
if (libtest::fatal::is_disabled())
{
@@ -133,7 +133,7 @@ test_return_t Collection::exec()
}
libtest::cancel_alarm();
}
- catch (libtest::fatal &e)
+ catch (const libtest::fatal& e)
{
stream::cerr(e.file(), e.line(), e.func()) << e.what();
_failed++;
@@ -159,7 +159,7 @@ test_return_t Collection::exec()
break;
default:
- fatal_message("invalid return code");
+ FATAL("invalid return code");
}
#if 0
@TODO add code here to allow for a collection to define a method to reset to allow tests to continue.
diff --git a/libtest/collection.h b/libtest/collection.h
index bc879e30..a9f9cba8 100644
--- a/libtest/collection.h
+++ b/libtest/collection.h
@@ -103,6 +103,10 @@ private:
uint32_t _total;
libtest::Timer _timer;
libtest::Formatter _formatter;
+
+private:
+ Collection( const Collection& );
+ const Collection& operator=( const Collection& );
};
} // namespace libtest
diff --git a/libtest/comparison.hpp b/libtest/comparison.hpp
index 1cd55d52..38299484 100644
--- a/libtest/comparison.hpp
+++ b/libtest/comparison.hpp
@@ -95,7 +95,7 @@ bool _compare_strcmp(const char *file, int line, const char *func, const T1_comp
{
if (__expected == NULL)
{
- fatal_message("Expected value was NULL, programmer error");
+ FATAL("Expected value was NULL, programmer error");
}
if (__actual == NULL)
diff --git a/libtest/dns.cc b/libtest/dns.cc
index 3623c4a1..0becfc99 100644
--- a/libtest/dns.cc
+++ b/libtest/dns.cc
@@ -45,16 +45,28 @@ namespace libtest {
bool lookup(const char* host)
{
- assert(host);
bool success= false;
- struct addrinfo *addrinfo= NULL;
-
- int limit= 5;
- while (limit--)
+ if (host)
{
- int ret;
- if ((ret= getaddrinfo(host, NULL, NULL, &(addrinfo))))
+ assert(host);
+ struct addrinfo *addrinfo= NULL;
+
+ int limit= 5;
+ while (--limit and success == false)
{
+ if (addrinfo)
+ {
+ freeaddrinfo(addrinfo);
+ addrinfo= NULL;
+ }
+
+ int ret;
+ if ((ret= getaddrinfo(host, NULL, NULL, &addrinfo)) == 0)
+ {
+ success= true;
+ break;
+ }
+
switch (ret)
{
case EAI_AGAIN:
@@ -64,16 +76,16 @@ bool lookup(const char* host)
default:
break;
}
+
+ break;
}
- else
+
+ if (addrinfo)
{
- success= true;
- break;
+ freeaddrinfo(addrinfo);
}
}
- freeaddrinfo(addrinfo);
-
return success;
}
@@ -87,7 +99,7 @@ bool check_dns()
if (lookup("does_not_exist.gearman.info")) // This should fail, if it passes,...
{
- return false;
+ fatal_assert("Your service provider sucks and is providing bogus DNS. You might be in an airport.");
}
return true;
diff --git a/libtest/drizzled.cc b/libtest/drizzled.cc
index 16933c4b..b8068ac8 100644
--- a/libtest/drizzled.cc
+++ b/libtest/drizzled.cc
@@ -62,7 +62,7 @@ using namespace libtest;
#endif
#if defined(HAVE_LIBDRIZZLE) && HAVE_LIBDRIZZLE
-#include <libdrizzle-1.0/drizzle_client.h>
+# include <libdrizzle-5.1/drizzle_client.h>
#endif
using namespace libtest;
@@ -72,31 +72,25 @@ bool ping_drizzled(const in_port_t _port)
{
(void)(_port);
#if defined(HAVE_LIBDRIZZLE) && HAVE_LIBDRIZZLE
+ if (HAVE_LIBDRIZZLE)
{
- drizzle_st *drizzle= drizzle_create(NULL);
+ drizzle_st *drizzle= drizzle_create_tcp(getenv("MYSQL_SERVER"),
+ getenv("MYSQL_PORT") ? atoi("MYSQL_PORT") : DRIZZLE_DEFAULT_TCP_PORT,
+ getenv("MYSQL_USER"),
+ getenv("MYSQL_PASSWORD"),
+ getenv("MYSQL_SCHEMA"), drizzle_options_t());
if (drizzle == NULL)
{
return false;
}
- drizzle_con_st *con;
-
- if ((con= drizzle_con_create(drizzle, NULL)) == NULL)
- {
- drizzle_free(drizzle);
- return false;
- }
-
- drizzle_con_set_tcp(con, "localhost", _port);
- drizzle_con_set_auth(con, "root", 0);
-
bool success= false;
drizzle_return_t rc;
- if ((rc= drizzle_con_connect(con)) == DRIZZLE_RETURN_OK)
+ if ((rc= drizzle_connect(drizzle)) == DRIZZLE_RETURN_OK)
{
- drizzle_result_st *result= drizzle_ping(con, NULL, &rc);
+ drizzle_result_st *result= drizzle_ping(drizzle, &rc);
success= bool(result);
drizzle_result_free(result);
}
@@ -108,8 +102,7 @@ bool ping_drizzled(const in_port_t _port)
Error << drizzle_error(drizzle) << " localhost:" << _port;
}
- drizzle_con_free(con);
- drizzle_free(drizzle);
+ drizzle_quit(drizzle);
return success;
}
@@ -189,10 +182,10 @@ public:
}
}
- bool build(size_t argc, const char *argv[]);
+ bool build();
};
-bool Drizzle::build(size_t argc, const char *argv[])
+bool Drizzle::build()
{
if (getuid() == 0 or geteuid() == 0)
{
@@ -204,16 +197,6 @@ bool Drizzle::build(size_t argc, const char *argv[])
add_option("--datadir=var/drizzle");
#endif
- for (size_t x= 0 ; x < argc ; x++)
- {
- if (argv[x] == NULL)
- {
- break;
- }
-
- add_option(argv[x]);
- }
-
return true;
}
diff --git a/libtest/fatal.cc b/libtest/fatal.cc
index 99b15535..0ed06c2c 100644
--- a/libtest/fatal.cc
+++ b/libtest/fatal.cc
@@ -43,72 +43,45 @@ namespace libtest {
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
fatal::fatal(const char *file_arg, int line_arg, const char *func_arg, ...) :
- __test_result(file_arg, line_arg, func_arg),
- _error_message(NULL),
- _error_message_size(0)
+ __test_result(file_arg, line_arg, func_arg)
{
va_list args;
va_start(args, func_arg);
- const char *format= va_arg(args, const char *);
- _error_message_size= vasprintf(&_error_message, format, args);
- assert(_error_message_size != -1);
- if (_error_message_size > 0)
- {
- _error_message_size++;
- }
+ init(args);
va_end(args);
}
fatal::fatal( const fatal& other ) :
- __test_result(other),
- _error_message_size(other._error_message_size)
-{
- _error_message= (char*) malloc(_error_message_size);
- if (_error_message)
- {
- memcpy(_error_message, other._error_message, _error_message_size);
- }
- else
- {
- _error_message_size= -1;
- }
-}
-
-fatal::~fatal() throw()
+ __test_result(other)
{
- if ((_error_message_size > 0) and _error_message)
- {
- free(_error_message);
- _error_message= NULL;
- }
}
static bool _disabled= false;
static uint32_t _counter= 0;
-bool fatal::is_disabled()
+bool fatal::is_disabled() throw()
{
return _disabled;
}
-void fatal::disable()
+void fatal::disable() throw()
{
_counter= 0;
_disabled= true;
}
-void fatal::enable()
+void fatal::enable() throw()
{
_counter= 0;
_disabled= false;
}
-uint32_t fatal::disabled_counter()
+uint32_t fatal::disabled_counter() throw()
{
return _counter;
}
-void fatal::increment_disabled_counter()
+void fatal::increment_disabled_counter() throw()
{
_counter++;
}
@@ -132,4 +105,15 @@ disconnected::disconnected(const char *file_arg, int line_arg, const char *func_
snprintf(_error_message, sizeof(_error_message), "%s:%u %s", instance.c_str(), uint32_t(port), last_error);
}
+disconnected::disconnected(const disconnected& other):
+ std::runtime_error(other._func),
+ _port(other._port),
+ _line(other._line),
+ _file(other._file),
+ _func(other._func)
+{
+ strncpy(_error_message, other._error_message, BUFSIZ);
+ strncpy(_instance, other._instance, BUFSIZ);
+}
+
} // namespace libtest
diff --git a/libtest/fatal.hpp b/libtest/fatal.hpp
index 7e627a46..c679f9b0 100644
--- a/libtest/fatal.hpp
+++ b/libtest/fatal.hpp
@@ -40,34 +40,36 @@
namespace libtest {
-class disconnected : std::runtime_error
+class disconnected : public std::runtime_error
{
public:
disconnected(const char *file, int line, const char *func, const std::string&, const in_port_t port, ...);
const char* what() const throw()
{
- return &_error_message[0];
+ return _error_message;
}
+ disconnected(const disconnected&);
+
// The following are just for unittesting the exception class
static bool is_disabled();
static void disable();
-
+ static void enable();
static uint32_t disabled_counter();
static void increment_disabled_counter();
- int line()
+ int line() const
{
return _line;
}
- const char* file()
+ const char* file() const
{
return _file;
}
- const char* func()
+ const char* func() const
{
return _func;
}
@@ -75,7 +77,7 @@ public:
private:
char _error_message[BUFSIZ];
in_port_t _port;
- char _instance[1024];
+ char _instance[BUFSIZ];
int _line;
const char* _file;
const char* _func;
diff --git a/libtest/framework.cc b/libtest/framework.cc
index 546ccb37..30f511af 100644
--- a/libtest/framework.cc
+++ b/libtest/framework.cc
@@ -133,12 +133,12 @@ void Framework::exec()
break;
}
}
- catch (libtest::fatal& e)
+ catch (const libtest::fatal& e)
{
_failed++;
stream::cerr(e.file(), e.line(), e.func()) << e.what();
}
- catch (libtest::disconnected& e)
+ catch (const libtest::disconnected& e)
{
_failed++;
Error << "Unhandled disconnection occurred:" << e.what();
diff --git a/libtest/framework.h b/libtest/framework.h
index f6dfc94a..7a24466a 100644
--- a/libtest/framework.h
+++ b/libtest/framework.h
@@ -162,8 +162,6 @@ public:
}
private:
- Framework& operator=(const Framework&);
-
uint32_t _total;
uint32_t _success;
uint32_t _skipped;
@@ -193,6 +191,10 @@ private:
std::string _only_run;
std::string _wildcard;
std::string _name;
+
+private:
+ Framework( const Framework& );
+ const Framework& operator=( const Framework& );
};
} // namespace libtest
diff --git a/libtest/gearmand.cc b/libtest/gearmand.cc
index d9dcf192..852cf194 100644
--- a/libtest/gearmand.cc
+++ b/libtest/gearmand.cc
@@ -123,7 +123,7 @@ public:
return true;
}
- bool build(size_t argc, const char *argv[]);
+ bool build();
};
Gearmand::Gearmand(const std::string& host_arg, in_port_t port_arg, bool libtool_, const char* binary_arg) :
@@ -132,7 +132,7 @@ Gearmand::Gearmand(const std::string& host_arg, in_port_t port_arg, bool libtool
set_pid_file();
}
-bool Gearmand::build(size_t argc, const char *argv[])
+bool Gearmand::build()
{
if (getuid() == 0 or geteuid() == 0)
{
@@ -141,16 +141,6 @@ bool Gearmand::build(size_t argc, const char *argv[])
add_option("--listen=localhost");
- for (size_t x= 0 ; x < argc ; x++)
- {
- if (argv[x] == NULL)
- {
- break;
- }
-
- add_option(argv[x]);
- }
-
return true;
}
diff --git a/libtest/http.cc b/libtest/http.cc
index 917e668f..621c714c 100644
--- a/libtest/http.cc
+++ b/libtest/http.cc
@@ -57,13 +57,13 @@ static void initialize_curl_startup()
#if defined(HAVE_LIBCURL) && HAVE_LIBCURL
if (curl_global_init(CURL_GLOBAL_ALL))
{
- fatal_message("curl_global_init(CURL_GLOBAL_ALL) failed");
+ FATAL("curl_global_init(CURL_GLOBAL_ALL) failed");
}
#endif
if (atexit(cleanup_curl))
{
- fatal_message("atexit() failed");
+ FATAL("atexit() failed");
}
}
@@ -73,7 +73,7 @@ static void initialize_curl(void)
int ret;
if ((ret= pthread_once(&start_key_once, initialize_curl_startup)) != 0)
{
- fatal_message(strerror(ret));
+ FATAL(strerror(ret));
}
}
diff --git a/libtest/include.am b/libtest/include.am
index 90641783..d1ede13b 100644
--- a/libtest/include.am
+++ b/libtest/include.am
@@ -13,6 +13,7 @@ MASSIF_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=massif
GDB_COMMAND= $(LIBTOOL_COMMAND) gdb -f -x libtest/run.gdb
PTRCHECK_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=exp-ptrcheck --error-exitcode=1
PAHOLE_COMMAND= $(LIBTOOL_COMMAND) --mode=execute pahole
+VALGRIND_SUPRESSION= $(LIBTOOL_COMMAND) valgrind --leak-check=full --show-reachable=yes --error-limit=no --gen-suppressions=all --log-file=minimalraw.log
export LIBTOOL_COMMAND
export VALGRIND_COMMAND
@@ -23,6 +24,9 @@ export GDB_COMMAND
valgrind:
@echo make check TESTS_ENVIRONMENT="\"$(VALGRIND_EXEC_COMMAND)\""
+valgrind-supressions:
+ @echo make check TESTS_ENVIRONMENT="\"$(VALGRIND_SUPRESSION)\""
+
gdb:
@echo make check TESTS_ENVIRONMENT="\"$(GDB_COMMAND)\""
@@ -104,6 +108,12 @@ libtest_libtest_la_CXXFLAGS=
EXTRA_libtest_libtest_la_DEPENDENCIES=
libtest_libtest_la_LIBADD=
libtest_libtest_la_SOURCES=
+if BUILDING_LIBMEMCACHED
+libtest_libtest_la_LIBADD+= libmemcached/libmemcached.la
+else
+libtest_libtest_la_CXXFLAGS+= @LIBMEMCACHED_CFLAGS@
+libtest_libtest_la_LIBADD+= @LIBMEMCACHED_LIB@
+endif
libtest_libtest_la_SOURCES+= libtest/alarm.cc
libtest_libtest_la_SOURCES+= libtest/binaries.cc
@@ -147,22 +157,19 @@ libtest_libtest_la_LIBADD+= $(CURL_LIBS)
libtest_libtest_la_LIBADD+= @RT_LIB@
EXTRA_libtest_libtest_la_DEPENDENCIES+= libtest_tmp_dir
-EXTRA_libtest_libtest_la_DEPENDENCIES+=libtest/abort
-EXTRA_libtest_libtest_la_DEPENDENCIES+=libtest/wait
+EXTRA_libtest_libtest_la_DEPENDENCIES+= libtest/abort
+EXTRA_libtest_libtest_la_DEPENDENCIES+= libtest/wait
# Declare unittest so that we can append to it
libtest_unittest_CXXFLAGS=
libtest_unittest_LDADD=
+libtest_libtest_la_LDFLAGS=
# We are either building in tree, or with
libtest_libtest_la_SOURCES+= libtest/memcached.cc
-if HAVE_LIBDRIZZLE
-
-libtest_libtest_la_LIBADD+= $(libdrizzle_LIBS)
-libtest_libtest_la_CXXFLAGS+= $(libdrizzle_CFLAGS)
-
-endif
+libtest_libtest_la_LDFLAGS+= @LIBDRIZZLE_LDFLAGS@
+libtest_libtest_la_LIBADD+= @LIBDRIZZLE_LIB@
libtest_libtest_la_SOURCES+= libtest/gearmand.cc
diff --git a/libtest/killpid.cc b/libtest/killpid.cc
index 7f5630ba..2cefff2c 100644
--- a/libtest/killpid.cc
+++ b/libtest/killpid.cc
@@ -86,7 +86,7 @@ bool kill_pid(pid_t pid_arg)
uint32_t waited;
uint32_t retry;
- for (waited= 0, retry= 4; ; retry++, waited+= this_wait)
+ for (waited= 0, retry= 1; ; retry++, waited+= this_wait)
{
int status= 0;
if (waitpid(pid_arg, &status, WNOHANG) == 0)
diff --git a/libtest/main.cc b/libtest/main.cc
index 588512d1..fe8938b9 100644
--- a/libtest/main.cc
+++ b/libtest/main.cc
@@ -299,7 +299,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
}
- catch (libtest::__skipped e)
+ catch (const libtest::__skipped& e)
{
return EXIT_SKIP;
}
@@ -345,26 +345,26 @@ int main(int argc, char *argv[])
Outn(); // Generate a blank to break up the messages if make check/test has been run
} while (exit_code == EXIT_SUCCESS and --opt_repeat);
}
- catch (libtest::__skipped e)
+ catch (const libtest::__skipped& e)
{
return EXIT_SKIP;
}
- catch (libtest::__failure e)
+ catch (const libtest::__failure& e)
{
libtest::stream::make_cout(e.file(), e.line(), e.func()) << e.what();
exit_code= EXIT_FAILURE;
}
- catch (libtest::fatal& e)
+ catch (const libtest::fatal& e)
{
std::cerr << "FATAL:" << e.what() << std::endl;
exit_code= EXIT_FAILURE;
}
- catch (libtest::disconnected& e)
+ catch (const libtest::disconnected& e)
{
std::cerr << "Unhandled disconnection occurred:" << e.what() << std::endl;
exit_code= EXIT_FAILURE;
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
std::cerr << "std::exception:" << e.what() << std::endl;
exit_code= EXIT_FAILURE;
diff --git a/libtest/memcached.cc b/libtest/memcached.cc
index 408e129f..0d6cc92a 100644
--- a/libtest/memcached.cc
+++ b/libtest/memcached.cc
@@ -191,13 +191,13 @@ public:
return true;
}
- bool build(size_t argc, const char *argv[]);
+ bool build();
};
#include <sstream>
-bool Memcached::build(size_t argc, const char *argv[])
+bool Memcached::build()
{
if (getuid() == 0 or geteuid() == 0)
{
@@ -205,7 +205,8 @@ bool Memcached::build(size_t argc, const char *argv[])
}
add_option("-l", "localhost");
-#ifndef TARGET_OS_OSX
+#ifdef __APPLE__
+#else
add_option("-m", "128");
add_option("-M");
#endif
@@ -215,16 +216,6 @@ bool Memcached::build(size_t argc, const char *argv[])
add_option(sasl());
}
- for (size_t x= 0 ; x < argc ; x++)
- {
- if (argv[x] == NULL)
- {
- break;
- }
-
- add_option(argv[x]);
- }
-
return true;
}
diff --git a/libtest/port.cc b/libtest/port.cc
index 1d3f4e5f..d8e8c12d 100644
--- a/libtest/port.cc
+++ b/libtest/port.cc
@@ -204,22 +204,22 @@ in_port_t get_free_port()
// We handle the case where if we max out retries, we still abort.
if (retries == 0)
{
- fatal_message("No port could be found, exhausted retry");
+ FATAL("No port could be found, exhausted retry");
}
if (ret_port == 0)
{
- fatal_message("No port could be found");
+ FATAL("No port could be found");
}
if (ret_port == default_port)
{
- fatal_message("No port could be found");
+ FATAL("No port could be found");
}
if (ret_port <= 1024)
{
- fatal_message("No port could be found, though some where available below or at 1024");
+ FATAL("No port could be found, though some where available below or at 1024");
}
all_socket_fd.last_port= ret_port;
diff --git a/libtest/result.cc b/libtest/result.cc
index ae37e8d2..9a1c8fba 100644
--- a/libtest/result.cc
+++ b/libtest/result.cc
@@ -2,7 +2,7 @@
*
* Data Differential YATL (i.e. libtest) library
*
- * Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -38,104 +38,87 @@
#include <libtest/common.h>
#include <cstdarg>
-#ifndef __INTEL_COMPILER
-# pragma GCC diagnostic ignored "-Wformat-nonliteral"
-#endif
-
namespace libtest {
__test_result::__test_result(const char *file_arg, int line_arg, const char *func_arg):
_line(line_arg),
_file(file_arg),
- _func(func_arg)
-{
-}
-
-__success::__success(const char *file_arg, int line_arg, const char *func_arg):
- __test_result(file_arg, line_arg, func_arg)
+ _func(func_arg),
+ _error_message(NULL),
+ _error_message_size(0)
{
}
-__skipped::__skipped(const char *file_arg, int line_arg, const char *func_arg, ...):
- __test_result(file_arg, line_arg, func_arg),
- _error_message(NULL),
- _error_message_size(0)
+#ifndef __INTEL_COMPILER
+# pragma GCC diagnostic ignored "-Wformat-nonliteral"
+#endif
+void __test_result::init(va_list args_)
{
- va_list args;
- va_start(args, func_arg);
- const char *format= va_arg(args, const char *);
- _error_message_size= vasprintf(&_error_message, format, args);
+ const char *format= va_arg(args_, const char *);
+ _error_message_size= vasprintf(&_error_message, format, args_);
assert(_error_message_size != -1);
if (_error_message_size > 0)
{
_error_message_size++;
}
- va_end(args);
}
-__skipped::__skipped( const __skipped& other ) :
- __test_result(other),
+__test_result::~__test_result() throw()
+{
+ free(_error_message);
+}
+
+__test_result::__test_result(const __test_result& other) :
+ _line(other._line),
+ _file(other._file),
+ _func(other._func),
_error_message_size(other._error_message_size)
{
- _error_message= (char*) malloc(_error_message_size);
- if (_error_message)
- {
- memcpy(_error_message, other._error_message, _error_message_size);
- }
- else
+ if (_error_message_size > 0)
{
- _error_message_size= -1;
+ _error_message= (char*) malloc(_error_message_size);
+ if (_error_message)
+ {
+ memcpy(_error_message, other._error_message, _error_message_size);
+ }
+ else
+ {
+ _error_message_size= -1;
+ }
}
}
-__skipped::~__skipped() throw()
+__success::__success(const char *file_arg, int line_arg, const char *func_arg):
+ __test_result(file_arg, line_arg, func_arg)
{
- if ((_error_message_size > 0) and _error_message)
- {
- free(_error_message);
- _error_message= NULL;
- }
}
-__failure::__failure(const char *file_arg, int line_arg, const char *func_arg, ...) :
- __test_result(file_arg, line_arg, func_arg),
- _error_message(NULL),
- _error_message_size(0)
+__skipped::__skipped(const char *file_arg, int line_arg, const char *func_arg, ...):
+ __test_result(file_arg, line_arg, func_arg)
{
va_list args;
va_start(args, func_arg);
- const char *format= va_arg(args, const char *);
- _error_message_size= vasprintf(&_error_message, format, args);
- assert(_error_message_size != -1);
- if (_error_message_size > 0)
- {
- _error_message_size++;
- }
+ init(args);
va_end(args);
}
-__failure::__failure( const __failure& other ) :
- __test_result(other),
- _error_message_size(other._error_message_size)
+__skipped::__skipped(const __skipped& other) :
+ __test_result(other)
{
- _error_message= (char*) malloc(_error_message_size);
- if (_error_message)
- {
- memcpy(_error_message, other._error_message, _error_message_size);
- }
- else
- {
- _error_message_size= -1;
- }
}
-__failure::~__failure() throw()
+__failure::__failure(const char *file_arg, int line_arg, const char *func_arg, ...) :
+ __test_result(file_arg, line_arg, func_arg)
+{
+ va_list args;
+ va_start(args, func_arg);
+ init(args);
+ va_end(args);
+}
+
+__failure::__failure(const __failure& other) :
+ __test_result(other)
{
- if ((_error_message_size > 0) and _error_message)
- {
- free(_error_message);
- _error_message= NULL;
- }
}
diff --git a/libtest/result.hpp b/libtest/result.hpp
index a5592640..0c78b998 100644
--- a/libtest/result.hpp
+++ b/libtest/result.hpp
@@ -57,10 +57,26 @@ do \
throw libtest::__failure(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \
} while (0)
-#define fatal_message(...) \
+#define FATAL(...) \
do \
{ \
throw libtest::fatal(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \
} while (0)
+#define FATAL_IF(__expression, ...) \
+do \
+{ \
+ if ((__expression)) { \
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, (#__expression)); \
+ } \
+} while (0)
+
+#define FATAL_IF_(__expression, ...) \
+do \
+{ \
+ if ((__expression)) { \
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \
+ } \
+} while (0)
+
#define fatal_assert(__assert) if((__assert)) {} else { throw libtest::fatal(LIBYATL_DEFAULT_PARAM, #__assert); }
diff --git a/libtest/result/base.hpp b/libtest/result/base.hpp
index 1859c22a..51ee995d 100644
--- a/libtest/result/base.hpp
+++ b/libtest/result/base.hpp
@@ -2,7 +2,7 @@
*
* Data Differential YATL (i.e. libtest) library
*
- * Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -43,32 +43,44 @@ class __test_result : public std::exception
public:
__test_result(const char *file, int line, const char *func);
- __test_result( const __test_result& other ) :
- _line(other._line),
- _file(other._file),
- _func(other._func)
+ __test_result( const __test_result& );
+
+ virtual ~__test_result() throw();
+
+ virtual const char* what() const throw()
{
+ if (_error_message)
+ {
+ return _error_message;
+ }
+
+ return "";
}
- int line()
+ int line() const
{
return _line;
}
- const char* file()
+ const char* file() const
{
return _file;
}
- const char* func()
+ const char* func() const
{
return _func;
}
+protected:
+ void init(va_list);
+
private:
int _line;
const char* _file;
const char* _func;
+ char* _error_message;
+ int _error_message_size;
};
} // namespace libtest
diff --git a/libtest/result/fail.hpp b/libtest/result/fail.hpp
index dae4a08b..fd8766a9 100644
--- a/libtest/result/fail.hpp
+++ b/libtest/result/fail.hpp
@@ -43,19 +43,9 @@ class __failure : public __test_result
public:
__failure(const char *file, int line, const char *func, ...);
- __failure(const __failure& other);
-
- ~__failure() throw();
-
- const char* what() const throw()
- {
- return _error_message;
- }
+ __failure(const __failure&);
private:
- char* _error_message;
- int _error_message_size;
};
} // namespace libtest
-
diff --git a/libtest/result/fatal.hpp b/libtest/result/fatal.hpp
index deebb358..8e6d1346 100644
--- a/libtest/result/fatal.hpp
+++ b/libtest/result/fatal.hpp
@@ -45,23 +45,14 @@ public:
fatal(const fatal&);
- ~fatal() throw();
-
- const char* what() const throw()
- {
- return &_error_message[0];
- }
-
// The following are just for unittesting the exception class
- static bool is_disabled();
- static void disable();
- static void enable();
- static uint32_t disabled_counter();
- static void increment_disabled_counter();
+ static bool is_disabled() throw();
+ static void disable() throw();
+ static void enable() throw();
+ static uint32_t disabled_counter() throw();
+ static void increment_disabled_counter() throw();
private:
- char* _error_message;
- int _error_message_size;
};
} // namespace libtest
diff --git a/libtest/result/skip.hpp b/libtest/result/skip.hpp
index 663044fe..d0226e9f 100644
--- a/libtest/result/skip.hpp
+++ b/libtest/result/skip.hpp
@@ -44,17 +44,6 @@ public:
__skipped(const char *file, int line, const char *func, ...);
__skipped(const __skipped&);
-
- ~__skipped() throw();
-
- const char* what() const throw()
- {
- return &_error_message[0];
- }
-
-private:
- char* _error_message;
- int _error_message_size;
};
} // namespace libtest
diff --git a/libtest/runner.cc b/libtest/runner.cc
index fdabb7c6..2f94ad37 100644
--- a/libtest/runner.cc
+++ b/libtest/runner.cc
@@ -50,24 +50,24 @@ test_return_t Runner::main(test_callback_fn* func, void *object)
try {
ret= run(func, object);
}
- catch (libtest::__skipped e)
+ catch (const libtest::__skipped& e)
{
ret= TEST_SKIPPED;
}
- catch (libtest::__failure e)
+ catch (const libtest::__failure& e)
{
libtest::stream::make_cerr(e.file(), e.line(), e.func()) << e.what();
ret= TEST_FAILURE;
}
- catch (libtest::__success)
+ catch (const libtest::__success&)
{
ret= TEST_SUCCESS;
}
- catch (libtest::fatal& e)
+ catch (const libtest::fatal&)
{
throw;
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what();
throw;
@@ -87,24 +87,24 @@ test_return_t Runner::setup(test_callback_fn* func, void *object)
try {
ret= pre(func, object);
}
- catch (libtest::__skipped e)
+ catch (const libtest::__skipped& e)
{
ret= TEST_SKIPPED;
}
- catch (libtest::__failure e)
+ catch (const libtest::__failure& e)
{
libtest::stream::make_cout(e.file(), e.line(), e.func()) << e.what();
ret= TEST_FAILURE;
}
- catch (libtest::__success)
+ catch (const libtest::__success&)
{
ret= TEST_SUCCESS;
}
- catch (libtest::fatal& e)
+ catch (const libtest::fatal& e)
{
throw;
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what();
throw;
@@ -124,24 +124,24 @@ test_return_t Runner::teardown(test_callback_fn* func, void *object)
try {
ret= post(func, object);
}
- catch (libtest::__skipped e)
+ catch (const libtest::__skipped& e)
{
ret= TEST_SKIPPED;
}
- catch (libtest::__failure e)
+ catch (const libtest::__failure& e)
{
libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what();
ret= TEST_FAILURE;
}
- catch (libtest::__success)
+ catch (const libtest::__success&)
{
ret= TEST_SUCCESS;
}
- catch (libtest::fatal& e)
+ catch (const libtest::fatal& e)
{
throw;
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what();
throw;
diff --git a/libtest/runner.h b/libtest/runner.h
index d90b70e4..627a0a8e 100644
--- a/libtest/runner.h
+++ b/libtest/runner.h
@@ -64,6 +64,10 @@ public:
private:
libtest::server_startup_st* _servers;
+
+private:
+ Runner( const Runner& );
+ const Runner& operator=( const Runner& );
};
} // namespace Runner
diff --git a/libtest/server.cc b/libtest/server.cc
index 522120be..d024d054 100644
--- a/libtest/server.cc
+++ b/libtest/server.cc
@@ -124,7 +124,7 @@ Server::Server(const std::string& host_arg, const in_port_t port_arg,
Server::~Server()
{
- murder();
+ kill();
}
bool Server::check()
@@ -148,7 +148,7 @@ bool Server::cycle()
while (--limit and
is_pid_valid(_app.pid()))
{
- if (murder())
+ if (kill())
{
Log << "Killed existing server," << *this;
dream(0, 50000);
@@ -173,6 +173,22 @@ bool Server::wait_for_pidfile() const
return wait.successful();
}
+bool Server::init(const char *argv[])
+{
+ if (argv)
+ {
+ for (const char **ptr= argv; *ptr ; ++ptr)
+ {
+ if (ptr)
+ {
+ add_option(*ptr);
+ }
+ }
+ }
+
+ return build();
+}
+
bool Server::has_pid() const
{
return (_app.pid() > 1);
@@ -498,7 +514,7 @@ bool Server::args(Application& app)
return true;
}
-bool Server::murder()
+bool Server::kill()
{
if (check_pid(_app.pid())) // If we kill it, reset
{
diff --git a/libtest/server.h b/libtest/server.h
index 5b26fcdd..bbebe957 100644
--- a/libtest/server.h
+++ b/libtest/server.h
@@ -41,10 +41,8 @@
#include <cassert>
#include <cstdio>
#include <cstring>
-
#include <netdb.h>
#include <netinet/in.h>
-
#include <string>
#include <unistd.h>
#include <vector>
@@ -179,7 +177,8 @@ public:
virtual bool ping()= 0;
- virtual bool build(size_t argc, const char *argv[])= 0;
+ bool init(const char *argv[]);
+ virtual bool build()= 0;
void add_option(const std::string&);
void add_option(const std::string&, const std::string&);
@@ -251,7 +250,7 @@ public:
std::string log_and_pid();
- bool murder();
+ bool kill();
bool start();
bool command(libtest::Application& app);
diff --git a/libtest/server_container.cc b/libtest/server_container.cc
index cc1e0a56..3a5a7a0e 100644
--- a/libtest/server_container.cc
+++ b/libtest/server_container.cc
@@ -103,7 +103,7 @@ bool server_startup_st::shutdown(uint32_t host_to_shutdown)
{
Server* tmp= servers[host_to_shutdown];
- if (tmp and tmp->murder() == false)
+ if (tmp and tmp->kill() == false)
{ }
else
{
@@ -139,7 +139,7 @@ bool server_startup_st::shutdown()
bool success= true;
for (std::vector<Server *>::iterator iter= servers.begin(); iter != servers.end(); ++iter)
{
- if ((*iter)->has_pid() and (*iter)->murder() == false)
+ if ((*iter)->has_pid() and (*iter)->kill() == false)
{
Error << "Unable to kill:" << *(*iter);
success= false;
@@ -176,9 +176,9 @@ bool server_startup_st::validate()
return _magic == MAGIC_MEMORY;
}
-bool server_startup(server_startup_st& construct, const std::string& server_type, in_port_t try_port, int argc, const char *argv[], const bool opt_startup_message)
+bool server_startup(server_startup_st& construct, const std::string& server_type, in_port_t try_port, const char *argv[])
{
- return construct.start_server(server_type, try_port, argc, argv, opt_startup_message);
+ return construct.start_server(server_type, try_port, argv);
}
libtest::Server* server_startup_st::create(const std::string& server_type, in_port_t try_port, const bool is_socket)
@@ -288,8 +288,7 @@ private:
bool server_startup_st::_start_server(const bool is_socket,
const std::string& server_type,
in_port_t try_port,
- int argc, const char *argv[],
- const bool opt_startup_message)
+ const char *argv[])
{
try {
ServerPtr server(create(server_type, try_port, is_socket));
@@ -309,7 +308,7 @@ bool server_startup_st::_start_server(const bool is_socket,
return false;
}
- server->build(argc, argv);
+ server->init(argv);
#if 0
if (false)
@@ -327,7 +326,6 @@ bool server_startup_st::_start_server(const bool is_socket,
}
else
{
- if (opt_startup_message)
{
#if defined(DEBUG)
if (DEBUG)
@@ -347,7 +345,7 @@ bool server_startup_st::_start_server(const bool is_socket,
set_default_socket(server->socket().c_str());
}
}
- catch (libtest::disconnected& err)
+ catch (const libtest::disconnected& err)
{
if (fatal::is_disabled() == false and try_port != LIBTEST_FAIL_PORT)
{
@@ -355,12 +353,12 @@ bool server_startup_st::_start_server(const bool is_socket,
return false;
}
}
- catch (libtest::__test_result& err)
+ catch (const libtest::__test_result& err)
{
stream::cerr(err.file(), err.line(), err.func()) << err.what();
return false;
}
- catch (std::exception& err)
+ catch (const std::exception& err)
{
Error << err.what();
return false;
@@ -374,18 +372,14 @@ bool server_startup_st::_start_server(const bool is_socket,
return true;
}
-bool server_startup_st::start_server(const std::string& server_type, in_port_t try_port,
- int argc, const char *argv[],
- const bool opt_startup_message)
+bool server_startup_st::start_server(const std::string& server_type, in_port_t try_port, const char *argv[])
{
- return _start_server(false, server_type, try_port, argc, argv, opt_startup_message);
+ return _start_server(false, server_type, try_port, argv);
}
-bool server_startup_st::start_socket_server(const std::string& server_type, const in_port_t try_port,
- int argc, const char *argv[],
- const bool opt_startup_message)
+bool server_startup_st::start_socket_server(const std::string& server_type, const in_port_t try_port, const char *argv[])
{
- return _start_server(true, server_type, try_port, argc, argv, opt_startup_message);
+ return _start_server(true, server_type, try_port, argv);
}
std::string server_startup_st::option_string() const
diff --git a/libtest/server_container.h b/libtest/server_container.h
index 48d90901..88e4763d 100644
--- a/libtest/server_container.h
+++ b/libtest/server_container.h
@@ -39,10 +39,8 @@
#include <cassert>
#include <cstdio>
#include <cstring>
-
#include <netdb.h>
#include <netinet/in.h>
-
#include <string>
#include <unistd.h>
#include <vector>
@@ -69,8 +67,8 @@ public:
bool validate();
- bool start_socket_server(const std::string& server_type, const in_port_t try_port, int argc, const char *argv[], const bool opt_startup_message= true);
- bool start_server(const std::string& server_type, const in_port_t try_port, int argc, const char *argv[], const bool opt_startup_message= true);
+ bool start_socket_server(const std::string& server_type, const in_port_t try_port, const char *argv[]);
+ bool start_server(const std::string& server_type, const in_port_t try_port, const char *argv[]);
uint32_t count() const
{
@@ -142,13 +140,12 @@ private:
bool _start_server(const bool is_socket,
const std::string& server_type,
const in_port_t try_port,
- int argc, const char *argv[],
- const bool opt_startup_message);
+ const char *argv[]);
private:
unsigned long int _servers_to_run;
};
-bool server_startup(server_startup_st&, const std::string&, in_port_t try_port, int argc, const char *argv[], const bool opt_startup_message= true);
+bool server_startup(server_startup_st&, const std::string&, in_port_t try_port, const char *argv[]);
} // namespace libtest
diff --git a/libtest/signal.cc b/libtest/signal.cc
index 165915f5..51f42a4e 100644
--- a/libtest/signal.cc
+++ b/libtest/signal.cc
@@ -209,11 +209,6 @@ SignalThread::SignalThread() :
sigaddset(&set, SIGINT);
sigaddset(&set, SIGVTALRM);
}
- else
- {
- Out << "Inside of GDB, disabling signal handlers";
- }
-
sigaddset(&set, SIGPIPE);
sigaddset(&set, SIGUSR2);
diff --git a/libtest/stream.h b/libtest/stream.h
index dea371b9..081c2bf0 100644
--- a/libtest/stream.h
+++ b/libtest/stream.h
@@ -130,7 +130,7 @@ template<template <class Ch, class Tr, class A> class OutputPolicy, class Ch = c
_func(func)
{ }
- ~log()
+ virtual ~log()
{
output_policy()(arg, _out, _filename, _line_number, _func);
}
@@ -145,6 +145,10 @@ template<template <class Ch, class Tr, class A> class OutputPolicy, class Ch = c
private:
typename output_policy::stream_buffer arg;
+
+ private:
+ log( const log& );
+ const log& operator=( const log& );
};
} // namespace detail
@@ -154,6 +158,9 @@ public:
detail::log<detail::channelln>(std::cerr, filename, line_number, func)
{ }
+private:
+ make_cerr( const make_cerr& );
+ const make_cerr& operator=( const make_cerr& );
};
class cerr : public detail::log<detail::channel> {
@@ -162,6 +169,9 @@ public:
detail::log<detail::channel>(std::cout, filename, line_number, func)
{ }
+private:
+ cerr( const cerr& );
+ const cerr& operator=( const cerr& );
};
class clog : public detail::log<detail::channel> {
@@ -169,6 +179,10 @@ public:
clog(const char* filename, int line_number, const char* func) :
detail::log<detail::channel>(std::clog, filename, line_number, func)
{ }
+
+private:
+ clog( const clog& );
+ const clog& operator=( const clog& );
};
class make_cout : public detail::log<detail::channelln> {
@@ -177,6 +191,9 @@ public:
detail::log<detail::channelln>(std::cout, filename, line_number, func)
{ }
+private:
+ make_cout( const make_cout& );
+ const make_cout& operator=( const make_cout& );
};
class cout : public detail::log<detail::channel> {
@@ -184,6 +201,10 @@ public:
cout(const char* filename, int line_number, const char* func) :
detail::log<detail::channel>(std::cout, filename, line_number, func)
{ }
+
+private:
+ cout( const cout& );
+ const cout& operator=( const cout& );
};
diff --git a/libtest/strerror.cc b/libtest/strerror.cc
index 901652fa..ebbc1e4f 100644
--- a/libtest/strerror.cc
+++ b/libtest/strerror.cc
@@ -52,7 +52,7 @@ const char *test_strerror(test_return_t code)
return "skipped";
}
- fatal_message("No port could be found");
+ FATAL("No port could be found");
}
} // namespace libtest
diff --git a/libtest/thread.hpp b/libtest/thread.hpp
index 25fc0993..b09da7fc 100644
--- a/libtest/thread.hpp
+++ b/libtest/thread.hpp
@@ -46,30 +46,32 @@ namespace thread
class Mutex
{
public:
- Mutex()
+ Mutex() :
+ _err(0)
{
- int err;
- if ((err= pthread_mutex_init(&_mutex, NULL)))
- {
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_mutex_init: %s", strerror(err));
- }
+ _err= pthread_mutex_init(&_mutex, NULL);
}
~Mutex()
{
- int err;
- if ((err= pthread_mutex_destroy(&_mutex)))
+ if ((_err= pthread_mutex_destroy(&_mutex)))
{
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_cond_destroy: %s", strerror(err));
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_cond_destroy: %s", strerror(_err));
}
}
pthread_mutex_t* handle()
{
+ if (_err != 0)
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_mutex_init: %s", strerror(_err));
+ }
+
return &_mutex;
}
private:
+ int _err;
pthread_mutex_t _mutex;
};
diff --git a/libtest/timer.cc b/libtest/timer.cc
index fe164ecf..fae814ca 100644
--- a/libtest/timer.cc
+++ b/libtest/timer.cc
@@ -41,8 +41,91 @@
#include <ctime>
#include <iomanip>
+#ifdef __MACH__
+# include <mach/clock.h>
+# include <mach/mach.h>
+#else
+# include <sys/time.h>
+#endif
+
namespace libtest {
+Timer::Timer()
+{
+ _begin.tv_sec= 0;
+ _begin.tv_nsec= 0;
+ _end.tv_sec= 0;
+ _end.tv_nsec= 0;
+}
+
+void Timer::reset()
+{
+ _end.tv_sec= 0;
+ _end.tv_nsec= 0;
+ _time(_begin);
+}
+
+void Timer::sample()
+{
+ _time(_end);
+}
+
+void Timer::offset(int64_t minutes_arg, int64_t seconds_arg, int64_t nanoseconds)
+{
+ reset();
+ _end= _begin;
+ _end.tv_sec+= (minutes_arg * 60) +seconds_arg;
+ _end.tv_nsec+= nanoseconds;
+}
+
+int64_t Timer::minutes()
+{
+ struct timespec result;
+ difference(result);
+ return int64_t(result.tv_sec / 60);
+}
+
+uint64_t Timer::elapsed_milliseconds() const
+{
+ struct timespec temp;
+ difference(temp);
+
+ return temp.tv_sec*1000 +temp.tv_nsec/1000000;
+}
+
+void Timer::difference(struct timespec& arg) const
+{
+ if ((_end.tv_nsec -_begin.tv_nsec) < 0)
+ {
+ arg.tv_sec= _end.tv_sec -_begin.tv_sec -1;
+ arg.tv_nsec= 1000000000 +_end.tv_nsec -_begin.tv_nsec;
+
+ }
+ else
+ {
+ arg.tv_sec= _end.tv_sec -_begin.tv_sec;
+ arg.tv_nsec= _end.tv_nsec -_begin.tv_nsec;
+ }
+}
+
+void Timer::_time(struct timespec& ts)
+{
+#ifdef __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);
+ clock_get_time(_clock_serv, &_mach_timespec);
+ mach_port_deallocate(mach_task_self(), _clock_serv);
+ ts.tv_sec= _mach_timespec.tv_sec;
+ ts.tv_nsec= _mach_timespec.tv_nsec;
+#elif defined(_WIN32)
+ ts.tv_sec= time(NULL);
+ ts.tv_nsec= 0;
+#else
+ clock_gettime(CLOCK_REALTIME, &ts);
+#endif
+}
+
std::ostream& operator<<(std::ostream& output, const libtest::Timer& arg)
{
struct timespec temp;
diff --git a/libtest/timer.hpp b/libtest/timer.hpp
index cd34124f..18ed3e8e 100644
--- a/libtest/timer.hpp
+++ b/libtest/timer.hpp
@@ -40,95 +40,28 @@
#include <ctime>
#include <iostream>
-#ifdef __MACH__
-# include <mach/clock.h>
-# include <mach/mach.h>
-#else
-# include <sys/time.h>
-#endif
-
namespace libtest {
class Timer {
public:
- Timer()
- {
- _begin.tv_sec= 0;
- _begin.tv_nsec= 0;
- _end.tv_sec= 0;
- _end.tv_nsec= 0;
- }
-
- void reset()
- {
- _end.tv_sec= 0;
- _end.tv_nsec= 0;
- _time(_begin);
- }
-
- void sample()
- {
- _time(_end);
- }
-
- void offset(int64_t minutes_arg, int64_t seconds_arg, int64_t nanoseconds)
- {
- reset();
- _end= _begin;
- _end.tv_sec+= (minutes_arg * 60) +seconds_arg;
- _end.tv_nsec+= nanoseconds;
- }
-
- int64_t minutes()
- {
- struct timespec result;
- difference(result);
- return int64_t(result.tv_sec / 60);
- }
-
- uint64_t elapsed_milliseconds() const
- {
- struct timespec temp;
- difference(temp);
-
- return temp.tv_sec*1000 +temp.tv_nsec/1000000;
- }
-
- void difference(struct timespec& arg) const
- {
- if ((_end.tv_nsec -_begin.tv_nsec) < 0)
- {
- arg.tv_sec= _end.tv_sec -_begin.tv_sec -1;
- arg.tv_nsec= 1000000000 +_end.tv_nsec -_begin.tv_nsec;
-
- }
- else
- {
- arg.tv_sec= _end.tv_sec -_begin.tv_sec;
- arg.tv_nsec= _end.tv_nsec -_begin.tv_nsec;
- }
- }
+ Timer();
+
+ void reset();
+
+ void sample();
+
+ void offset(int64_t minutes_arg, int64_t seconds_arg, int64_t nanoseconds);
+
+ int64_t minutes();
+
+ uint64_t elapsed_milliseconds() const;
+
+ void difference(struct timespec& arg) const;
private:
- void _time(struct timespec& ts)
- {
-#ifdef __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);
- clock_get_time(_clock_serv, &_mach_timespec);
- mach_port_deallocate(mach_task_self(), _clock_serv);
- ts.tv_sec= _mach_timespec.tv_sec;
- ts.tv_nsec= _mach_timespec.tv_nsec;
-#elif defined(_WIN32)
- ts.tv_sec= time(NULL);
- ts.tv_nsec= 0;
-#else
- clock_gettime(CLOCK_REALTIME, &ts);
-#endif
- }
+ void _time(struct timespec& ts);
private:
struct timespec _begin;
diff --git a/libtest/unittest.cc b/libtest/unittest.cc
index 6b11c3b0..b96fea06 100644
--- a/libtest/unittest.cc
+++ b/libtest/unittest.cc
@@ -111,7 +111,7 @@ static test_return_t test_throw_success_TEST(void *)
try {
_SUCCESS;
}
- catch (libtest::__success)
+ catch (const libtest::__success&)
{
return TEST_SUCCESS;
}
@@ -128,7 +128,7 @@ static test_return_t test_throw_skip_macro_TEST(void *)
try {
SKIP_IF(true);
}
- catch (libtest::__skipped e)
+ catch (const libtest::__skipped&)
{
return TEST_SUCCESS;
}
@@ -147,7 +147,7 @@ static test_return_t test_throw_skip_TEST(void *)
try {
throw libtest::__skipped(LIBYATL_DEFAULT_PARAM, "basic test");
}
- catch (libtest::__skipped e)
+ catch (const libtest::__skipped&)
{
return TEST_SUCCESS;
}
@@ -396,7 +396,7 @@ static test_return_t drizzled_cycle_test(void *object)
test_skip(true, has_drizzled());
- test_skip(true, server_startup(*servers, "drizzled", get_free_port(), 0, NULL, false));
+ test_skip(true, server_startup(*servers, "drizzled", get_free_port(), NULL));
return TEST_SUCCESS;
}
@@ -407,7 +407,7 @@ static test_return_t gearmand_cycle_test(void *object)
test_true(servers and servers->validate());
test_skip(true, has_gearmand());
- test_skip(true, server_startup(*servers, "gearmand", get_free_port(), 0, NULL, false));
+ test_skip(true, server_startup(*servers, "gearmand", get_free_port(), NULL));
servers->clear();
return TEST_SUCCESS;
@@ -442,7 +442,7 @@ static test_return_t server_startup_fail_TEST(void *object)
test_true(servers);
fatal::disable();
- ASSERT_EQ(servers->start_server(testing_service, LIBTEST_FAIL_PORT, 0, NULL, false), true);
+ ASSERT_EQ(servers->start_server(testing_service, LIBTEST_FAIL_PORT, NULL), true);
fatal::enable();
return TEST_SUCCESS;
@@ -453,7 +453,7 @@ static test_return_t server_startup_TEST(void *object)
server_startup_st *servers= (server_startup_st*)object;
test_true(servers);
- ASSERT_EQ(servers->start_server(testing_service, get_free_port(), 0, NULL, false), true);
+ ASSERT_EQ(servers->start_server(testing_service, get_free_port(), NULL), true);
test_true(servers->last());
pid_t last_pid= servers->last()->pid();
@@ -476,7 +476,7 @@ static test_return_t socket_server_startup_TEST(void *object)
server_startup_st *servers= (server_startup_st*)object;
test_true(servers);
- test_true(servers->start_socket_server(testing_service, get_free_port(), 0, NULL, false));
+ test_true(servers->start_socket_server(testing_service, get_free_port(), NULL));
return TEST_SUCCESS;
}
@@ -494,7 +494,7 @@ static test_return_t memcached_sasl_test(void *object)
if (HAVE_LIBMEMCACHED)
{
test_true(has_memcached_sasl());
- test_true(server_startup(*servers, "memcached-sasl", get_free_port(), 0, NULL, false));
+ test_true(server_startup(*servers, "memcached-sasl", get_free_port(), NULL));
return TEST_SUCCESS;
}
@@ -866,11 +866,8 @@ static test_return_t lookup_true_TEST(void *)
static test_return_t lookup_false_TEST(void *)
{
- if (libtest::lookup("does_not_exist.gearman.info"))
- {
- Error << "Broken DNS server detected";
- return TEST_SKIPPED;
- }
+ SKIP_IF_(libtest::lookup("does_not_exist.gearman.info"),
+ "Broken DNS server detected");
return TEST_SUCCESS;
}
@@ -896,7 +893,7 @@ static test_return_t create_tmpfile_TEST(void *)
static test_return_t fatal_message_TEST(void *)
{
ASSERT_EQ(fatal_calls++, fatal::disabled_counter());
- fatal_message("Fatal test");
+ FATAL("Fatal test");
return TEST_SUCCESS;
}
@@ -935,7 +932,6 @@ static test_return_t check_for_gearman(void *)
static test_return_t check_for_drizzle(void *)
{
- test_skip(true, HAVE_LIBDRIZZLE);
test_skip(true, has_drizzled());
testing_service= "drizzled";
@@ -1111,6 +1107,7 @@ test_st application_tests[] ={
static test_return_t check_for_curl(void *)
{
+ test_skip_valgrind();
test_skip(true, HAVE_LIBCURL);
return TEST_SUCCESS;
}
diff --git a/libtest/vchar.cc b/libtest/vchar.cc
index c899b515..9d2244b3 100644
--- a/libtest/vchar.cc
+++ b/libtest/vchar.cc
@@ -121,7 +121,7 @@ void append(libtest::vchar_ptr_t& arg, const char* ptr)
char* new_ptr= strdup(ptr);
if (new_ptr == NULL)
{
- fatal_message("UNABLE to allocate %s(%p)", ptr, ptr);
+ FATAL("UNABLE to allocate %s(%p)", ptr, ptr);
}
arg.push_back(new_ptr);
diff --git a/libtest/wait.h b/libtest/wait.h
index 5f013cd3..a39a853e 100644
--- a/libtest/wait.h
+++ b/libtest/wait.h
@@ -38,9 +38,8 @@
#include <unistd.h>
#include <string>
-#include <csignal>
+#include <signal.h>
-#include <sys/types.h>
#include <libtest/dream.h>
namespace libtest {
diff --git a/tests/cycle.cc b/tests/cycle.cc
index 3865eeb5..41a12d97 100644
--- a/tests/cycle.cc
+++ b/tests/cycle.cc
@@ -48,7 +48,7 @@ using namespace libtest;
static test_return_t server_startup_single_TEST(void *obj)
{
server_startup_st *servers= (server_startup_st*)obj;
- test_compare(true, server_startup(*servers, "memcached", libtest::get_free_port(), 0, NULL, false));
+ test_compare(true, server_startup(*servers, "memcached", libtest::get_free_port(), NULL));
test_compare(true, servers->shutdown());
@@ -60,9 +60,9 @@ static test_return_t server_startup_multiple_TEST(void *obj)
test_skip(true, jenkins_is_caller());
server_startup_st *servers= (server_startup_st*)obj;
- for (size_t x= 0; x < 10; x++)
+ for (size_t x= 0; x < 10; ++x)
{
- test_compare(true, server_startup(*servers, "memcached", libtest::get_free_port(), 0, NULL, false));
+ test_compare(true, server_startup(*servers, "memcached", libtest::get_free_port(), NULL));
}
test_compare(true, servers->shutdown());
diff --git a/tests/failure.cc b/tests/failure.cc
index 1b54b74e..b039603a 100644
--- a/tests/failure.cc
+++ b/tests/failure.cc
@@ -84,7 +84,7 @@ static test_return_t add_shutdown_servers(memcached_st *memc)
while (memcached_server_count(memc) < 2)
{
const char *argv[1]= { "add_shutdown_server" };
- test_true(global_framework->servers().start_socket_server("memcached", libtest::default_port(), 1, argv));
+ test_true(global_framework->servers().start_socket_server("memcached", libtest::default_port(), argv));
test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, "localhost", libtest::default_port()));
}
diff --git a/tests/include.am b/tests/include.am
index 0ac1d898..44fdbfa3 100644
--- a/tests/include.am
+++ b/tests/include.am
@@ -58,7 +58,6 @@ test-failure: tests/failure
gdb-failure: tests/failure
@$(GDB_COMMAND) tests/failure
-
tests_testhashkit_SOURCES= tests/hashkit_functions.cc
tests_testhashkit_LDADD= libtest/libtest.la libhashkit/libhashkit.la $(TESTS_LDADDS)
check_PROGRAMS+= tests/testhashkit
diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc
index 83b56c21..91e75372 100644
--- a/tests/libmemcached-1.0/mem_functions.cc
+++ b/tests/libmemcached-1.0/mem_functions.cc
@@ -39,7 +39,7 @@
#include <libtest/test.hpp>
#if defined(HAVE_LIBUUID) && HAVE_LIBUUID
-#include <uuid/uuid.h>
+# include <uuid/uuid.h>
#endif
/*
@@ -4606,7 +4606,7 @@ test_return_t regression_bug_583031(memcached_st *)
test_true(memc);
test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, "10.2.3.4", 11211));
- memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, 1000);
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, 3000);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 1000);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SND_TIMEOUT, 1000);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RCV_TIMEOUT, 1000);
@@ -4621,7 +4621,7 @@ test_return_t regression_bug_583031(memcached_st *)
test_false(value);
test_zero(length);
- test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_last_error_message(memc));
+ test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_error(memc));
memcached_free(memc);
diff --git a/tests/libmemcached-1.0/pool.cc b/tests/libmemcached-1.0/pool.cc
index 7e484bd3..ced14bbc 100644
--- a/tests/libmemcached-1.0/pool.cc
+++ b/tests/libmemcached-1.0/pool.cc
@@ -243,10 +243,7 @@ struct test_pool_context_st {
static __attribute__((noreturn)) void* connection_release(void *arg)
{
test_pool_context_st *resource= static_cast<test_pool_context_st *>(arg);
- if (resource == NULL)
- {
- fatal_message("resource == NULL");
- }
+ FATAL_IF(resource == NULL);
// Release all of the memc we are holding
resource->rc= memcached_pool_release(resource->pool, resource->mmc);
@@ -396,17 +393,11 @@ static bool _running= false;
static void set_running(const bool arg)
{
int error;
- if ((error= pthread_mutex_lock(&mutex)) != 0)
- {
- fatal_message(strerror(error));
- }
+ FATAL_IF_((error= pthread_mutex_lock(&mutex)) != 0, strerror(error));
_running= arg;
- if ((error= pthread_mutex_unlock(&mutex)) != 0)
- {
- fatal_message(strerror(error));
- }
+ FATAL_IF_((error= pthread_mutex_unlock(&mutex)) != 0, strerror(error));
}
static bool running()
@@ -414,17 +405,11 @@ static bool running()
int error;
bool ret;
- if ((error= pthread_mutex_lock(&mutex)) != 0)
- {
- fatal_message(strerror(error));
- }
+ FATAL_IF_((error= pthread_mutex_lock(&mutex)) != 0, strerror(error));
ret= _running;
- if ((error= pthread_mutex_unlock(&mutex)) != 0)
- {
- fatal_message(strerror(error));
- }
+ FATAL_IF_((error= pthread_mutex_unlock(&mutex)) != 0, strerror(error));
return ret;
}
@@ -504,15 +489,9 @@ test_return_t regression_bug_962815(memcached_st *memc)
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;
}
diff --git a/tests/libmemcached_world.h b/tests/libmemcached_world.h
index 596ec8ee..3dda2d8a 100644
--- a/tests/libmemcached_world.h
+++ b/tests/libmemcached_world.h
@@ -77,7 +77,7 @@ static void *world_create(libtest::server_startup_st& servers, test_return_t& er
if (servers.sasl())
{
- if (server_startup(servers, "memcached-sasl", port, 0, NULL) == false)
+ if (server_startup(servers, "memcached-sasl", port, NULL) == false)
{
error= TEST_SKIPPED;
return NULL;
@@ -85,7 +85,7 @@ static void *world_create(libtest::server_startup_st& servers, test_return_t& er
}
else
{
- if (server_startup(servers, "memcached", port, 0, NULL) == false)
+ if (server_startup(servers, "memcached", port, NULL) == false)
{
error= TEST_SKIPPED;
return NULL;
diff --git a/tests/libmemcached_world_socket.h b/tests/libmemcached_world_socket.h
index a3078e76..64cf55e5 100644
--- a/tests/libmemcached_world_socket.h
+++ b/tests/libmemcached_world_socket.h
@@ -53,8 +53,8 @@ static void *world_create(libtest::server_startup_st& servers, test_return_t& er
for (uint32_t x= 0; x < servers.servers_to_run(); x++)
{
- const char *argv[1]= { "memcached" };
- if (servers.start_socket_server("memcached", libtest::get_free_port(), 1, argv) == false)
+ const char *argv[]= { "memcached", 0 };
+ if (servers.start_socket_server("memcached", libtest::get_free_port(), argv) == false)
{
#if 0
fatal_message("Could not launch memcached");
diff --git a/tests/memcapable.cc b/tests/memcapable.cc
index 795fb6f8..054342c3 100644
--- a/tests/memcapable.cc
+++ b/tests/memcapable.cc
@@ -113,7 +113,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
return NULL;
}
- if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
+ if (server_startup(servers, "memcached", libtest::default_port(), NULL) == false)
{
error= TEST_SKIPPED;
}
diff --git a/tests/memcat.cc b/tests/memcat.cc
index 6664bf66..e019bc9b 100644
--- a/tests/memcat.cc
+++ b/tests/memcat.cc
@@ -132,7 +132,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
return NULL;
}
- if (not server_startup(servers, "memcached", libtest::default_port(), 0, NULL))
+ if (not server_startup(servers, "memcached", libtest::default_port(), NULL))
{
error= TEST_FAILURE;
}
diff --git a/tests/memcp.cc b/tests/memcp.cc
index 64f17847..9c9f4d62 100644
--- a/tests/memcp.cc
+++ b/tests/memcp.cc
@@ -91,7 +91,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
return NULL;
}
- if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
+ if (server_startup(servers, "memcached", libtest::default_port(), NULL) == false)
{
error= TEST_FAILURE;
}
diff --git a/tests/memdump.cc b/tests/memdump.cc
index 0d04ea28..e55b2b99 100644
--- a/tests/memdump.cc
+++ b/tests/memdump.cc
@@ -118,7 +118,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
return NULL;
}
- if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
+ if (server_startup(servers, "memcached", libtest::default_port(), NULL) == false)
{
error= TEST_FAILURE;
return NULL;
diff --git a/tests/memexist.cc b/tests/memexist.cc
index b2db6e53..98d224f7 100644
--- a/tests/memexist.cc
+++ b/tests/memexist.cc
@@ -149,7 +149,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
return NULL;
}
- if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
+ if (server_startup(servers, "memcached", libtest::default_port(), NULL) == false)
{
error= TEST_SKIPPED;
}
diff --git a/tests/memflush.cc b/tests/memflush.cc
index f3d9c6f9..ca49e711 100644
--- a/tests/memflush.cc
+++ b/tests/memflush.cc
@@ -101,7 +101,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
return NULL;
}
- if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == 0)
+ if (server_startup(servers, "memcached", libtest::default_port(), NULL) == 0)
{
error= TEST_SKIPPED;
}
diff --git a/tests/memrm.cc b/tests/memrm.cc
index 798dd56a..acd24fc0 100644
--- a/tests/memrm.cc
+++ b/tests/memrm.cc
@@ -152,7 +152,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
return NULL;
}
- if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
+ if (server_startup(servers, "memcached", libtest::default_port(), NULL) == false)
{
error= TEST_FAILURE;
}
diff --git a/tests/memslap.cc b/tests/memslap.cc
index 9dfeca8d..6bf080f3 100644
--- a/tests/memslap.cc
+++ b/tests/memslap.cc
@@ -173,8 +173,8 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
return NULL;
}
- const char *argv[1]= { "memslap" };
- if (not server_startup(servers, "memcached", libtest::default_port(), 1, argv))
+ const char *argv[]= { "memslap", 0 };
+ if (server_startup(servers, "memcached", libtest::default_port(), argv) == false)
{
error= TEST_FAILURE;
}
diff --git a/tests/memstat.cc b/tests/memstat.cc
index 2607afdf..3ff97717 100644
--- a/tests/memstat.cc
+++ b/tests/memstat.cc
@@ -113,7 +113,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
return NULL;
}
- if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
+ if (server_startup(servers, "memcached", libtest::default_port(), NULL) == false)
{
error= TEST_SKIPPED;
}
diff --git a/tests/memtouch.cc b/tests/memtouch.cc
index 9d55d8c0..247e1870 100644
--- a/tests/memtouch.cc
+++ b/tests/memtouch.cc
@@ -145,7 +145,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
return NULL;
}
- if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
+ if (server_startup(servers, "memcached", libtest::default_port(), NULL) == false)
{
error= TEST_SKIPPED;
}
diff --git a/util/string.hpp b/util/string.hpp
index 9f678698..bf87eab8 100644
--- a/util/string.hpp
+++ b/util/string.hpp
@@ -2,7 +2,7 @@
*
* DataDifferential Utility Library
*
- * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2011-2013 Data Differential, http://datadifferential.com/
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
diff --git a/win32/wrappers.h b/win32/wrappers.h
index 976303cb..5bf325e9 100644
--- a/win32/wrappers.h
+++ b/win32/wrappers.h
@@ -9,8 +9,7 @@
* 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>
@@ -76,5 +75,3 @@
#define waitpid(a,b,c) (-1)
#define fnmatch(a,b,c) (-1)
#define sleep(a) Sleep(a*1000)
-
-#endif /* WIN32_WRAPPERS_H */