Skip to content

Commit be19864

Browse files
committed
move implementations of file type to detail
1 parent 90e9a05 commit be19864

17 files changed

Lines changed: 414 additions & 547 deletions

include/boost/http_proto.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@
1818
#include <boost/http_proto/fields_view.hpp>
1919
#include <boost/http_proto/fields_view_base.hpp>
2020
#include <boost/http_proto/file.hpp>
21-
#include <boost/http_proto/file_base.hpp>
22-
#include <boost/http_proto/file_posix.hpp>
21+
#include <boost/http_proto/file_mode.hpp>
2322
#include <boost/http_proto/file_sink.hpp>
2423
#include <boost/http_proto/file_source.hpp>
25-
#include <boost/http_proto/file_stdio.hpp>
26-
#include <boost/http_proto/file_win32.hpp>
2724
#include <boost/http_proto/header_limits.hpp>
2825
#include <boost/http_proto/message_base.hpp>
2926
#include <boost/http_proto/message_view_base.hpp>

include/boost/http_proto/file_posix.hpp renamed to include/boost/http_proto/detail/file_posix.hpp

Lines changed: 6 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
// Official repository: https://github.com/cppalliance/http_proto
88
//
99

10-
#ifndef BOOST_HTTP_PROTO_FILE_POSIX_HPP
11-
#define BOOST_HTTP_PROTO_FILE_POSIX_HPP
10+
#ifndef BOOST_HTTP_PROTO_DETAIL_FILE_POSIX_HPP
11+
#define BOOST_HTTP_PROTO_DETAIL_FILE_POSIX_HPP
1212

1313
#include <boost/http_proto/detail/config.hpp>
1414

@@ -29,17 +29,15 @@
2929
#if BOOST_HTTP_PROTO_USE_POSIX_FILE
3030

3131
#include <boost/http_proto/error.hpp>
32-
#include <boost/http_proto/file_base.hpp>
32+
#include <boost/http_proto/file_mode.hpp>
3333
#include <boost/system/error_code.hpp>
3434
#include <cstdint>
3535

