13 #ifndef __STOUT_OS_WINDOWS_READ_HPP__ 14 #define __STOUT_OS_WINDOWS_READ_HPP__ 34 OVERLAPPED* overlapped)
36 CHECK_LE(size, UINT_MAX);
42 ::ReadFile(fd, data, static_cast<DWORD>(size), &bytes, overlapped);
47 const DWORD errorCode = ::GetLastError();
48 if (success == FALSE &&
49 (errorCode == ERROR_BROKEN_PIPE || errorCode == ERROR_HANDLE_EOF)) {
57 std::is_same<OVERLAPPED, WSAOVERLAPPED>::value,
58 "Expected `WSAOVERLAPPED` to be of type `OVERLAPPED`.");
64 static_cast<u_long
>(
size),
65 static_cast<char*>(data)
71 ::WSARecv(fd, &buf, 1, &bytes, &flags, overlapped,
nullptr);
85 CHECK_LE(size, UINT_MAX);
91 if (!fd.is_overlapped()) {
94 ::ReadFile(fd, data, static_cast<DWORD>(size), &bytes,
nullptr);
96 if (result == FALSE) {
99 if (::GetLastError() != ERROR_BROKEN_PIPE) {
105 return static_cast<ssize_t>(bytes);
117 OVERLAPPED overlapped = overlapped_.
get();
130 const BOOL wait_success =
131 ::GetOverlappedResult(fd, &overlapped, &bytes, TRUE);
133 if (wait_success == TRUE) {
140 const DWORD
error = ::GetLastError();
141 if (error == ERROR_BROKEN_PIPE || error == ERROR_HANDLE_EOF) {
148 return ::recv(fd, (
char*)data, static_cast<unsigned int>(size), 0);
157 #endif // __STOUT_OS_WINDOWS_READ_HPP__ SSIZE_T ssize_t
Definition: windows.hpp:186
Try< Bytes > size(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:130
T & get()&
Definition: try.hpp:80
Try< OVERLAPPED > init_overlapped_for_sync_io()
Definition: overlapped.hpp:30
Result< size_t > process_async_io_result(bool successful_return_code, size_t bytes_transfered)
Definition: overlapped.hpp:71
Definition: posix_signalhandler.hpp:23
Future< size_t > recv(const int_fd &fd, void *buf, size_t size)
#define UNREACHABLE()
Definition: unreachable.hpp:22
Result< size_t > read_async(const int_fd &fd, void *data, size_t size, OVERLAPPED *overlapped)
Definition: read.hpp:30
Result< std::string > read(int_fd fd, size_t size)
Definition: read.hpp:55
bool isError() const
Definition: try.hpp:78
std::string error(const std::string &msg, uint32_t code)
T & get()&
Definition: result.hpp:116
bool isSome() const
Definition: result.hpp:112
bool isError() const
Definition: result.hpp:114
int int_fd
Definition: int_fd.hpp:35