Index: mojo/shell/domain_socket/socket_libevent.cc |
diff --git a/mojo/shell/domain_socket/socket_libevent.cc b/mojo/shell/domain_socket/socket_libevent.cc |
index 8e98d7c2b333ca4ac0e0229899cbe2cc3ed05c41..cf4bd7912881e66ca994b474f44f5e16d95bc5eb 100644 |
--- a/mojo/shell/domain_socket/socket_libevent.cc |
+++ b/mojo/shell/domain_socket/socket_libevent.cc |
@@ -63,6 +63,13 @@ int MapConnectError(int os_error) { |
} |
} |
+int SetNonBlocking(int fd) { |
+ int flags = fcntl(fd, F_GETFL, 0); |
+ if (-1 == flags) |
+ return flags; |
+ return fcntl(fd, F_SETFL, flags | O_NONBLOCK); |
+} |
+ |
} // namespace |
SocketLibevent::SocketLibevent() |
@@ -79,9 +86,19 @@ int SocketLibevent::Open(int address_family) { |
DCHECK(address_family == AF_INET || address_family == AF_INET6 || |
address_family == AF_UNIX); |
+ int socket_type = SOCK_STREAM; |
+#ifdef SOCK_NONBLOCK |
+ socket_type |= SOCK_NONBLOCK; |
+#endif |
socket_fd_ = ::socket(address_family, |
- SOCK_STREAM | SOCK_NONBLOCK, |
+ socket_type, |
address_family == AF_UNIX ? 0 : IPPROTO_TCP); |
+#ifndef SOCK_NONBLOCK |
+ if (SetNonBlocking(socket_fd_) != 0) { |
+ PLOG(ERROR) << "SetNonBlocking() returned an error, errno=" << errno; |
+ return net::MapSystemError(errno); |
+ } |
+#endif |
if (socket_fd_ < 0) { |
PLOG(ERROR) << "CreatePlatformSocket() returned an error, errno=" << errno; |
return net::MapSystemError(errno); |
@@ -90,15 +107,6 @@ int SocketLibevent::Open(int address_family) { |
return net::OK; |
} |
-namespace { |
-int SetNonBlocking(int fd) { |
- int flags = fcntl(fd, F_GETFL, 0); |
- if (-1 == flags) |
- return flags; |
- return fcntl(fd, F_SETFL, flags | O_NONBLOCK); |
-} |
-} // namespace |
- |
int SocketLibevent::AdoptConnectedSocket(SocketDescriptor socket, |
const SockaddrStorage& address) { |
DCHECK(thread_checker_.CalledOnValidThread()); |