Skip to content
Merged
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
59 changes: 53 additions & 6 deletions coroio/socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ class TSocketBase: public TSocketBase<void> {
/**
* @brief Asynchronously reads data from the socket into the provided buffer.
*
* When awaited, this method suspends the current coroutine until the read operation
* completes and then returns the number of bytes read.
* Semantics: returns bytes read (>0), 0 on closure, and a negative value
* (retry hint) for transient errors (e.g. EINTR/EAGAIN/EINPROGRESS). Non-retryable
* errors throw std::system_error.
*
* @param buf Pointer to the destination buffer.
* @param size The number of bytes to read.
Expand All @@ -150,8 +151,9 @@ class TSocketBase: public TSocketBase<void> {
/**
* @brief Forces a read operation on the next event loop iteration.
*
* Similar to @ref ReadSome(), but this variant ensures that the read is deferred
* to the next iteration of the event loop.
* Semantics: returns bytes read (>0), 0 on closure, and a negative value
* (retry hint) for transient errors (e.g. EINTR/EAGAIN/EINPROGRESS). Non-retryable
* errors throw std::system_error.
*
* @param buf Pointer to the buffer where data will be stored.
* @param size Number of bytes to read.
Expand All @@ -176,8 +178,9 @@ class TSocketBase: public TSocketBase<void> {
/**
* @brief Asynchronously writes data from the provided buffer to the socket.
*
* This method suspends the current coroutine until the data is written, and then returns
* the number of bytes successfully written.
* Semantics: returns bytes written (>0), 0 if nothing written, and a negative value
* (retry hint) for transient errors (e.g. EINTR/EAGAIN/EINPROGRESS). Non-retryable
* errors throw std::system_error.
*
* @param buf Pointer to the data to be written.
* @param size The number of bytes to write.
Expand Down Expand Up @@ -659,6 +662,17 @@ class TPollerDrivenSocket: public TSocket
auto await_resume() {
auto ret = poller->Result();
if (ret < 0) {
#ifdef _WIN32
int err = -ret;
if (err == WSAEWOULDBLOCK || err == WSAEINTR || err == WSAEINPROGRESS) {
return ret; // retry hint
}
#else
int err = -ret;
if (err == EINTR || err == EAGAIN || err == EINPROGRESS) {
return ret; // retry hint
}
#endif
throw std::system_error(-ret, std::generic_category());
}
return ret;
Expand Down Expand Up @@ -694,6 +708,17 @@ class TPollerDrivenSocket: public TSocket
auto await_resume() {
auto ret = poller->Result();
if (ret < 0) {
#ifdef _WIN32
int err = -ret;
if (err == WSAEWOULDBLOCK || err == WSAEINTR || err == WSAEINPROGRESS) {
return ret; // retry hint
}
#else
int err = -ret;
if (err == EINTR || err == EAGAIN || err == EINPROGRESS) {
return ret; // retry hint
}
#endif
throw std::system_error(-ret, std::generic_category());
}
return ret;
Expand Down Expand Up @@ -776,6 +801,17 @@ class TPollerDrivenFileHandle: public TFileHandle
auto await_resume() {
auto ret = poller->Result();
if (ret < 0) {
#ifdef _WIN32
int err = -ret;
if (err == WSAEWOULDBLOCK || err == WSAEINTR || err == WSAEINPROGRESS) {
return ret; // retry hint
}
#else
int err = -ret;
if (err == EINTR || err == EAGAIN || err == EINPROGRESS) {
return ret; // retry hint
}
#endif
throw std::system_error(-ret, std::generic_category());
}
return ret;
Expand Down Expand Up @@ -811,6 +847,17 @@ class TPollerDrivenFileHandle: public TFileHandle
auto await_resume() {
auto ret = poller->Result();
if (ret < 0) {
#ifdef _WIN32
int err = -ret;
if (err == WSAEWOULDBLOCK || err == WSAEINTR || err == WSAEINPROGRESS) {
return ret; // retry hint
}
#else
int err = -ret;
if (err == EINTR || err == EAGAIN || err == EINPROGRESS) {
return ret; // retry hint
}
#endif
throw std::system_error(-ret, std::generic_category());
}
return ret;
Expand Down
Loading