File indexing completed on 2025-01-18 09:28:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_IMPL_WINSOCK_INIT_IPP
0012 #define BOOST_ASIO_DETAIL_IMPL_WINSOCK_INIT_IPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019
0020 #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
0021
0022 #include <boost/asio/detail/socket_types.hpp>
0023 #include <boost/asio/detail/winsock_init.hpp>
0024 #include <boost/asio/detail/throw_error.hpp>
0025 #include <boost/asio/error.hpp>
0026
0027 #include <boost/asio/detail/push_options.hpp>
0028
0029 namespace boost {
0030 namespace asio {
0031 namespace detail {
0032
0033 void winsock_init_base::startup(data& d,
0034 unsigned char major, unsigned char minor)
0035 {
0036 if (::InterlockedIncrement(&d.init_count_) == 1)
0037 {
0038 WSADATA wsa_data;
0039 long result = ::WSAStartup(MAKEWORD(major, minor), &wsa_data);
0040 ::InterlockedExchange(&d.result_, result);
0041 }
0042 }
0043
0044 void winsock_init_base::manual_startup(data& d)
0045 {
0046 if (::InterlockedIncrement(&d.init_count_) == 1)
0047 {
0048 ::InterlockedExchange(&d.result_, 0);
0049 }
0050 }
0051
0052 void winsock_init_base::cleanup(data& d)
0053 {
0054 if (::InterlockedDecrement(&d.init_count_) == 0)
0055 {
0056 ::WSACleanup();
0057 }
0058 }
0059
0060 void winsock_init_base::manual_cleanup(data& d)
0061 {
0062 ::InterlockedDecrement(&d.init_count_);
0063 }
0064
0065 void winsock_init_base::throw_on_error(data& d)
0066 {
0067 long result = ::InterlockedExchangeAdd(&d.result_, 0);
0068 if (result != 0)
0069 {
0070 boost::system::error_code ec(result,
0071 boost::asio::error::get_system_category());
0072 boost::asio::detail::throw_error(ec, "winsock");
0073 }
0074 }
0075
0076 }
0077 }
0078 }
0079
0080 #include <boost/asio/detail/pop_options.hpp>
0081
0082 #endif
0083
0084 #endif