26#ifndef MYSQL_HARNESS_NET_TS_IMPL_FILE_H_
27#define MYSQL_HARNESS_NET_TS_IMPL_FILE_H_
30#include <system_error>
59 return {
static_cast<int>(GetLastError()), std::system_category()};
61 return {errno, std::generic_category()};
65template <
int Name,
class Arg>
72 constexpr int name()
const {
return Name; }
87 constexpr int name()
const {
return Name; }
89 constexpr int value()
const {
return 0; }
124template <
class FileControlOption>
128 if (-1 == (res = ::
fcntl(fd, cmd.name(), cmd.value()))) {
145 std::array<file_handle_type, 2> fds{};
153 if (0 == ::CreatePipe(&fds[0], &fds[1],
nullptr, 0)) {
156#elif defined(__linux__) || defined(__FreeBSD__)
160 if (0 != ::pipe2(fds.data(),
flags)) {
164 if (0 != ::
pipe(fds.data())) {
169 auto fcntl_res =
fcntl(fds[0], fl);
177 fcntl_res =
fcntl(fds[1], fl);
186 return std::make_pair(fds[0], fds[1]);
199 if (0 == ::WriteFile(
handle,
buf, buf_len, &transfered,
nullptr)) {
204 if (-1 == transfered) {
218 void *
buf,
size_t buf_len) {
221 if (0 == ::ReadFile(
handle,
buf, buf_len, &transfered,
nullptr)) {
226 if (-1 == transfered) {
void arg_type
Definition: file.h:83
constexpr int value() const
Definition: file.h:89
file_control_option()=default
constexpr int name() const
Definition: file.h:87
file_control_option(value_type v)
Definition: file.h:70
Arg value_type
Definition: file.h:68
value_type v_
Definition: file.h:77
constexpr value_type value() const
Definition: file.h:74
constexpr int name() const
Definition: file.h:72
Definition: expected.h:286
static int flags[50]
Definition: hp_test1.cc:40
Definition: buf0block_hint.cc:30
Definition: http_server_component.cc:34
stdx::expected< int, std::error_code > fcntl(file_handle_type fd, const FileControlOption &cmd)
Definition: file.h:125
stdx::expected< size_t, std::error_code > read(file_handle_type handle, void *buf, size_t buf_len)
read from file handle into a buffer.
Definition: file.h:217
int file_handle_type
Definition: file.h:53
constexpr file_handle_type kInvalidHandle
Definition: file.h:54
std::error_code last_error_code()
Definition: file.h:57
stdx::expected< std::pair< file_handle_type, file_handle_type >, std::error_code > pipe(int flags=0)
create pipe.
Definition: file.h:144
stdx::expected< size_t, std::error_code > write(file_handle_type handle, const void *buf, size_t buf_len)
write a buffer to a file handle.
Definition: file.h:194
stdx::expected< void, std::error_code > close(file_handle_type native_handle)
close file handle.
Definition: file.h:239
std::error_code make_error_code(net::stream_errc e) noexcept
Definition: buffer.h:103
static int handle(int sql_errno, const char *sqlstate, const char *message, void *state)
Bridge function between the C++ API offered by this module and the C API of the parser service.
Definition: services.cc:64
native_handle_type native_handle()
Definition: process.h:56
unexpected(E) -> unexpected< E >
#define HANDLE
Definition: violite.h:159