File indexing completed on 2025-01-18 09:28:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_SOCKET_HOLDER_HPP
0012 #define BOOST_ASIO_DETAIL_SOCKET_HOLDER_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/detail/noncopyable.hpp>
0020 #include <boost/asio/detail/socket_ops.hpp>
0021
0022 #include <boost/asio/detail/push_options.hpp>
0023
0024 namespace boost {
0025 namespace asio {
0026 namespace detail {
0027
0028
0029 class socket_holder
0030 : private noncopyable
0031 {
0032 public:
0033
0034 socket_holder()
0035 : socket_(invalid_socket)
0036 {
0037 }
0038
0039
0040 explicit socket_holder(socket_type s)
0041 : socket_(s)
0042 {
0043 }
0044
0045
0046 ~socket_holder()
0047 {
0048 if (socket_ != invalid_socket)
0049 {
0050 boost::system::error_code ec;
0051 socket_ops::state_type state = 0;
0052 socket_ops::close(socket_, state, true, ec);
0053 }
0054 }
0055
0056
0057 socket_type get() const
0058 {
0059 return socket_;
0060 }
0061
0062
0063 void reset()
0064 {
0065 if (socket_ != invalid_socket)
0066 {
0067 boost::system::error_code ec;
0068 socket_ops::state_type state = 0;
0069 socket_ops::close(socket_, state, true, ec);
0070 socket_ = invalid_socket;
0071 }
0072 }
0073
0074
0075 void reset(socket_type s)
0076 {
0077 reset();
0078 socket_ = s;
0079 }
0080
0081
0082 socket_type release()
0083 {
0084 socket_type tmp = socket_;
0085 socket_ = invalid_socket;
0086 return tmp;
0087 }
0088
0089 private:
0090
0091 socket_type socket_;
0092 };
0093
0094 }
0095 }
0096 }
0097
0098 #include <boost/asio/detail/pop_options.hpp>
0099
0100 #endif