Repository: mesos Updated Branches: refs/heads/master 0d232bf28 -> fc4f9d25f
Windows: Libprocess: Winsock class to handle WSAStartup/WSACleanup. Review: https://reviews.apache.org/r/46344/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/cd879244 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/cd879244 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/cd879244 Branch: refs/heads/master Commit: cd879244d42ade1f63d228694e5681ea254a9902 Parents: 0d232bf Author: Alex Clemmer <clemmer.alexan...@gmail.com> Authored: Sun May 8 13:32:09 2016 -0700 Committer: Joris Van Remoortere <joris.van.remoort...@gmail.com> Committed: Sun May 8 13:36:45 2016 -0700 ---------------------------------------------------------------------- 3rdparty/libprocess/include/Makefile.am | 3 +- .../include/process/windows/winsock.hpp | 66 ++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/cd879244/3rdparty/libprocess/include/Makefile.am ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/Makefile.am b/3rdparty/libprocess/include/Makefile.am index 47f5347..6414450 100644 --- a/3rdparty/libprocess/include/Makefile.am +++ b/3rdparty/libprocess/include/Makefile.am @@ -66,4 +66,5 @@ nobase_include_HEADERS = \ process/time.hpp \ process/timeout.hpp \ process/timer.hpp \ - process/timeseries.hpp + process/timeseries.hpp \ + process/windows/winsock.hpp http://git-wip-us.apache.org/repos/asf/mesos/blob/cd879244/3rdparty/libprocess/include/process/windows/winsock.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/windows/winsock.hpp b/3rdparty/libprocess/include/process/windows/winsock.hpp new file mode 100644 index 0000000..4920a66 --- /dev/null +++ b/3rdparty/libprocess/include/process/windows/winsock.hpp @@ -0,0 +1,66 @@ +// 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 __PROCESS_WINDOWS_WINSOCK_HPP__ +#define __PROCESS_WINDOWS_WINSOCK_HPP__ + +#include <stdlib.h> + +#include <glog/logging.h> + +#include <stout/abort.hpp> +#include <stout/lambda.hpp> +#include <stout/windows.hpp> + +#include <stout/os/socket.hpp> + +#include <process/once.hpp> + + +namespace process { + +class Winsock +{ +public: + // Initializes Winsock and calls `::exit(1)` on failure. + Winsock() : Winsock([] { ::exit(EXIT_FAILURE); }) {} + + // Initializes Winsock and calls the specified function on failure. The intent + // is to have the caller pass a function that will exit the process with + // an error code (specified by the `failureCode` argument). + Winsock( + const lambda::function<void()>& on_failure_callback) + : on_failure(on_failure_callback) + { + initialize(); + } + + ~Winsock() + { + net::wsa_cleanup(); + } + +private: + inline void initialize() + { + static Once* initialized = new Once(); + + if (!initialized->once() && !net::wsa_initialize()) { + on_failure(); + } + } + + const lambda::function<void()> on_failure; +}; + +} // namespace process { + +#endif // __PROCESS_WINDOWS_WINSOCK_HPP__