Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
runs-on: "windows-2022"
b2-toolset: "gcc"
generator: "MinGW Makefiles"
is-latest: true
is-latest: false
is-earliest: true
name: "MinGW"
build-type: "Release"
Expand All @@ -143,7 +143,7 @@ jobs:
runs-on: "windows-2022"
b2-toolset: "gcc"
generator: "MinGW Makefiles"
is-latest: true
is-latest: false
is-earliest: true
name: "MinGW (shared)"
shared: true
Expand Down
8 changes: 3 additions & 5 deletions include/boost/http_proto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
#include <boost/http_proto/fields_view.hpp>
#include <boost/http_proto/fields_view_base.hpp>
#include <boost/http_proto/file.hpp>
#include <boost/http_proto/file_base.hpp>
#include <boost/http_proto/file_body.hpp>
#include <boost/http_proto/file_posix.hpp>
#include <boost/http_proto/file_win32.hpp>
#include <boost/http_proto/file_stdio.hpp>
#include <boost/http_proto/file_mode.hpp>
#include <boost/http_proto/file_sink.hpp>
#include <boost/http_proto/file_source.hpp>
#include <boost/http_proto/header_limits.hpp>
#include <boost/http_proto/message_base.hpp>
#include <boost/http_proto/message_view_base.hpp>
Expand Down
116 changes: 116 additions & 0 deletions include/boost/http_proto/detail/file_posix.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
92 changes: 92 additions & 0 deletions include/boost/http_proto/detail/file_stdio.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//
// 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_STDIO_HPP
#define BOOST_HTTP_PROTO_DETAIL_FILE_STDIO_HPP

#include <boost/http_proto/detail/config.hpp>
#include <boost/http_proto/error.hpp>
#include <boost/http_proto/file_mode.hpp>
#include <cstdio>
#include <cstdint>

namespace boost {
namespace http_proto {
namespace detail {

// Implementation of File which uses cstdio.
class file_stdio
{
std::FILE* f_ = nullptr;

public:
using native_handle_type = std::FILE*;

BOOST_HTTP_PROTO_DECL
~file_stdio();

file_stdio() = default;

BOOST_HTTP_PROTO_DECL
file_stdio(file_stdio&& other) noexcept;

BOOST_HTTP_PROTO_DECL
file_stdio&
operator=(file_stdio&& other) noexcept;

std::FILE*
native_handle() const
{
return f_;
}

BOOST_HTTP_PROTO_DECL
void
native_handle(std::FILE* f);

bool
is_open() const
{
return f_ != nullptr;
}

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
108 changes: 108 additions & 0 deletions include/boost/http_proto/detail/file_win32.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// 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_WIN32_HPP
#define BOOST_HTTP_PROTO_DETAIL_FILE_WIN32_HPP

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

#if ! defined(BOOST_HTTP_PROTO_USE_WIN32_FILE)
# ifdef _WIN32
# define BOOST_HTTP_PROTO_USE_WIN32_FILE 1
# else
# define BOOST_HTTP_PROTO_USE_WIN32_FILE 0
# endif
#endif

#if BOOST_HTTP_PROTO_USE_WIN32_FILE

#include <boost/http_proto/error.hpp>
#include <boost/http_proto/file_mode.hpp>
#include <boost/winapi/basic_types.hpp>
#include <boost/winapi/handles.hpp>
#include <cstdio>
#include <cstdint>

namespace boost {
namespace http_proto {
namespace detail {

// Implementation of File for Win32.
class file_win32
{
boost::winapi::HANDLE_ h_ =
boost::winapi::INVALID_HANDLE_VALUE_;

public:
using native_handle_type = boost::winapi::HANDLE_;

BOOST_HTTP_PROTO_DECL
~file_win32();

file_win32() = default;

BOOST_HTTP_PROTO_DECL
file_win32(file_win32&& other) noexcept;

BOOST_HTTP_PROTO_DECL
file_win32&
operator=(file_win32&& other) noexcept;

native_handle_type
native_handle()
{
return h_;
}

BOOST_HTTP_PROTO_DECL
void
native_handle(native_handle_type h);

bool
is_open() const
{
return h_ != boost::winapi::INVALID_HANDLE_VALUE_;
}

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
Loading
Loading