~ubuntu-branches/ubuntu/maverick/libtorrent-rasterbar/maverick

« back to all changes in this revision

Viewing changes to include/libtorrent/asio/detail/socket_holder.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2010-08-10 12:59:37 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810125937-jbcmmf17y8yo9hgz
Tags: 0.15.0-0ubuntu1
* New upstream version.
* debian/patches/100_fix_html_docs.patch: refreshed.
* debian/control: bump up standards-version to 3.9.1 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// socket_holder.hpp
3
 
// ~~~~~~~~~~~~~~~~~
4
 
//
5
 
// Copyright (c) 2003-2008 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/push_options.hpp"
19
 
 
20
 
#include "asio/detail/noncopyable.hpp"
21
 
#include "asio/detail/socket_ops.hpp"
22
 
 
23
 
namespace asio {
24
 
namespace detail {
25
 
 
26
 
// Implement the resource acquisition is initialisation idiom for sockets.
27
 
class socket_holder
28
 
  : private noncopyable
29
 
{
30
 
public:
31
 
  // Construct as an uninitialised socket.
32
 
  socket_holder()
33
 
    : socket_(invalid_socket)
34
 
  {
35
 
  }
36
 
 
37
 
  // Construct to take ownership of the specified socket.
38
 
  explicit socket_holder(socket_type s)
39
 
    : socket_(s)
40
 
  {
41
 
  }
42
 
 
43
 
  // Destructor.
44
 
  ~socket_holder()
45
 
  {
46
 
    if (socket_ != invalid_socket)
47
 
    {
48
 
      asio::error_code ec;
49
 
      socket_ops::close(socket_, ec);
50
 
    }
51
 
  }
52
 
 
53
 
  // Get the underlying socket.
54
 
  socket_type get() const
55
 
  {
56
 
    return socket_;
57
 
  }
58
 
 
59
 
  // Reset to an uninitialised socket.
60
 
  void reset()
61
 
  {
62
 
    if (socket_ != invalid_socket)
63
 
    {
64
 
      asio::error_code ec;
65
 
      socket_ops::close(socket_, ec);
66
 
      socket_ = invalid_socket;
67
 
    }
68
 
  }
69
 
 
70
 
  // Reset to take ownership of the specified socket.
71
 
  void reset(socket_type s)
72
 
  {
73
 
    reset();
74
 
    socket_ = s;
75
 
  }
76
 
 
77
 
  // Release ownership of the socket.
78
 
  socket_type release()
79
 
  {
80
 
    socket_type tmp = socket_;
81
 
    socket_ = invalid_socket;
82
 
    return tmp;
83
 
  }
84
 
 
85
 
private:
86
 
  // The underlying socket.
87
 
  socket_type socket_;
88
 
};
89
 
 
90
 
} // namespace detail
91
 
} // namespace asio
92
 
 
93
 
#include "asio/detail/pop_options.hpp"
94
 
 
95
 
#endif // ASIO_DETAIL_SOCKET_HOLDER_HPP