2 // detail/impl/winsock_init.ipp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_DETAIL_IMPL_WINSOCK_INIT_IPP
12 #define BOOST_ASIO_DETAIL_IMPL_WINSOCK_INIT_IPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
22 #include <boost/asio/detail/socket_types.hpp>
23 #include <boost/asio/detail/winsock_init.hpp>
24 #include <boost/asio/detail/throw_error.hpp>
25 #include <boost/asio/error.hpp>
27 #include <boost/asio/detail/push_options.hpp>
33 void winsock_init_base::startup(data& d,
34 unsigned char major, unsigned char minor)
36 if (::InterlockedIncrement(&d.init_count_) == 1)
39 long result = ::WSAStartup(MAKEWORD(major, minor), &wsa_data);
40 ::InterlockedExchange(&d.result_, result);
44 void winsock_init_base::manual_startup(data& d)
46 if (::InterlockedIncrement(&d.init_count_) == 1)
48 ::InterlockedExchange(&d.result_, 0);
52 void winsock_init_base::cleanup(data& d)
54 if (::InterlockedDecrement(&d.init_count_) == 0)
60 void winsock_init_base::manual_cleanup(data& d)
62 ::InterlockedDecrement(&d.init_count_);
65 void winsock_init_base::throw_on_error(data& d)
67 long result = ::InterlockedExchangeAdd(&d.result_, 0);
70 boost::system::error_code ec(result,
71 boost::asio::error::get_system_category());
72 boost::asio::detail::throw_error(ec, "winsock");
80 #include <boost/asio/detail/pop_options.hpp>
82 #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
84 #endif // BOOST_ASIO_DETAIL_IMPL_WINSOCK_INIT_IPP