NBSendResult has setStopAtEdge() now

This commit is contained in:
Kirigaya Kazuto 2018-09-12 00:59:03 +08:00
parent 3bad71c8c9
commit 9d4767f741
2 changed files with 20 additions and 1 deletions

View File

@ -456,6 +456,11 @@ struct NBSendResult::_impl
int total; int total;
int done; 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. // 0: Not started.
// 1: Data is being sent // 1: Data is being sent
// 2: Data sent without error. // 2: Data sent without error.
@ -496,7 +501,14 @@ void NBSendResult::_impl::update()
if (err == gerrno::WouldBlock) if (err == gerrno::WouldBlock)
{ {
status = 1; if (stopAtEdge)
{
status = 2;
}
else
{
status = 1;
}
} }
else else
{ {
@ -512,6 +524,11 @@ NBSendResult::NBSendResult() : _p(new _impl)
_p->status = 0; _p->status = 0;
} }
void NBSendResult::setStopAtEdge(bool flag)
{
_p->stopAtEdge = true;
}
bool NBSendResult::isFinished() bool NBSendResult::isFinished()
{ {
_p->update(); _p->update();

View File

@ -94,6 +94,8 @@ class NBSendResult
public: public:
NBSendResult(); NBSendResult();
void setStopAtEdge(bool flag);
// Is the operation finished. // Is the operation finished.
bool isFinished(); bool isFinished();