ゴミ箱
file_posix.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2015-2016 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/boostorg/beast
8 //
9 
10 #ifndef BOOST_BEAST_CORE_FILE_POSIX_HPP
11 #define BOOST_BEAST_CORE_FILE_POSIX_HPP
12 
13 #include <boost/config.hpp>
14 
15 #if ! defined(BOOST_BEAST_NO_POSIX_FILE)
16 # if ! defined(__APPLE__) && ! defined(__linux__)
17 # define BOOST_BEAST_NO_POSIX_FILE
18 # endif
19 #endif
20 
21 #if ! defined(BOOST_BEAST_USE_POSIX_FILE)
22 # if ! defined(BOOST_BEAST_NO_POSIX_FILE)
23 # define BOOST_BEAST_USE_POSIX_FILE 1
24 # else
25 # define BOOST_BEAST_USE_POSIX_FILE 0
26 # endif
27 #endif
28 
29 #if BOOST_BEAST_USE_POSIX_FILE
30 
33 #include <cstdint>
34 
35 namespace boost {
36 namespace beast {
37 
42 class file_posix
43 {
44  int fd_ = -1;
45 
46 public:
51  using native_handle_type = int;
52 
57  ~file_posix();
58 
63  file_posix() = default;
64 
69  file_posix(file_posix&& other);
70 
75  file_posix& operator=(file_posix&& other);
76 
78  native_handle_type
79  native_handle() const
80  {
81  return fd_;
82  }
83 
90  void
91  native_handle(native_handle_type fd);
92 
94  bool
95  is_open() const
96  {
97  return fd_ != -1;
98  }
99 
104  void
105  close(error_code& ec);
106 
115  void
116  open(char const* path, file_mode mode, error_code& ec);
117 
124  std::uint64_t
125  size(error_code& ec) const;
126 
133  std::uint64_t
134  pos(error_code& ec) const;
135 
142  void
143  seek(std::uint64_t offset, error_code& ec);
144 
153  std::size_t
154  read(void* buffer, std::size_t n, error_code& ec) const;
155 
164  std::size_t
165  write(void const* buffer, std::size_t n, error_code& ec);
166 };
167 
168 } // beast
169 } // boost
170 
172 
173 #endif
174 
175 #endif
file_mode
Definition: file_base.hpp:26
Definition: async_result.hpp:20
boost::system::error_code error_code
The type of error code used by the library.
Definition: error.hpp:21