int flags = fcntl(sock, F_GETFL, 0);
if (flags == -1) {
perror("Failed to get socket flags");
int flags = fcntl(sock, F_GETFL, 0);
if (flags == -1) {
perror("Failed to get socket flags");
return INVALID_SOCKET;
}
if ((flags & O_NONBLOCK) != O_NONBLOCK) {
if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1) {
perror("Failed to set socket to nonblocking mode");
return INVALID_SOCKET;
}
if ((flags & O_NONBLOCK) != O_NONBLOCK) {
if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1) {
perror("Failed to set socket to nonblocking mode");
-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 {
ssize_t ret;
if (direction == POLLOUT) {
ret = send(fd, buf, len, 0);
} else {
- ret = recv(fd, buf, len, 0);
+ ret = recv(fd, const_cast<char *>(buf), len, 0);
if (direction == POLLOUT) {
ret = send(fd, buf, len, 0);
} else {
if (direction == POLLOUT) {
ret = send(fd, buf, len, 0);
} else {
- ret = recv(fd, buf, len, 0);
+ ret = recv(fd, const_cast<char *>(buf), len, 0);
- 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);
- //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) {
sock = connect_server(hostname, port);
if (sock == INVALID_SOCKET) {
- fprintf(stderr, "Failed to connect to <%s:%s>: %s\n", hostname ?: "(null)", port ?: "(null)",
+ fprintf(stderr, "Failed to connect to <%s:%s>: %s\n", hostname, port,
- fprintf(stderr, "Failed to connect to <%s:%s>: %s\n", hostname ?: "(null)",
- port ?: "(null)", strerror(get_socket_errno()));
+ fprintf(stderr, "Failed to connect to <%s:%s>: %s\n", hostname,
+ port, strerror(get_socket_errno()));
fprintf(stderr, "%d of %d tests failed\n", failed, total);
return EXIT_FAILURE;
}
fprintf(stderr, "%d of %d tests failed\n", failed, total);
return EXIT_FAILURE;
}
fprintf(stderr, "%d of %d tests failed\n", failed, total);
}
fprintf(stderr, "%d of %d tests failed\n", failed, total);
}