Skip to content

Commit 7538eb4

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

18 files changed

Lines changed: 523 additions & 662 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>
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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__)
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+
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+
native_handle() const
67+
{
68+
return fd_;
69+
}
70+
71+
BOOST_HTTP_PROTO_DECL
72+
void
73+
native_handle(native_handle_type fd);
74+
75+
bool
76+
is_open() const
77+
{
78+
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
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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(file_stdio&& other) noexcept;
38+
39+
BOOST_HTTP_PROTO_DECL
40+
file_stdio&
41+
operator=(file_stdio&& other) noexcept;
42+
43+
std::FILE*
44+
native_handle() const
45+
{
46+
return f_;
47+
}
48+
49+
BOOST_HTTP_PROTO_DECL
50+
void
51+
native_handle(std::FILE* f);
52+
53+
bool
54+
is_open() const
55+
{
56+
return f_ != nullptr;
57+
}
58+
59+
BOOST_HTTP_PROTO_DECL
60+
void
61+
close(system::error_code& ec);
62+
63+
BOOST_HTTP_PROTO_DECL
64+
void
65+
open(char const* path, file_mode mode, system::error_code& ec);
66+
67+
BOOST_HTTP_PROTO_DECL
68+
std::uint64_t
69+
size(system::error_code& ec) const;
70+
71+
BOOST_HTTP_PROTO_DECL
72+
std::uint64_t
73+
pos(system::error_code& ec) const;
74+
75+
BOOST_HTTP_PROTO_DECL
76+
void
77+
seek(std::uint64_t offset, system::error_code& ec);
78+
79+
BOOST_HTTP_PROTO_DECL
80+
std::size_t
81+
read(void* buffer, std::size_t n, system::error_code& ec);
82+
83+
BOOST_HTTP_PROTO_DECL
84+
std::size_t
85+
write(void const* buffer, std::size_t n, system::error_code& ec);
86+
};
87+
88+
} // detail
89+
} // http_proto
90+
} // boost
91+
92+
#endif
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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_mode.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(file_win32&& other) noexcept;
52+
53+
BOOST_HTTP_PROTO_DECL
54+
file_win32&
55+
operator=(file_win32&& other) noexcept;
56+
57+
native_handle_type
58+
native_handle()
59+
{
60+
return h_;
61+
}
62+
63+
BOOST_HTTP_PROTO_DECL
64+
void
65+
native_handle(native_handle_type h);
66+
67+
bool
68+
is_open() const
69+
{
70+
return h_ != boost::winapi::INVALID_HANDLE_VALUE_;
71+
}
72+
73+
BOOST_HTTP_PROTO_DECL
74+
void
75+
close(system::error_code& ec);
76+
77+
BOOST_HTTP_PROTO_DECL
78+
void
79+
open(char const* path, file_mode mode, system::error_code& ec);
80+
81+
BOOST_HTTP_PROTO_DECL
82+
std::uint64_t
83+
size(system::error_code& ec) const;
84+
85+
BOOST_HTTP_PROTO_DECL
86+
std::uint64_t
87+
pos(system::error_code& ec) const;
88+
89+
BOOST_HTTP_PROTO_DECL
90+
void
91+
seek(std::uint64_t offset, system::error_code& ec);
92+
93+
BOOST_HTTP_PROTO_DECL
94+
std::size_t
95+
read(void* buffer, std::size_t n, system::error_code& ec);
96+
97+
BOOST_HTTP_PROTO_DECL
98+
std::size_t
99+
write(void const* buffer, std::size_t n, system::error_code& ec);
100+
};
101+
102+
} // detail
103+
} // http_proto
104+
} // boost
105+
106+
#endif
107+
108+
#endif

0 commit comments

Comments
 (0)