]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/beast/core/file_win32.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / beast / core / file_win32.hpp
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_WIN32_HPP
11 #define BOOST_BEAST_CORE_FILE_WIN32_HPP
12
13 #include <boost/config.hpp>
14
15 #if ! defined(BOOST_BEAST_USE_WIN32_FILE)
16 # ifdef BOOST_MSVC
17 # define BOOST_BEAST_USE_WIN32_FILE 1
18 # else
19 # define BOOST_BEAST_USE_WIN32_FILE 0
20 # endif
21 #endif
22
23 #if BOOST_BEAST_USE_WIN32_FILE
24
25 #include <boost/beast/core/error.hpp>
26 #include <boost/beast/core/file_base.hpp>
27 #include <boost/winapi/basic_types.hpp>
28 #include <boost/winapi/handles.hpp>
29 #include <cstdio>
30 #include <cstdint>
31
32 namespace boost {
33 namespace beast {
34
35 /** An implementation of File for Win32.
36
37 This class implements a @b File using Win32 native interfaces.
38 */
39 class file_win32
40 {
41 boost::winapi::HANDLE_ h_ =
42 boost::winapi::INVALID_HANDLE_VALUE_;
43
44 public:
45 /** The type of the underlying file handle.
46
47 This is platform-specific.
48 */
49 #if BOOST_BEAST_DOXYGEN
50 using native_handle_type = HANDLE;
51 #else
52 using native_handle_type = boost::winapi::HANDLE_;
53 #endif
54
55 /** Destructor
56
57 If the file is open it is first closed.
58 */
59 ~file_win32();
60
61 /** Constructor
62
63 There is no open file initially.
64 */
65 file_win32() = default;
66
67 /** Constructor
68
69 The moved-from object behaves as if default constructed.
70 */
71 file_win32(file_win32&& other);
72
73 /** Assignment
74
75 The moved-from object behaves as if default constructed.
76 */
77 file_win32& operator=(file_win32&& other);
78
79 /// Returns the native handle associated with the file.
80 native_handle_type
81 native_handle()
82 {
83 return h_;
84 }
85
86 /** Set the native handle associated with the file.
87
88 If the file is open it is first closed.
89
90 @param h The native file handle to assign.
91 */
92 void
93 native_handle(native_handle_type h);
94
95 /// Returns `true` if the file is open
96 bool
97 is_open() const
98 {
99 return h_ != boost::winapi::INVALID_HANDLE_VALUE_;
100 }
101
102 /** Close the file if open
103
104 @param ec Set to the error, if any occurred.
105 */
106 void
107 close(error_code& ec);
108
109 /** Open a file at the given path with the specified mode
110
111 @param path The utf-8 encoded path to the file
112
113 @param mode The file mode to use
114
115 @param ec Set to the error, if any occurred
116 */
117 void
118 open(char const* path, file_mode mode, error_code& ec);
119
120 /** Return the size of the open file
121
122 @param ec Set to the error, if any occurred
123
124 @return The size in bytes
125 */
126 std::uint64_t
127 size(error_code& ec) const;
128
129 /** Return the current position in the open file
130
131 @param ec Set to the error, if any occurred
132
133 @return The offset in bytes from the beginning of the file
134 */
135 std::uint64_t
136 pos(error_code& ec);
137
138 /** Adjust the current position in the open file
139
140 @param offset The offset in bytes from the beginning of the file
141
142 @param ec Set to the error, if any occurred
143 */
144 void
145 seek(std::uint64_t offset, error_code& ec);
146
147 /** Read from the open file
148
149 @param buffer The buffer for storing the result of the read
150
151 @param n The number of bytes to read
152
153 @param ec Set to the error, if any occurred
154 */
155 std::size_t
156 read(void* buffer, std::size_t n, error_code& ec);
157
158 /** Write to the open file
159
160 @param buffer The buffer holding the data to write
161
162 @param n The number of bytes to write
163
164 @param ec Set to the error, if any occurred
165 */
166 std::size_t
167 write(void const* buffer, std::size_t n, error_code& ec);
168 };
169
170 } // beast
171 } // boost
172
173 #include <boost/beast/core/impl/file_win32.ipp>
174
175 #endif
176
177 #endif