Line data Source code
1 : //
2 : // Copyright (c) 2022 Vinnie Falco (vinnie.falco@gmail.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/cppalliance/http_proto
8 : //
9 :
10 : #ifndef BOOST_HTTP_PROTO_DETAIL_FILE_POSIX_HPP
11 : #define BOOST_HTTP_PROTO_DETAIL_FILE_POSIX_HPP
12 :
13 : #include <boost/http_proto/detail/config.hpp>
14 :
15 : #if ! defined(BOOST_HTTP_PROTO_NO_POSIX_FILE)
16 : # if ! defined(__APPLE__) && ! defined(__linux__) && ! defined(__FreeBSD__) && ! defined(__NetBSD__)
17 : # define BOOST_HTTP_PROTO_NO_POSIX_FILE
18 : # endif
19 : #endif
20 :
21 : #if ! defined(BOOST_HTTP_PROTO_USE_POSIX_FILE)
22 : # if ! defined(BOOST_HTTP_PROTO_NO_POSIX_FILE)
23 : # define BOOST_HTTP_PROTO_USE_POSIX_FILE 1
24 : # else
25 : # define BOOST_HTTP_PROTO_USE_POSIX_FILE 0
26 : # endif
27 : #endif
28 :
29 : #if BOOST_HTTP_PROTO_USE_POSIX_FILE
30 :
31 : #include <boost/http_proto/error.hpp>
32 : #include <boost/http_proto/file_mode.hpp>
33 : #include <boost/system/error_code.hpp>
34 : #include <cstdint>
35 :
36 : namespace boost {
37 : namespace http_proto {
38 : namespace detail {
39 :
40 : // Implementation of File for POSIX systems.
41 : class file_posix
42 : {
43 : int fd_ = -1;
44 :
45 : BOOST_HTTP_PROTO_DECL
46 : static
47 : int
48 : native_close(int& fd);
49 :
50 : public:
51 : using native_handle_type = int;
52 :
53 : BOOST_HTTP_PROTO_DECL
54 : ~file_posix();
55 :
56 1 : file_posix() = default;
57 :
58 : BOOST_HTTP_PROTO_DECL
59 : file_posix(file_posix&& other) noexcept;
60 :
61 : BOOST_HTTP_PROTO_DECL
62 : file_posix&
63 : operator=(file_posix&& other) noexcept;
64 :
65 : native_handle_type
66 4 : native_handle() const
67 : {
68 4 : return fd_;
69 : }
70 :
71 : BOOST_HTTP_PROTO_DECL
72 : void
73 : native_handle(native_handle_type fd);
74 :
75 : bool
76 22 : is_open() const
77 : {
78 22 : return fd_ != -1;
79 : }
80 :
81 : BOOST_HTTP_PROTO_DECL
82 : void
83 : close(system::error_code& ec);
84 :
85 : BOOST_HTTP_PROTO_DECL
86 : void
87 : open(char const* path, file_mode mode, system::error_code& ec);
88 :
89 : BOOST_HTTP_PROTO_DECL
90 : std::uint64_t
91 : size(system::error_code& ec) const;
92 :
93 : BOOST_HTTP_PROTO_DECL
94 : std::uint64_t
95 : pos(system::error_code& ec) const;
96 :
97 : BOOST_HTTP_PROTO_DECL
98 : void
99 : seek(std::uint64_t offset, system::error_code& ec);
100 :
101 : BOOST_HTTP_PROTO_DECL
102 : std::size_t
103 : read(void* buffer, std::size_t n, system::error_code& ec);
104 :
105 : BOOST_HTTP_PROTO_DECL
106 : std::size_t
107 : write(void const* buffer, std::size_t n, system::error_code& ec);
108 : };
109 :
110 : } // detail
111 : } // http_proto
112 : } // boost
113 :
114 : #endif
115 :
116 : #endif
|