aboutsummaryrefslogtreecommitdiffhomepage
path: root/tdnet
diff options
context:
space:
mode:
authorArseny Smirnov <arseny30@gmail.com>2020-07-21 18:29:39 +0300
committerArseny Smirnov <arseny30@gmail.com>2020-07-21 18:29:39 +0300
commit38ef3a75cc74b5adb0cb22a72fc0426e8ffd094f (patch)
treef4c9c106986f47c19568f458532def3a22e83328 /tdnet
parentceb49d01432fce1627e7b5d5a7594eb2eac946d1 (diff)
PollableFd: explicit sync_with_poll
GitOrigin-RevId: 71fa35a594816e84e372ebcfa9d0077a13f26a62
Diffstat (limited to 'tdnet')
-rw-r--r--tdnet/td/net/HttpConnectionBase.cpp9
-rw-r--r--tdnet/td/net/TcpListener.cpp5
-rw-r--r--tdnet/td/net/TransparentProxy.cpp6
3 files changed, 12 insertions, 8 deletions
diff --git a/tdnet/td/net/HttpConnectionBase.cpp b/tdnet/td/net/HttpConnectionBase.cpp
index 1a0a11629..7ef6a83c4 100644
--- a/tdnet/td/net/HttpConnectionBase.cpp
+++ b/tdnet/td/net/HttpConnectionBase.cpp
@@ -92,7 +92,8 @@ void HttpConnectionBase::timeout_expired() {
stop();
}
void HttpConnectionBase::loop() {
- if (can_read(fd_)) {
+ sync_with_poll(fd_);
+ if (can_read_local(fd_)) {
LOG(DEBUG) << "Can read from the connection";
auto r = fd_.flush_read();
if (r.is_error()) {
@@ -133,7 +134,7 @@ void HttpConnectionBase::loop() {
write_source_.wakeup();
- if (can_write(fd_)) {
+ if (can_write_local(fd_)) {
LOG(DEBUG) << "Can write to the connection";
auto r = fd_.flush_write();
if (r.is_error()) {
@@ -146,7 +147,7 @@ void HttpConnectionBase::loop() {
}
Status pending_error;
- if (fd_.get_poll_info().get_flags().has_pending_error()) {
+ if (fd_.get_poll_info().get_flags_local().has_pending_error()) {
pending_error = fd_.get_pending_error();
}
if (pending_error.is_ok() && write_sink_.status().is_error()) {
@@ -163,7 +164,7 @@ void HttpConnectionBase::loop() {
state_ = State::Close;
}
- if (can_close(fd_)) {
+ if (can_close_local(fd_)) {
LOG(DEBUG) << "Can close the connection";
state_ = State::Close;
}
diff --git a/tdnet/td/net/TcpListener.cpp b/tdnet/td/net/TcpListener.cpp
index 8bbf00afd..e6161811c 100644
--- a/tdnet/td/net/TcpListener.cpp
+++ b/tdnet/td/net/TcpListener.cpp
@@ -40,7 +40,8 @@ void TcpListener::loop() {
if (server_fd_.empty()) {
start_up();
}
- while (can_read(server_fd_)) {
+ sync_with_poll(server_fd_);
+ while (can_read_local(server_fd_)) {
auto r_socket_fd = server_fd_.accept();
if (r_socket_fd.is_error()) {
if (r_socket_fd.error().code() != -1) {
@@ -51,7 +52,7 @@ void TcpListener::loop() {
send_closure(callback_, &Callback::accept, r_socket_fd.move_as_ok());
}
- if (can_close(server_fd_)) {
+ if (can_close_local(server_fd_)) {
stop();
}
}
diff --git a/tdnet/td/net/TransparentProxy.cpp b/tdnet/td/net/TransparentProxy.cpp
index ed38b9a51..002dacec0 100644
--- a/tdnet/td/net/TransparentProxy.cpp
+++ b/tdnet/td/net/TransparentProxy.cpp
@@ -55,12 +55,14 @@ void TransparentProxy::start_up() {
VLOG(proxy) << "Begin to connect to proxy";
Scheduler::subscribe(fd_.get_poll_info().extract_pollable_fd(this));
set_timeout_in(10);
- if (can_write(fd_)) {
+ sync_with_poll(fd_);
+ if (can_write_local(fd_)) {
loop();
}
}
void TransparentProxy::loop() {
+ sync_with_poll(fd_);
auto status = [&] {
TRY_STATUS(fd_.flush_read());
TRY_STATUS(loop_impl());
@@ -70,7 +72,7 @@ void TransparentProxy::loop() {
if (status.is_error()) {
on_error(std::move(status));
}
- if (can_close(fd_)) {
+ if (can_close_local(fd_)) {
on_error(Status::Error("Connection closed"));
}
}