-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathfile_posix.hpp
More file actions
116 lines (89 loc) · 2.4 KB
/
file_posix.hpp
File metadata and controls
116 lines (89 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// Copyright (c) 2022 Vinnie Falco (vinnie.falco@gmail.com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/cppalliance/http_proto
//
#ifndef BOOST_HTTP_PROTO_DETAIL_FILE_POSIX_HPP
#define BOOST_HTTP_PROTO_DETAIL_FILE_POSIX_HPP
#include <boost/http_proto/detail/config.hpp>
#if ! defined(BOOST_HTTP_PROTO_NO_POSIX_FILE)
# if ! defined(__APPLE__) && ! defined(__linux__) && ! defined(__FreeBSD__) && ! defined(__NetBSD__)
# define BOOST_HTTP_PROTO_NO_POSIX_FILE
# endif
#endif
#if ! defined(BOOST_HTTP_PROTO_USE_POSIX_FILE)
# if ! defined(BOOST_HTTP_PROTO_NO_POSIX_FILE)
# define BOOST_HTTP_PROTO_USE_POSIX_FILE 1
# else
# define BOOST_HTTP_PROTO_USE_POSIX_FILE 0
# endif
#endif
#if BOOST_HTTP_PROTO_USE_POSIX_FILE
#include <boost/http_proto/error.hpp>
#include <boost/http_proto/file_mode.hpp>
#include <boost/system/error_code.hpp>
#include <cstdint>
namespace boost {
namespace http_proto {
namespace detail {
// Implementation of File for POSIX systems.
class file_posix
{
int fd_ = -1;
BOOST_HTTP_PROTO_DECL
static
int
native_close(int& fd);
public:
using native_handle_type = int;
BOOST_HTTP_PROTO_DECL
~file_posix();
file_posix() = default;
BOOST_HTTP_PROTO_DECL
file_posix(file_posix&& other) noexcept;
BOOST_HTTP_PROTO_DECL
file_posix&
operator=(file_posix&& other) noexcept;
native_handle_type
native_handle() const
{
return fd_;
}
BOOST_HTTP_PROTO_DECL
void
native_handle(native_handle_type fd);
bool
is_open() const
{
return fd_ != -1;
}
BOOST_HTTP_PROTO_DECL
void
close(system::error_code& ec);
BOOST_HTTP_PROTO_DECL
void
open(char const* path, file_mode mode, system::error_code& ec);
BOOST_HTTP_PROTO_DECL
std::uint64_t
size(system::error_code& ec) const;
BOOST_HTTP_PROTO_DECL
std::uint64_t
pos(system::error_code& ec) const;
BOOST_HTTP_PROTO_DECL
void
seek(std::uint64_t offset, system::error_code& ec);
BOOST_HTTP_PROTO_DECL
std::size_t
read(void* buffer, std::size_t n, system::error_code& ec);
BOOST_HTTP_PROTO_DECL
std::size_t
write(void const* buffer, std::size_t n, system::error_code& ec);
};
} // detail
} // http_proto
} // boost
#endif
#endif