From 9d4767f741e523d75aca394b380dc2fb5b4d5a56 Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Wed, 12 Sep 2018 00:59:03 +0800 Subject: [PATCH] NBSendResult has setStopAtEdge() now --- gsock.cpp | 19 ++++++++++++++++++- gsock.h | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/gsock.cpp b/gsock.cpp index cc307d1..50b3591 100644 --- a/gsock.cpp +++ b/gsock.cpp @@ -456,6 +456,11 @@ struct NBSendResult::_impl int total; int done; + // When work together with epoll at ET mode, + // setting this flag can avoid infinite EAGAIN send loop. + // (caused by buffer full or something else) + bool stopAtEdge; + // 0: Not started. // 1: Data is being sent // 2: Data sent without error. @@ -496,7 +501,14 @@ void NBSendResult::_impl::update() if (err == gerrno::WouldBlock) { - status = 1; + if (stopAtEdge) + { + status = 2; + } + else + { + status = 1; + } } else { @@ -512,6 +524,11 @@ NBSendResult::NBSendResult() : _p(new _impl) _p->status = 0; } +void NBSendResult::setStopAtEdge(bool flag) +{ + _p->stopAtEdge = true; +} + bool NBSendResult::isFinished() { _p->update(); diff --git a/gsock.h b/gsock.h index 89b616e..2a0ef27 100644 --- a/gsock.h +++ b/gsock.h @@ -94,6 +94,8 @@ class NBSendResult public: NBSendResult(); + void setStopAtEdge(bool flag); + // Is the operation finished. bool isFinished();