Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:36

0001 //
0002 // detail/impl/winsock_init.ipp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
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 // defined(_MSC_VER) && (_MSC_VER >= 1200)
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 } // namespace detail
0077 } // namespace asio
0078 } // namespace boost
0079 
0080 #include <boost/asio/detail/pop_options.hpp>
0081 
0082 #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
0083 
0084 #endif // BOOST_ASIO_DETAIL_IMPL_WINSOCK_INIT_IPP