123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- #ifndef BOOST_ASIO_DETAIL_WINSOCK_INIT_HPP
- #define BOOST_ASIO_DETAIL_WINSOCK_INIT_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif
- #include <boost/asio/detail/push_options.hpp>
- #include <boost/asio/detail/push_options.hpp>
- #include <boost/config.hpp>
- #include <boost/system/system_error.hpp>
- #include <boost/asio/detail/pop_options.hpp>
- #if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
- #include <boost/asio/detail/push_options.hpp>
- #include <boost/shared_ptr.hpp>
- #include <boost/throw_exception.hpp>
- #include <boost/asio/detail/pop_options.hpp>
- #include <boost/asio/error.hpp>
- #include <boost/asio/detail/noncopyable.hpp>
- #include <boost/asio/detail/socket_types.hpp>
- namespace boost {
- namespace asio {
- namespace detail {
- template <int Major = 2, int Minor = 0>
- class winsock_init
- : private noncopyable
- {
- private:
-
- struct do_init
- {
- do_init()
- {
- WSADATA wsa_data;
- result_ = ::WSAStartup(MAKEWORD(Major, Minor), &wsa_data);
- }
- ~do_init()
- {
- ::WSACleanup();
- }
- int result() const
- {
- return result_;
- }
-
-
-
-
-
- static boost::shared_ptr<do_init> instance()
- {
- static boost::shared_ptr<do_init> init(new do_init);
- return init;
- }
- private:
- int result_;
- };
- public:
-
- winsock_init()
- : ref_(do_init::instance())
- {
-
-
-
- if (this != &instance_ && ref_->result() != 0)
- {
- boost::system::system_error e(
- boost::system::error_code(ref_->result(),
- boost::asio::error::get_system_category()),
- "winsock");
- boost::throw_exception(e);
- }
- }
-
- ~winsock_init()
- {
- }
- private:
-
- static winsock_init instance_;
-
-
- boost::shared_ptr<do_init> ref_;
- };
- template <int Major, int Minor>
- winsock_init<Major, Minor> winsock_init<Major, Minor>::instance_;
- }
- }
- }
- #endif
- #include <boost/asio/detail/pop_options.hpp>
- #endif
|