You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2016/03/24 10:27:00 UTC
[02/11] mesos git commit: Windows: [1/2] Lifted socket API into Stout.
Windows: [1/2] Lifted socket API into Stout.
Review: https://reviews.apache.org/r/44138/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6f8544cf
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6f8544cf
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6f8544cf
Branch: refs/heads/master
Commit: 6f8544cf5e2748a58ac979e6d12336b2dccbf1fb
Parents: d13ebc2
Author: Daniel Pravat <dp...@outlook.com>
Authored: Thu Mar 24 09:32:57 2016 +0100
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Thu Mar 24 10:26:49 2016 +0100
----------------------------------------------------------------------
.../stout/include/stout/os/posix/socket.hpp | 58 ++++++++++++++++
.../3rdparty/stout/include/stout/os/socket.hpp | 52 ++++++++++++++
.../stout/include/stout/os/windows/socket.hpp | 72 ++++++++++++++++++++
3 files changed, 182 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/6f8544cf/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/socket.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/socket.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/socket.hpp
new file mode 100644
index 0000000..ab5f62a
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/socket.hpp
@@ -0,0 +1,58 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_POSIX_SOCKET_HPP__
+#define __STOUT_OS_POSIX_SOCKET_HPP__
+
+#include <unistd.h>
+
+#include <sys/socket.h>
+#include <sys/stat.h>
+
+namespace net {
+
+// The error indicates the last socket operation has been
+// interupted, the operation can be restarted imediately.
+inline bool is_restartable_error(int error)
+{
+ return (error == EINTR);
+}
+
+
+// The error indicates the last socket function on a non-blocking socket
+// cannot be completed. This is a temporary condition and the caller can
+// retry the operation later.
+inline bool is_retryable_error(int error)
+{
+ return (error == EWOULDBLOCK || error == EAGAIN);
+}
+
+
+inline bool is_inprogress_error(int error)
+{
+ return (error == EINPROGRESS);
+}
+
+
+inline bool is_socket(int fd)
+{
+ struct stat statbuf;
+ if (fstat(fd, &statbuf) < 0) {
+ return false;
+ }
+
+ return S_ISSOCK(statbuf.st_mode) != 0;
+}
+
+} // namespace net {
+
+#endif // __STOUT_OS_POSIX_SOCKET_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/6f8544cf/3rdparty/libprocess/3rdparty/stout/include/stout/os/socket.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/socket.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/socket.hpp
new file mode 100644
index 0000000..e9d9306
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/socket.hpp
@@ -0,0 +1,52 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_SOCKET_HPP__
+#define __STOUT_OS_SOCKET_HPP__
+
+#include <stout/error.hpp>
+#include <stout/try.hpp>
+
+#ifdef __WINDOWS__
+#include <stout/os/windows/socket.hpp>
+#else
+#include <stout/os/posix/socket.hpp>
+#endif // __WINDOWS__
+
+namespace net {
+
+// Returns a socket file descriptor for the specified options.
+// NOTE: on OS X, the returned socket will have the SO_NOSIGPIPE option set.
+inline Try<int> socket(int family, int type, int protocol)
+{
+ // TODO(dpravat): Since Windows sockets are 64bit values,
+ // an additional patch is required to avoid the truncation.
+ int s;
+ if ((s = ::socket(family, type, protocol)) == -1) {
+ return ErrnoError();
+ }
+
+#ifdef __APPLE__
+ // Disable SIGPIPE via setsockopt because OS X does not support
+ // the MSG_NOSIGNAL flag on send(2).
+ const int enable = 1;
+ if (setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, &enable, sizeof(int)) == -1) {
+ return ErrnoError();
+ }
+#endif // __APPLE__
+
+ return s;
+}
+
+} // namespace net {
+
+#endif // __STOUT_OS_SOCKET_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/6f8544cf/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/socket.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/socket.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/socket.hpp
new file mode 100644
index 0000000..b5aeab7
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/socket.hpp
@@ -0,0 +1,72 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_WINDOWS_SOCKET_HPP__
+#define __STOUT_OS_WINDOWS_SOCKET_HPP__
+
+#include <winsock.h>
+
+#include <stout/abort.hpp>
+
+namespace net {
+
+// The error indicates the last socket operation has been
+// interupted, the operation can be restarted imediately.
+// The error will append on Windows only when the operation
+// is interupted using `WSACancelBlockingCall`.
+inline bool is_restartable_error(int error)
+{
+ return (error == WSAEINTR);
+}
+
+
+// The error indicates the last socket function on a non-blocking socket
+// cannot be completed. This is a temporary condition and the caller can
+// retry the operation later.
+inline bool is_retryable_error(int error)
+{
+ return (error == WSAEWOULDBLOCK);
+}
+
+
+inline bool is_inprogress_error(int error)
+{
+ return (error == WSAEWOULDBLOCK);
+}
+
+
+inline bool is_socket(SOCKET fd)
+{
+ int value = 0;
+ int length = sizeof(int);
+
+ if (::getsockopt(
+ fd,
+ SOL_SOCKET,
+ SO_TYPE,
+ (char*) &value,
+ &length) == SOCKET_ERROR) {
+ switch (WSAGetLastError()) {
+ case WSAENOTSOCK:
+ return false;
+ default:
+ // TODO(benh): Handle `WSANOTINITIALISED`.
+ ABORT("Not expecting 'getsockopt' to fail when passed a valid socket");
+ }
+ }
+
+ return true;
+}
+
+} // namespace net {
+
+#endif // __STOUT_OS_WINDOWS_SOCKET_HPP__