]> granicus.if.org Git - libevent/commitdiff
New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
authorNick Mathewson <nickm@torproject.org>
Tue, 13 Jan 2009 19:19:50 +0000 (19:19 +0000)
committerNick Mathewson <nickm@torproject.org>
Tue, 13 Jan 2009 19:19:50 +0000 (19:19 +0000)
svn:r994

Makefile.am
util-internal.h [new file with mode: 0644]

index 8be7421b5656ff3e9a57fc74a2c08a17940fd19a..d0b40b408eeceec3cdfec8a268ba63737eda37d5 100644 (file)
@@ -81,6 +81,8 @@ event-config.h: config.h
            -e 's/#ifndef /#ifndef _EVENT_/' < config.h >> $@
        echo "#endif" >> $@
 
+noinst_HEADERS = util-internal.h
+
 CORE_SRC = event.c buffer.c evbuffer-internal.h bufferevent.c \
        bufferevent-internal.h evmap.c evmap.h \
        log.c evutil.c strlcpy.c strlcpy-internal.h $(SYS_SRC)
diff --git a/util-internal.h b/util-internal.h
new file mode 100644 (file)
index 0000000..aafed92
--- /dev/null
@@ -0,0 +1,54 @@
+
+#ifndef _EVENT_UTIL_INTERNAL_H
+#define _EVENT_UTIL_INTERNAL_H
+
+#include "event-config.h"
+#include <errno.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Internal use only: macros to match patterns of error codes in a
+   cross-platform way.  We need these macros because of two historical
+   reasons: first, nonblocking IO functions are generally written to give an
+   error on the "blocked now, try later" case, so sometimes an error from a
+   read, write, connect, or accept means "no error; just wait for more
+   data," and we need to look at the error code.  Second, Windows defines
+   a different set of error codes for sockets. */
+
+#ifndef WIN32
+
+/* True iff e is an error that means a read/write operation can be retried. */
+#define EVUTIL_ERR_RW_RETRIABLE(e)                             \
+       ((e) == EINTR || (e) == EAGAIN)
+/* True iff e is an error that means an accept can be retried. */
+#define EVUTIL_ERR_CONNECT_RETRIABLE(e)                        \
+       ((e) == EINTR || (e) == EINPROGRESS)
+/* True iff e is an error that means a connect can be retried. */
+#define EVUTIL_ERR_ACCEPT_RETRIABLE(e)                 \
+       ((e) == EINTR || (e) == EAGAIN || (e) == ECONNABORTED)
+
+#else
+
+#define EVUTIL_ERR_RW_RETRIABLE(e)                                                             \
+       ((e) == WSAEAGAIN ||                                                                            \
+        (e) == WSAEWOULDBLOCK ||                                                                       \
+        (e) == WSAEINTR)
+
+#define EVUTIL_ERR_CONNECT_RETRIABLE(e)                        \
+       ((e) == WSAEWOULDBLOCK ||                                       \
+        (e) == WSAEINTR ||                                                     \
+        (e) == WSAEINPROGRESS ||                                       \
+        (e) == WSAEINVAL))
+
+#define EVUTIL_ERR_ACCEPT_RETRIABLE(e)                 \
+       EVUTIL_ERR_RW_RETRIABLE(e)
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif