5 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_DETAIL_SOCKET_HOLDER_HPP
12 #define BOOST_ASIO_DETAIL_SOCKET_HOLDER_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/push_options.hpp>
20 #include <boost/asio/detail/noncopyable.hpp>
21 #include <boost/asio/detail/socket_ops.hpp>
27 // Implement the resource acquisition is initialisation idiom for sockets.
32 // Construct as an uninitialised socket.
34 : socket_(invalid_socket
)
38 // Construct to take ownership of the specified socket.
39 explicit socket_holder(socket_type s
)
47 if (socket_
!= invalid_socket
)
49 boost::system::error_code ec
;
50 socket_ops::close(socket_
, ec
);
54 // Get the underlying socket.
55 socket_type
get() const
60 // Reset to an uninitialised socket.
63 if (socket_
!= invalid_socket
)
65 boost::system::error_code ec
;
66 socket_ops::close(socket_
, ec
);
67 socket_
= invalid_socket
;
71 // Reset to take ownership of the specified socket.
72 void reset(socket_type s
)
78 // Release ownership of the socket.
81 socket_type tmp
= socket_
;
82 socket_
= invalid_socket
;
87 // The underlying socket.
95 #include <boost/asio/detail/pop_options.hpp>
97 #endif // BOOST_ASIO_DETAIL_SOCKET_HOLDER_HPP