فهرست منبع

Use ERROR_TRY_AGAIN macro for all operating systems

Socket/poll result unification: Linux vs Windows
bel2125 2 سال پیش
والد
کامیت
876b31ab50
1فایلهای تغییر یافته به همراه4 افزوده شده و 9 حذف شده
  1. 4 9
      src/civetweb.c

+ 4 - 9
src/civetweb.c

@@ -438,10 +438,12 @@ _civet_safe_clock_gettime(int clk_id, struct timespec *t)
 #endif
 #endif
 
 
 
 
-#if !defined(_WIN32)
+#if defined(_WIN32)
+#define ERROR_TRY_AGAIN(err) ((err) == WSAEWOULDBLOCK)
+#else
 /* Unix might return different error codes indicating to try again.
 /* Unix might return different error codes indicating to try again.
  * For Linux EAGAIN==EWOULDBLOCK, maybe EAGAIN!=EWOULDBLOCK is history from
  * For Linux EAGAIN==EWOULDBLOCK, maybe EAGAIN!=EWOULDBLOCK is history from
- * decades ago, but better check both and let the compile optimize it. */
+ * decades ago, but better check both and let the compiler optimize it. */
 #define ERROR_TRY_AGAIN(err)                                                   \
 #define ERROR_TRY_AGAIN(err)                                                   \
 	(((err) == EAGAIN) || ((err) == EWOULDBLOCK) || ((err) == EINTR))
 	(((err) == EAGAIN) || ((err) == EWOULDBLOCK) || ((err) == EINTR))
 #endif
 #endif
@@ -6086,17 +6088,10 @@ push_inner(struct mg_context *ctx,
 		} else {
 		} else {
 			n = (int)send(sock, buf, (len_t)len, MSG_NOSIGNAL);
 			n = (int)send(sock, buf, (len_t)len, MSG_NOSIGNAL);
 			err = (n < 0) ? ERRNO : 0;
 			err = (n < 0) ? ERRNO : 0;
-#if defined(_WIN32)
-			if (err == WSAEWOULDBLOCK) {
-				err = 0;
-				n = 0;
-			}
-#else
 			if (ERROR_TRY_AGAIN(err)) {
 			if (ERROR_TRY_AGAIN(err)) {
 				err = 0;
 				err = 0;
 				n = 0;
 				n = 0;
 			}
 			}
-#endif
 			if (n < 0) {
 			if (n < 0) {
 				/* shutdown of the socket at client side */
 				/* shutdown of the socket at client side */
 				return -2;
 				return -2;