Repository: mesos Updated Branches: refs/heads/master 59215ad57 -> 4913b8697
Fix compilation error for Socket on older linux + OSX. Test whether SOCK_NONBLOCK and SOCK_CLOEXEC are defined to use single system call to create socket. Otherwise use os::nonblock and os::cloexec after creating the socket. Review: https://reviews.apache.org/r/28125 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/4913b869 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/4913b869 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/4913b869 Branch: refs/heads/master Commit: 4913b869778d7e8eb0c15c2b4ec9b11d17077960 Parents: 59215ad Author: Joris Van Remoortere <[email protected]> Authored: Mon Nov 17 21:21:19 2014 +0100 Committer: Till Toenshoff <[email protected]> Committed: Mon Nov 17 21:21:19 2014 +0100 ---------------------------------------------------------------------- 3rdparty/libprocess/include/process/socket.hpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/4913b869/3rdparty/libprocess/include/process/socket.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/socket.hpp b/3rdparty/libprocess/include/process/socket.hpp index 20136ba..3f3e01c 100644 --- a/3rdparty/libprocess/include/process/socket.hpp +++ b/3rdparty/libprocess/include/process/socket.hpp @@ -92,11 +92,32 @@ public: const Impl& create() const { CHECK(s < 0); + + // Supported in Linux >= 2.6.27. +#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC) Try<int> fd = process::socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); + + if (fd.isError()) { + ABORT("Failed to create socket: " + fd.error()); + } +#else + Try<int> fd = process::socket(AF_INET, SOCK_STREAM, 0); if (fd.isError()) { ABORT("Failed to create socket: " + fd.error()); } + + Try<Nothing> nonblock = os::nonblock(fd.get()); + if (nonblock.isError()) { + ABORT("Failed to create socket, nonblock: " + nonblock.error()); + } + + Try<Nothing> cloexec = os::cloexec(fd.get()); + if (cloexec.isError()) { + ABORT("Failed to create socket, cloexec: " + cloexec.error()); + } +#endif + s = fd.get(); return *this; }
