Permalink
Browse files

MB-3202 - windows async connect() returns different errcode

Enabled async connect() usage on windows, so moxi will have the same
"pull network plug" behavior as on linux.  However, windows returns
EWOULDBLOCK instead of EINPROGRESS, and WSAGetLastError() must be used
instead of errno.

Change-Id: I6f4918387737cbb6ee458825aec96b57877062ae
Reviewed-on: http://review.membase.org/4103
Reviewed-by: Bin Cui <bin.cui@gmail.com>
Tested-by: Steve Yen <steve.yen@gmail.com>
  • Loading branch information...
1 parent 8a151a8 commit b9ddb37bf630e99ba8dae6cd382327de1b4b90f0 @steveyen steveyen committed Dec 16, 2010
Showing with 33 additions and 25 deletions.
  1. +10 −11 cproxy.c
  2. +8 −2 mcs.c
  3. +15 −12 win32/win32.h
View
@@ -15,12 +15,8 @@
#include "log.h"
#ifndef MOXI_BLOCKING_CONNECT
-#ifdef WIN32
-#define MOXI_BLOCKING_CONNECT true
-#else
#define MOXI_BLOCKING_CONNECT false
#endif
-#endif
// Internal forward declarations.
//
@@ -1469,13 +1465,15 @@ conn *cproxy_connect_downstream_conn(downstream *d,
int fd = mcs_connect(mcs_server_st_hostname(msst),
mcs_server_st_port(msst), &err,
MOXI_BLOCKING_CONNECT);
- if (fd != -1) {
- if (settings.verbose > 2) {
- moxi_log_write("%d: cproxy_connect_downstream_conn %s:%d\n", fd,
- mcs_server_st_hostname(msst),
- mcs_server_st_port(msst));
- }
+ if (settings.verbose > 2) {
+ moxi_log_write("%d: cproxy_connect_downstream_conn %s:%d %d %d\n", fd,
+ mcs_server_st_hostname(msst),
+ mcs_server_st_port(msst),
+ MOXI_BLOCKING_CONNECT, err);
+ }
+
+ if (fd != -1) {
conn *c = conn_new(fd, conn_pause, 0,
DATA_BUFFER_SIZE,
tcp_transport,
@@ -1488,7 +1486,8 @@ conn *cproxy_connect_downstream_conn(downstream *d,
c->thread = thread;
c->cmd_start_time = start;
- if (err == EINPROGRESS) {
+ if (err == EINPROGRESS ||
+ err == EWOULDBLOCK) {
if (update_event_timed(c, EV_WRITE | EV_PERSIST,
&behavior->connect_timeout)) {
conn_set_state(c, conn_connecting);
View
@@ -465,12 +465,18 @@ int mcs_connect(const char *hostname, int portnum,
}
if (connect(sock, ai->ai_addr, ai->ai_addrlen) == -1) {
- int errno_last = errno;
+ int errno_last;
+#ifdef WIN32
+ errno_last = WSAGetLastError();
+#else
+ errno_last = errno;
+#endif
if (errno_out != NULL) {
*errno_out = errno_last;
}
- if (!blocking && (errno_last == EINPROGRESS)) {
+ if (!blocking && (errno_last == EINPROGRESS ||
+ errno_last == EWOULDBLOCK)) {
ret = sock;
break;
}
View
@@ -20,7 +20,7 @@
#include <process.h>
#include <signal.h>
-#define EWOULDBLOCK EAGAIN
+#define EWOULDBLOCK WSAEWOULDBLOCK
#define EAFNOSUPPORT 47
#define EADDRINUSE WSAEADDRINUSE
#define ECONNRESET WSAECONNRESET
@@ -137,9 +137,10 @@ static inline size_t mem_write(int s, void *buf, size_t len)
if(WSASend(s, &wsabuf, 1, &dwBufferCount, 0, NULL, NULL) == 0) {
return dwBufferCount;
}
- error = WSAGetLastError();
- if(error == WSAECONNRESET) return 0;
- mapErr(error);
+ error = WSAGetLastError();
+ if(error == WSAECONNRESET)
+ return 0;
+ mapErr(error);
return -1;
}
@@ -158,13 +159,13 @@ static inline size_t mem_read(int s, void *buf, size_t len)
&dwBufferCount,
&flags,
NULL,
- NULL
- ) == 0) {
+ NULL) == 0) {
return dwBufferCount;
}
error = WSAGetLastError();
- if (error == WSAECONNRESET) return 0;
- mapErr(error);
+ if (error == WSAECONNRESET)
+ return 0;
+ mapErr(error);
return -1;
}
@@ -181,13 +182,13 @@ static inline int sendmsg(int s, const struct msghdr *msg, int flags)
msg->msg_name,
msg->msg_namelen,
NULL,
- NULL
- ) == 0) {
+ NULL) == 0) {
return dwBufferCount;
}
error = WSAGetLastError();
- if (error == WSAECONNRESET) return 0;
- mapErr(error);
+ if (error == WSAECONNRESET)
+ return 0;
+ mapErr(error);
return -1;
}
@@ -212,11 +213,13 @@ static int fcntl(SOCKET s, int cmd, int val)
imode = 1;
if(ioctlsocket(s, FIONBIO, &imode) == SOCKET_ERROR)
return -1;
+ return 0;
break;
case O_BLOCK:
imode = 0;
if(ioctlsocket(s, FIONBIO, &imode) == SOCKET_ERROR)
return -1;
+ return 0;
break;
default:
return -1;

0 comments on commit b9ddb37

Please sign in to comment.