25#ifndef MYSQL_HARNESS_NET_TS_IMPL_FILE_H_
26#define MYSQL_HARNESS_NET_TS_IMPL_FILE_H_
29#include <system_error>
58 return {
static_cast<int>(GetLastError()), std::system_category()};
60 return {errno, std::generic_category()};
64template <
int Name,
class Arg>
71 constexpr int name()
const {
return Name; }
86 constexpr int name()
const {
return Name; }
88 constexpr int value()
const {
return 0; }
123template <
class FileControlOption>
127 if (-1 == (res = ::
fcntl(fd, cmd.name(), cmd.value()))) {
144 std::array<file_handle_type, 2> fds{};
152 if (0 == ::CreatePipe(&fds[0], &fds[1],
nullptr, 0)) {
155#elif defined(__linux__) || defined(__FreeBSD__)
159 if (0 != ::pipe2(fds.data(),
flags)) {
163 if (0 != ::
pipe(fds.data())) {
168 auto fcntl_res =
fcntl(fds[0], fl);
176 fcntl_res =
fcntl(fds[1], fl);
185 return std::make_pair(fds[0], fds[1]);
198 if (0 == ::WriteFile(
handle,
buf, buf_len, &transfered,
nullptr)) {
203 if (-1 == transfered) {
217 void *
buf,
size_t buf_len) {
220 if (0 == ::ReadFile(
handle,
buf, buf_len, &transfered,
nullptr)) {
225 if (-1 == transfered) {
void arg_type
Definition: file.h:82
constexpr int value() const
Definition: file.h:88
file_control_option()=default
constexpr int name() const
Definition: file.h:86
file_control_option(value_type v)
Definition: file.h:69
Arg value_type
Definition: file.h:67
value_type v_
Definition: file.h:76
constexpr value_type value() const
Definition: file.h:73
constexpr int name() const
Definition: file.h:71
Definition: expected.h:943
static int flags[50]
Definition: hp_test1.cc:39
Definition: buf0block_hint.cc:29
Definition: authentication.cc:35
stdx::expected< int, std::error_code > fcntl(file_handle_type fd, const FileControlOption &cmd)
Definition: file.h:124
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:216
int file_handle_type
Definition: file.h:52
constexpr file_handle_type kInvalidHandle
Definition: file.h:53
std::error_code last_error_code()
Definition: file.h:56
stdx::expected< std::pair< file_handle_type, file_handle_type >, std::error_code > pipe(int flags=0)
create pipe.
Definition: file.h:143
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:193
stdx::expected< void, std::error_code > close(file_handle_type native_handle)
close file handle.
Definition: file.h:238
std::error_code make_error_code(net::stream_errc e) noexcept
Definition: buffer.h:102
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:63
native_handle_type native_handle()
Definition: process.h:55
constexpr auto make_unexpected(E &&e) -> unexpected< std::decay_t< E > >
Definition: expected.h:124
#define HANDLE
Definition: violite.h:158