aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/neh/asio/tcp_socket_impl.cpp
diff options
context:
space:
mode:
authormonster <monster@ydb.tech>2022-07-07 14:41:37 +0300
committermonster <monster@ydb.tech>2022-07-07 14:41:37 +0300
commit06e5c21a835c0e923506c4ff27929f34e00761c2 (patch)
tree75efcbc6854ef9bd476eb8bf00cc5c900da436a2 /library/cpp/neh/asio/tcp_socket_impl.cpp
parent03f024c4412e3aa613bb543cf1660176320ba8f4 (diff)
downloadydb-06e5c21a835c0e923506c4ff27929f34e00761c2.tar.gz
fix ya.make
Diffstat (limited to 'library/cpp/neh/asio/tcp_socket_impl.cpp')
-rw-r--r--library/cpp/neh/asio/tcp_socket_impl.cpp117
1 files changed, 117 insertions, 0 deletions
diff --git a/library/cpp/neh/asio/tcp_socket_impl.cpp b/library/cpp/neh/asio/tcp_socket_impl.cpp
new file mode 100644
index 0000000000..98cef97561
--- /dev/null
+++ b/library/cpp/neh/asio/tcp_socket_impl.cpp
@@ -0,0 +1,117 @@
+#include "tcp_socket_impl.h"
+
+using namespace NAsio;
+
+TSocketOperation::TSocketOperation(TTcpSocket::TImpl& s, TPollType pt, TInstant deadline)
+ : TFdOperation(s.Fd(), pt, deadline)
+ , S_(s)
+{
+}
+
+bool TOperationWrite::Execute(int errorCode) {
+ if (errorCode) {
+ H_(errorCode, Written_, *this);
+
+ return true; //op. completed
+ }
+
+ TErrorCode ec;
+ TContIOVector& iov = *Buffs_->GetIOvec();
+
+ size_t n = S_.WriteSome(iov, ec);
+
+ if (ec && ec.Value() != EAGAIN && ec.Value() != EWOULDBLOCK) {
+ H_(ec, Written_ + n, *this);
+
+ return true;
+ }
+
+ if (n) {
+ Written_ += n;
+ iov.Proceed(n);
+ if (!iov.Bytes()) {
+ H_(ec, Written_, *this);
+
+ return true; //op. completed
+ }
+ }
+
+ return false; //operation not compleled
+}
+
+bool TOperationWriteVector::Execute(int errorCode) {
+ if (errorCode) {
+ H_(errorCode, Written_, *this);
+
+ return true; //op. completed
+ }
+
+ TErrorCode ec;
+
+ size_t n = S_.WriteSome(V_, ec);
+
+ if (ec && ec.Value() != EAGAIN && ec.Value() != EWOULDBLOCK) {
+ H_(ec, Written_ + n, *this);
+
+ return true;
+ }
+
+ if (n) {
+ Written_ += n;
+ V_.Proceed(n);
+ if (!V_.Bytes()) {
+ H_(ec, Written_, *this);
+
+ return true; //op. completed
+ }
+ }
+
+ return false; //operation not compleled
+}
+
+bool TOperationReadSome::Execute(int errorCode) {
+ if (errorCode) {
+ H_(errorCode, 0, *this);
+
+ return true; //op. completed
+ }
+
+ TErrorCode ec;
+
+ H_(ec, S_.ReadSome(Buff_, Size_, ec), *this);
+
+ return true;
+}
+
+bool TOperationRead::Execute(int errorCode) {
+ if (errorCode) {
+ H_(errorCode, Read_, *this);
+
+ return true; //op. completed
+ }
+
+ TErrorCode ec;
+ size_t n = S_.ReadSome(Buff_, Size_, ec);
+ Read_ += n;
+
+ if (ec && ec.Value() != EAGAIN && ec.Value() != EWOULDBLOCK) {
+ H_(ec, Read_, *this);
+
+ return true; //op. completed
+ }
+
+ if (n) {
+ Size_ -= n;
+ if (!Size_) {
+ H_(ec, Read_, *this);
+
+ return true;
+ }
+ Buff_ += n;
+ } else if (!ec) { // EOF while read not all
+ H_(ec, Read_, *this);
+ return true;
+ }
+
+ return false;
+}