Realistic 3D camera system
3D camera system components
socket_holder.hpp
Go to the documentation of this file.
1 //
2 // detail/socket_holder.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 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 
11 #ifndef ASIO_DETAIL_SOCKET_HOLDER_HPP
12 #define ASIO_DETAIL_SOCKET_HOLDER_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
21 
23 
24 namespace asio {
25 namespace detail {
26 
27 // Implement the resource acquisition is initialisation idiom for sockets.
29  : private noncopyable
30 {
31 public:
32  // Construct as an uninitialised socket.
34  : socket_(invalid_socket)
35  {
36  }
37 
38  // Construct to take ownership of the specified socket.
40  : socket_(s)
41  {
42  }
43 
44  // Destructor.
46  {
47  if (socket_ != invalid_socket)
48  {
50  socket_ops::state_type state = 0;
51  socket_ops::close(socket_, state, true, ec);
52  }
53  }
54 
55  // Get the underlying socket.
56  socket_type get() const
57  {
58  return socket_;
59  }
60 
61  // Reset to an uninitialised socket.
62  void reset()
63  {
64  if (socket_ != invalid_socket)
65  {
67  socket_ops::state_type state = 0;
68  socket_ops::close(socket_, state, true, ec);
69  socket_ = invalid_socket;
70  }
71  }
72 
73  // Reset to take ownership of the specified socket.
75  {
76  reset();
77  socket_ = s;
78  }
79 
80  // Release ownership of the socket.
82  {
83  socket_type tmp = socket_;
84  socket_ = invalid_socket;
85  return tmp;
86  }
87 
88 private:
89  // The underlying socket.
90  socket_type socket_;
91 };
92 
93 } // namespace detail
94 } // namespace asio
95 
97 
98 #endif // ASIO_DETAIL_SOCKET_HOLDER_HPP
SocketService & s
Definition: connect.hpp:521
unsigned char state_type
Definition: socket_ops.hpp:59
Class to represent an error code value.
Definition: error_code.hpp:80
const int invalid_socket
void reset(socket_type s)
int close(socket_type s, state_type &state, bool destruction, asio::error_code &ec)
Definition: socket_ops.ipp:295