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 ASIO_DETAIL_SOCKET_HOLDER_HPP
12
#define ASIO_DETAIL_SOCKET_HOLDER_HPP
14
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
16
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18
#include "asio/detail/push_options.hpp"
20
#include "asio/detail/noncopyable.hpp"
21
#include "asio/detail/socket_ops.hpp"
26
// Implement the resource acquisition is initialisation idiom for sockets.
31
// Construct as an uninitialised socket.
33
: socket_(invalid_socket)
37
// Construct to take ownership of the specified socket.
38
explicit socket_holder(socket_type s)
46
if (socket_ != invalid_socket)
49
socket_ops::close(socket_, ec);
53
// Get the underlying socket.
54
socket_type get() const
59
// Reset to an uninitialised socket.
62
if (socket_ != invalid_socket)
65
socket_ops::close(socket_, ec);
66
socket_ = invalid_socket;
70
// Reset to take ownership of the specified socket.
71
void reset(socket_type s)
77
// Release ownership of the socket.
80
socket_type tmp = socket_;
81
socket_ = invalid_socket;
86
// The underlying socket.
93
#include "asio/detail/pop_options.hpp"
95
#endif // ASIO_DETAIL_SOCKET_HOLDER_HPP