3636
namespace boost {
3737
namespace http_proto {
38+
namespace detail {
3839

39-
/** An implementation of File for POSIX systems.
40-
41-
This class implements a <em>File</em> using POSIX interfaces.
42-
*/
40+
// Implementation of File for POSIX systems.
4341
class file_posix
4442
{
4543
int fd_ = -1;
@@ -50,141 +48,68 @@ class file_posix
5048
native_close(int& fd);
5149

5250
public:
53-
/** The type of the underlying file handle.
54-
55-
This is platform-specific.
56-
*/
5751
using native_handle_type = int;
5852

59-
/** Destructor
60-
61-
If the file is open it is first closed.
62-
*/
6353
BOOST_HTTP_PROTO_DECL
6454
~file_posix();
6555

66-
/** Constructor
67-
68-
There is no open file initially.
69-
*/
7056
file_posix() = default;
7157

72-
/** Constructor
73-
74-
The moved-from object behaves as if default constructed.
75-
*/
7658
BOOST_HTTP_PROTO_DECL
7759
file_posix(
7860
file_posix&& other) noexcept;
7961

80-
/** Assignment
81-
82-
The moved-from object behaves as if default constructed.
83-
*/
8462
BOOST_HTTP_PROTO_DECL
8563
file_posix&
8664
operator=(
8765
file_posix&& other) noexcept;
8866

89-
/// Returns the native handle associated with the file.
9067
native_handle_type
9168
native_handle() const
9269
{
9370
return fd_;
9471
}
9572

96-
/** Set the native handle associated with the file.
97-
98-
If the file is open it is first closed.
99-
100-
@param fd The native file handle to assign.
101-
*/
10273
BOOST_HTTP_PROTO_DECL
10374
void
10475
native_handle(native_handle_type fd);
10576

106-
/// Returns `true` if the file is open
10777
bool
10878
is_open() const
10979
{
11080
return fd_ != -1;
11181
}
11282

113-
/** Close the file if open
114-
115-
@param ec Set to the error, if any occurred.
116-
*/
11783
BOOST_HTTP_PROTO_DECL
11884
void
11985
close(system::error_code& ec);
12086

121-
/** Open a file at the given path with the specified mode
122-
123-
@param path The utf-8 encoded path to the file
124-
125-
@param mode The file mode to use
126-
127-
@param ec Set to the error, if any occurred
128-
*/
12987
BOOST_HTTP_PROTO_DECL
13088
void
13189
open(char const* path, file_mode mode, system::error_code& ec);
13290

133-
/** Return the size of the open file
134-
135-
@param ec Set to the error, if any occurred
136-
137-
@return The size in bytes
138-
*/
13991
BOOST_HTTP_PROTO_DECL
14092
std::uint64_t
14193
size(system::error_code& ec) const;
14294

143-
/** Return the current position in the open file
144-
145-
@param ec Set to the error, if any occurred
146-
147-
@return The offset in bytes from the beginning of the file
148-
*/
14995
BOOST_HTTP_PROTO_DECL
15096
std::uint64_t
15197
pos(system::error_code& ec) const;
15298

153-
/** Adjust the current position in the open file
154-
155-
@param offset The offset in bytes from the beginning of the file
156-
157-
@param ec Set to the error, if any occurred
158-
*/
15999
BOOST_HTTP_PROTO_DECL
160100
void
161101
seek(std::uint64_t offset, system::error_code& ec);
162102

163-
/** Read from the open file
164-
165-
@param buffer The buffer for storing the result of the read
166-
167-
@param n The number of bytes to read
168-
169-
@param ec Set to the error, if any occurred
170-
*/
171103
BOOST_HTTP_PROTO_DECL
172104
std::size_t
173105
read(void* buffer, std::size_t n, system::error_code& ec) const;
174106

175-
/** Write to the open file
176-
177-
@param buffer The buffer holding the data to write
178-
179-
@param n The number of bytes to write
180-
181-
@param ec Set to the error, if any occurred
182-
*/
183107
BOOST_HTTP_PROTO_DECL
184108
std::size_t
185109
write(void const* buffer, std::size_t n, system::error_code& ec);
186110
};
187111

112+
} // detail
188113
} // http_proto
189114
} // boost
190115

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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_STDIO_HPP
11+
#define BOOST_HTTP_PROTO_DETAIL_FILE_STDIO_HPP
12+
13+
#include <boost/http_proto/detail/config.hpp>
14+
#include <boost/http_proto/error.hpp>
15+
#include <boost/http_proto/file_mode.hpp>
16+
#include <cstdio>
17+
#include <cstdint>
18+
19+
namespace boost {
20+
namespace http_proto {
21+
namespace detail {
22+
23+
// Implementation of File which uses cstdio.
24+
class file_stdio
25+
{
26+
std::FILE* f_ = nullptr;
27+
28+
public:
29+
using native_handle_type = std::FILE*;
30+
31+
BOOST_HTTP_PROTO_DECL
32+
~file_stdio();
33+
34+
file_stdio() = default;
35+
36+
BOOST_HTTP_PROTO_DECL
37+
file_stdio(
38+
file_stdio&& other) noexcept;
39+
40+
BOOST_HTTP_PROTO_DECL
41+
file_stdio&
42+
operator=(
43+
file_stdio&& other) noexcept;
44+
45+
std::FILE*
46+
native_handle() const
47+
{
48+
return f_;
49+
}
50+
51+
BOOST_HTTP_PROTO_DECL
52+
void
53+
native_handle(std::FILE* f);
54+
55+
bool
56+
is_open() const
57+
{
58+
return f_ != nullptr;
59+
}
60+
61+
BOOST_HTTP_PROTO_DECL
62+
void
63+
close(system::error_code& ec);
64+
65+
BOOST_HTTP_PROTO_DECL
66+
void
67+
open(char const* path, file_mode mode, system::error_code& ec);
68+
69+
BOOST_HTTP_PROTO_DECL
70+
std::uint64_t
71+
size(system::error_code& ec) const;
72+
73+
BOOST_HTTP_PROTO_DECL
74+
std::uint64_t
75+
pos(system::error_code& ec) const;
76+
77+
BOOST_HTTP_PROTO_DECL
78+
void
79+
seek(std::uint64_t offset, system::error_code& ec);
80+
81+
BOOST_HTTP_PROTO_DECL
82+
std::size_t
83+
read(void* buffer, std::size_t n, system::error_code& ec) const;
84+
85+
BOOST_HTTP_PROTO_DECL
86+
std::size_t
87+
write(void const* buffer, std::size_t n, system::error_code& ec);
88+
};
89+
90+
} // detail
91+
} // http_proto
92+
} // boost
93+
94+
#endif
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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_WIN32_HPP
11+
#define BOOST_HTTP_PROTO_DETAIL_FILE_WIN32_HPP
12+
13+
#include <boost/http_proto/detail/config.hpp>
14+
15+
#if ! defined(BOOST_HTTP_PROTO_USE_WIN32_FILE)
16+
# ifdef _WIN32
17+
# define BOOST_HTTP_PROTO_USE_WIN32_FILE 1
18+
# else
19+
# define BOOST_HTTP_PROTO_USE_WIN32_FILE 0
20+
# endif
21+
#endif
22+
23+
#if BOOST_HTTP_PROTO_USE_WIN32_FILE
24+
25+
#include <boost/http_proto/error.hpp>
26+
#include <boost/http_proto/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 http_proto {
34+
namespace detail {
35+
36+
// Implementation of File for Win32.
37+
class file_win32
38+
{
39+
boost::winapi::HANDLE_ h_ =
40+
boost::winapi::INVALID_HANDLE_VALUE_;
41+
42+
public:
43+
using native_handle_type = boost::winapi::HANDLE_;
44+
45+
BOOST_HTTP_PROTO_DECL
46+
~file_win32();
47+
48+
file_win32() = default;
49+
50+
BOOST_HTTP_PROTO_DECL
51+
file_win32(
52+
file_win32&& other) noexcept;
53+
54+
BOOST_HTTP_PROTO_DECL
55+
file_win32&
56+
operator=(
57+
file_win32&& other) noexcept;
58+
59+
native_handle_type
60+
native_handle()
61+
{
62+
return h_;
63+
}
64+
65+
BOOST_HTTP_PROTO_DECL
66+
void
67+
native_handle(native_handle_type h);
68+
69+
bool
70+
is_open() const
71+
{
72+
return h_ != boost::winapi::INVALID_HANDLE_VALUE_;
73+
}
74+
75+
BOOST_HTTP_PROTO_DECL
76+
void
77+
close(system::error_code& ec);
78+
79+
BOOST_HTTP_PROTO_DECL
80+
void
81+
open(char const* path, file_mode mode, system::error_code& ec);
82+
83+
BOOST_HTTP_PROTO_DECL
84+
std::uint64_t
85+
size(system::error_code& ec) const;
86+
87+
BOOST_HTTP_PROTO_DECL
88+
std::uint64_t
89+
pos(system::error_code& ec);
90+
91+
BOOST_HTTP_PROTO_DECL
92+
void
93+
seek(std::uint64_t offset, system::error_code& ec);
94+
95+
BOOST_HTTP_PROTO_DECL
96+
std::size_t
97+
read(void* buffer, std::size_t n, system::error_code& ec);
98+
99+
BOOST_HTTP_PROTO_DECL
100+
std::size_t
101+
write(void const* buffer, std::size_t n, system::error_code& ec);
102+
};
103+
104+
} // detail
105+
} // http_proto
106+
} // boost
107+
108+
#endif
109+
110+
#endif

0 commit comments

Comments
 (0)