Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / detail / socket_holder.hpp @ 2486

History | View | Annotate | Download (2.1 kB)

1 2486 sjacqu01
//
2 2486 sjacqu01
// detail/socket_holder.hpp
3 2486 sjacqu01
// ~~~~~~~~~~~~~~~~~~~~~~~~
4 2486 sjacqu01
//
5 2486 sjacqu01
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 2486 sjacqu01
//
7 2486 sjacqu01
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8 2486 sjacqu01
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 2486 sjacqu01
//
10 2486 sjacqu01
11 2486 sjacqu01
#ifndef BOOST_ASIO_DETAIL_SOCKET_HOLDER_HPP
12 2486 sjacqu01
#define BOOST_ASIO_DETAIL_SOCKET_HOLDER_HPP
13 2486 sjacqu01
14 2486 sjacqu01
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 2486 sjacqu01
# pragma once
16 2486 sjacqu01
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 2486 sjacqu01
18 2486 sjacqu01
#include <boost/asio/detail/config.hpp>
19 2486 sjacqu01
#include <boost/asio/detail/noncopyable.hpp>
20 2486 sjacqu01
#include <boost/asio/detail/socket_ops.hpp>
21 2486 sjacqu01
22 2486 sjacqu01
#include <boost/asio/detail/push_options.hpp>
23 2486 sjacqu01
24 2486 sjacqu01
namespace boost {
25 2486 sjacqu01
namespace asio {
26 2486 sjacqu01
namespace detail {
27 2486 sjacqu01
28 2486 sjacqu01
// Implement the resource acquisition is initialisation idiom for sockets.
29 2486 sjacqu01
class socket_holder
30 2486 sjacqu01
  : private noncopyable
31 2486 sjacqu01
{
32 2486 sjacqu01
public:
33 2486 sjacqu01
  // Construct as an uninitialised socket.
34 2486 sjacqu01
  socket_holder()
35 2486 sjacqu01
    : socket_(invalid_socket)
36 2486 sjacqu01
  {
37 2486 sjacqu01
  }
38 2486 sjacqu01
39 2486 sjacqu01
  // Construct to take ownership of the specified socket.
40 2486 sjacqu01
  explicit socket_holder(socket_type s)
41 2486 sjacqu01
    : socket_(s)
42 2486 sjacqu01
  {
43 2486 sjacqu01
  }
44 2486 sjacqu01
45 2486 sjacqu01
  // Destructor.
46 2486 sjacqu01
  ~socket_holder()
47 2486 sjacqu01
  {
48 2486 sjacqu01
    if (socket_ != invalid_socket)
49 2486 sjacqu01
    {
50 2486 sjacqu01
      boost::system::error_code ec;
51 2486 sjacqu01
      socket_ops::state_type state = 0;
52 2486 sjacqu01
      socket_ops::close(socket_, state, true, ec);
53 2486 sjacqu01
    }
54 2486 sjacqu01
  }
55 2486 sjacqu01
56 2486 sjacqu01
  // Get the underlying socket.
57 2486 sjacqu01
  socket_type get() const
58 2486 sjacqu01
  {
59 2486 sjacqu01
    return socket_;
60 2486 sjacqu01
  }
61 2486 sjacqu01
62 2486 sjacqu01
  // Reset to an uninitialised socket.
63 2486 sjacqu01
  void reset()
64 2486 sjacqu01
  {
65 2486 sjacqu01
    if (socket_ != invalid_socket)
66 2486 sjacqu01
    {
67 2486 sjacqu01
      boost::system::error_code ec;
68 2486 sjacqu01
      socket_ops::state_type state = 0;
69 2486 sjacqu01
      socket_ops::close(socket_, state, true, ec);
70 2486 sjacqu01
      socket_ = invalid_socket;
71 2486 sjacqu01
    }
72 2486 sjacqu01
  }
73 2486 sjacqu01
74 2486 sjacqu01
  // Reset to take ownership of the specified socket.
75 2486 sjacqu01
  void reset(socket_type s)
76 2486 sjacqu01
  {
77 2486 sjacqu01
    reset();
78 2486 sjacqu01
    socket_ = s;
79 2486 sjacqu01
  }
80 2486 sjacqu01
81 2486 sjacqu01
  // Release ownership of the socket.
82 2486 sjacqu01
  socket_type release()
83 2486 sjacqu01
  {
84 2486 sjacqu01
    socket_type tmp = socket_;
85 2486 sjacqu01
    socket_ = invalid_socket;
86 2486 sjacqu01
    return tmp;
87 2486 sjacqu01
  }
88 2486 sjacqu01
89 2486 sjacqu01
private:
90 2486 sjacqu01
  // The underlying socket.
91 2486 sjacqu01
  socket_type socket_;
92 2486 sjacqu01
};
93 2486 sjacqu01
94 2486 sjacqu01
} // namespace detail
95 2486 sjacqu01
} // namespace asio
96 2486 sjacqu01
} // namespace boost
97 2486 sjacqu01
98 2486 sjacqu01
#include <boost/asio/detail/pop_options.hpp>
99 2486 sjacqu01
100 2486 sjacqu01
#endif // BOOST_ASIO_DETAIL_SOCKET_HOLDER_HPP