/Src/Dependencies/Boost/boost/asio/detail/impl/winsock_init.ipp

http://hadesmem.googlecode.com/ · C++ Header · 71 lines · 48 code · 14 blank · 9 comment · 8 complexity · 6a8abac8f188863a1a9d0c21241be54b MD5 · raw file

  1. //
  2. // detail/impl/winsock_init.ipp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2011 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  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)
  9. //
  10. #ifndef BOOST_ASIO_DETAIL_IMPL_WINSOCK_INIT_IPP
  11. #define BOOST_ASIO_DETAIL_IMPL_WINSOCK_INIT_IPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
  17. #include <boost/asio/detail/socket_types.hpp>
  18. #include <boost/asio/detail/winsock_init.hpp>
  19. #include <boost/asio/detail/throw_error.hpp>
  20. #include <boost/asio/error.hpp>
  21. #include <boost/asio/detail/push_options.hpp>
  22. namespace boost {
  23. namespace asio {
  24. namespace detail {
  25. void winsock_init_base::startup(data& d,
  26. unsigned char major, unsigned char minor)
  27. {
  28. if (::InterlockedIncrement(&d.init_count_) == 1)
  29. {
  30. WSADATA wsa_data;
  31. long result = ::WSAStartup(MAKEWORD(major, minor), &wsa_data);
  32. ::InterlockedExchange(&d.result_, result);
  33. }
  34. }
  35. void winsock_init_base::cleanup(data& d)
  36. {
  37. if (::InterlockedDecrement(&d.init_count_) == 0)
  38. {
  39. ::WSACleanup();
  40. }
  41. }
  42. void winsock_init_base::throw_on_error(data& d)
  43. {
  44. long result = ::InterlockedExchangeAdd(&d.result_, 0);
  45. if (result != 0)
  46. {
  47. boost::system::error_code ec(result,
  48. boost::asio::error::get_system_category());
  49. boost::asio::detail::throw_error(ec, "winsock");
  50. }
  51. }
  52. } // namespace detail
  53. } // namespace asio
  54. } // namespace boost
  55. #include <boost/asio/detail/pop_options.hpp>
  56. #endif // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
  57. #endif // BOOST_ASIO_DETAIL_IMPL_WINSOCK_INIT_IPP