Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(583)

Unified Diff: runtime/bin/socket_linux.cc

Issue 9837060: Treat EAGAIN/EWOULDBLOCK as requests for retry on socket accept. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/bin/socket_linux.cc
diff --git a/runtime/bin/socket_linux.cc b/runtime/bin/socket_linux.cc
index 5f4096bb75f3120625ccbc2bb3fb705f70fdeeee..8e37849f3d2fda52ab4a047809085a766e1a29f5 100644
--- a/runtime/bin/socket_linux.cc
+++ b/runtime/bin/socket_linux.cc
@@ -188,13 +188,32 @@ intptr_t ServerSocket::CreateBindListen(const char* host,
return fd;
}
+
+static bool IsTemporaryAcceptError(int error) {
+ // On Linux a number of protocol errors should be treated as EAGAIN.
+ // These are the ones for TCP/IP.
+ return (error == EAGAIN) || (error == ENETDOWN) || (error == EPROTO) ||
+ (error == ENOPROTOOPT) || (error == EHOSTDOWN) || (error == ENONET) ||
+ (error == EHOSTUNREACH) || (error == EOPNOTSUPP) ||
+ (error == ENETUNREACH);
+}
+
+
intptr_t ServerSocket::Accept(intptr_t fd) {
intptr_t socket;
struct sockaddr clientaddr;
socklen_t addrlen = sizeof(clientaddr);
socket = TEMP_FAILURE_RETRY(accept(fd, &clientaddr, &addrlen));
- if (socket < 0) {
- fprintf(stderr, "Error Accept: %s\n", strerror(errno));
+ if (socket == -1) {
+ if (IsTemporaryAcceptError(errno)) {
+ // We need to signal to the caller that this is actually not an
+ // error. We got woken up from the poll on the listening socket,
+ // but there is no connection ready to be accepted.
+ ASSERT(kTemporaryFailure != -1);
+ socket = kTemporaryFailure;
+ } else {
+ fprintf(stderr, "Error Accept: %s\n", strerror(errno));
Ivan Posva 2012/03/23 21:09:48 Mads says this should be removed.
+ }
} else {
FDUtils::SetNonBlocking(socket);
}

Powered by Google App Engine
This is Rietveld 408576698