X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fbin%2Fmemcapable.cc;h=1b9af02a5dc4bd596408351b8df6845255e55199;hb=aeac01630eed825d8a624e7fd7c107d47bb2e40c;hp=a3a4e3a2b559c93ab1d530aaf4711ba47a6ad2ad;hpb=dfdcce95b625e98144c1681f05b337648b92f20f;p=awesomized%2Flibmemcached diff --git a/src/bin/memcapable.cc b/src/bin/memcapable.cc index a3a4e3a2..1b9af02a 100644 --- a/src/bin/memcapable.cc +++ b/src/bin/memcapable.cc @@ -17,12 +17,6 @@ #include "mem_config.h" -#ifdef HAVE_POLL_H -# include -#else -# include "poll/poll.h" -#endif - #include #include #include @@ -31,14 +25,19 @@ #include #include #include -#include +#include #include #include #if HAVE_UNISTD_H # include #endif -#include "libmemcached-1.0/memcached.h" +#ifndef HAVE_GETOPT_H +# include "../../win32/getopt.h" +#endif + +#include "libmemcached-1.0/memcached.h" +#include "libmemcached/poll.h" #include "libmemcached/socket.hpp" #include "libmemcachedprotocol-0.0/binary.h" #include "libmemcached/byteorder.h" @@ -176,13 +175,13 @@ static memcached_socket_t connect_server(const char *hostname, const char *port) return sock; } -static ssize_t timeout_io_op(memcached_socket_t fd, short direction, void *buf, size_t len) { +static ssize_t timeout_io_op(memcached_socket_t fd, short direction, const char *buf, size_t len) { ssize_t ret; if (direction == POLLOUT) { ret = send(fd, buf, len, 0); } else { - ret = recv(fd, buf, len, 0); + ret = recv(fd, const_cast(buf), len, 0); } if (ret == SOCKET_ERROR && get_socket_errno() == EWOULDBLOCK) { @@ -196,7 +195,7 @@ static ssize_t timeout_io_op(memcached_socket_t fd, short direction, void *buf, if (direction == POLLOUT) { ret = send(fd, buf, len, 0); } else { - ret = recv(fd, buf, len, 0); + ret = recv(fd, const_cast(buf), len, 0); } } else if (err == 0) { errno = ETIMEDOUT; @@ -251,7 +250,7 @@ static enum test_return retry_write(const void *buf, size_t len) { do { size_t num_bytes = len - offset; - ssize_t nw = timeout_io_op(sock, POLLOUT, (void *) (ptr + offset), num_bytes); + ssize_t nw = timeout_io_op(sock, POLLOUT, (ptr + offset), num_bytes); if (nw == -1) { verify(get_socket_errno() == EINTR || get_socket_errno() == EAGAIN); } else { @@ -1882,7 +1881,14 @@ int main(int argc, char **argv) { return EXIT_FAILURE; } - //initialize_sockets(); + #ifdef _WIN32 + WSADATA wsaData; + if (WSAStartup(MAKEWORD(2, 2), &wsaData)) { + fprintf(stderr, "Socket Initialization Error.\n"); + return EXIT_FAILURE; + } +#endif // _WIN32 + sock = connect_server(hostname, port); if (sock == INVALID_SOCKET) { fprintf(stderr, "Failed to connect to <%s:%s>: %s\n", hostname, port, @@ -1958,5 +1964,9 @@ int main(int argc, char **argv) { fprintf(stderr, "%d of %d tests failed\n", failed, total); } +#ifdef _WIN32 + WSACleanup(); +#endif + return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; }