From eaec590513377720ddbca13446f76889a43cb1d6 Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Wed, 12 Sep 2018 12:43:15 +0800 Subject: [PATCH] NBAcceptResult can stopAtEdge now --- gsock.cpp | 23 ++++++++++++++++++++++- gsock.h | 2 ++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gsock.cpp b/gsock.cpp index 8f899a5..1734625 100644 --- a/gsock.cpp +++ b/gsock.cpp @@ -522,6 +522,7 @@ void NBSendResult::_impl::update() NBSendResult::NBSendResult() : _p(new _impl) { _p->status = 0; + _p->stopAtEdge = false; } void NBSendResult::setStopAtEdge(bool flag) @@ -626,6 +627,7 @@ void NBRecvResult::_impl::update() NBRecvResult::NBRecvResult() : _p(new _impl) { _p->status = 0; + _p->stopAtEdge = false; } void NBRecvResult::setStopAtEdge(bool flag) @@ -1026,6 +1028,8 @@ struct NBAcceptResult::_impl { int sfd; + bool stopAtEdge; + // For client use bool isv4; sockaddr_in saddr; @@ -1071,10 +1075,21 @@ void NBAcceptResult::_impl::update() { gerrno err = TranslateNativeErrToGErr(GetNativeErrCode()); errcode = err; - if (err == gerrno::InProgress || err == gerrno::WouldBlock || err == gerrno::Already) + if (err == gerrno::InProgress || err == gerrno::Already) { status = 1; } + else if (err == gerrno::WouldBlock) + { + if (stopAtEdge) + { + status = 3; + } + else + { + status = 1; + } + } else { status = 3; @@ -1087,6 +1102,12 @@ void NBAcceptResult::_impl::update() NBAcceptResult::NBAcceptResult() : _sp(new _impl) { _sp->status = 0; + _sp->stopAtEdge = false; +} + +void NBAcceptResult::stopAtEdge(bool flag) +{ + _sp->stopAtEdge = flag; } bool NBAcceptResult::isFinished() diff --git a/gsock.h b/gsock.h index 2a0ef27..736148e 100644 --- a/gsock.h +++ b/gsock.h @@ -187,6 +187,8 @@ class NBAcceptResult public: NBAcceptResult(); + void stopAtEdge(bool flag); + bool isFinished(); bool isSuccess();