--- /dev/null
+/* LibMemcached
+ * Copyright (C) 2006-2009 Brian Aker
+ * All rights reserved.
+ *
+ * Use and distribution licensed under the BSD license. See
+ * the COPYING file in the parent directory for full text.
+ *
+ * Summary: Connection pool library.
+ *
+ * Author: Trond Norbye, Brian Aker
+ *
+ */
+
+
+#ifndef __LIBMEMCACHED__UTIL_H__
+#define __LIBMEMCACHED__UTIL_H__
+
+#include <libmemcached/memcached_util.h>
+
+#endif /* __LIBMEMCACHED__UTIL_H__ */
--- /dev/null
+/* LibMemcached
+ * Copyright (C) 2010 Brian Aker
+ * All rights reserved.
+ *
+ * Use and distribution licensed under the BSD license. See
+ * the COPYING file in the parent directory for full text.
+ *
+ * Summary: connects to a host, and makes sure it is alive.
+ *
+ */
+
+#include "libmemcached/common.h"
+#include "libmemcached/memcached_util.h"
+
+
+bool libmemcached_ping(const char *hostname, in_port_t port, memcached_return_t *ret)
+{
+ memcached_return_t rc;
+ memcached_st memc, *memc_ptr;
+
+ memc_ptr= memcached_create(&memc);
+
+ rc= memcached_server_add(memc_ptr, hostname, port);
+
+ if (rc == MEMCACHED_SUCCESS)
+ {
+ rc= memcached_version(memc_ptr);
+ }
+
+ memcached_free(memc_ptr);
+
+ if (ret)
+ {
+ *ret= rc;
+ }
+
+ return rc == MEMCACHED_SUCCESS;
+}
--- /dev/null
+/* LibMemcached
+ * Copyright (C) 2010 Brian Aker
+ * All rights reserved.
+ *
+ * Use and distribution licensed under the BSD license. See
+ * the COPYING file in the parent directory for full text.
+ *
+ * Summary: connects to a host, and makes sure it is alive.
+ *
+ */
+
+#ifndef __LIBMEMCACHED_PING_H__
+#define __LIBMEMCACHED_PING_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+LIBMEMCACHED_API
+bool libmemcached_ping(const char *hostname, in_port_t port, memcached_return_t *ret);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LIBMEMCACHED_PING_H__ */
#include <assert.h>
#include <signal.h>
#include <libmemcached/memcached.h>
+#include <libmemcached/util.h>
#include <unistd.h>
#include "server.h"
if (x == 0)
{
sprintf(buffer, "%s -d -P /tmp/%umemc.pid -t 1 -p %u -U %u -m 128",
- MEMCACHED_BINARY, x, x + TEST_PORT_BASE, x + TEST_PORT_BASE);
+ MEMCACHED_BINARY, x, x + TEST_PORT_BASE, x + TEST_PORT_BASE);
}
else
{
sprintf(buffer, "%s -d -P /tmp/%umemc.pid -t 1 -p %u -U %u",
- MEMCACHED_BINARY, x, x + TEST_PORT_BASE, x + TEST_PORT_BASE);
+ MEMCACHED_BINARY, x, x + TEST_PORT_BASE, x + TEST_PORT_BASE);
}
- fprintf(stderr, "STARTING SERVER: %s\n", buffer);
- status= system(buffer);
+ if (libmemcached_ping("localhost", (in_port_t)(x + TEST_PORT_BASE), NULL))
+ {
+ fprintf(stderr, "Server on port %u already exists\n", x + TEST_PORT_BASE);
+ }
+ else
+ {
+ status= system(buffer);
+ fprintf(stderr, "STARTING SERVER: %s status:%d\n", buffer, status);
+ }
count= sprintf(end_ptr, "localhost:%u,", x + TEST_PORT_BASE);
end_ptr+= count;
}