mirror of
https://github.com/huiwan-code/CProxy.git
synced 2026-02-07 23:16:23 +08:00
41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
#include "public_conn.h"
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include "tunnel.h"
|
|
#include "spdlog/spdlog.h"
|
|
|
|
void PublicConn::handleRead() {
|
|
try {
|
|
int bs = splice(fd_, NULL, pipe_fds_[1], NULL, 2048, SPLICE_F_MOVE | SPLICE_F_NONBLOCK);
|
|
if (bs < 0) {
|
|
SPDLOG_CRITICAL("public_fd: {} -> pipe_fd: {} splice err: {}", fd_, pipe_fds_[1],
|
|
strerror(errno));
|
|
return;
|
|
}
|
|
// 添加closing_判断的原因详看localConn.cpp
|
|
if (bs == 0 && !closing_) {
|
|
// 收到fin包,通知proxy
|
|
tun_->shutdownFromPublic(proxy_id_, getTranCount());
|
|
closing_ = true;
|
|
return;
|
|
}
|
|
bs = splice(pipe_fds_[0], NULL, peer_conn_fd_, NULL, bs, SPLICE_F_MOVE | SPLICE_F_NONBLOCK);
|
|
if (bs < 0) {
|
|
SPDLOG_CRITICAL("proxy_id {} pipe {} - >proxy_fd: {} splice err: {}", proxy_id_, pipe_fds_[0],
|
|
peer_conn_fd_, strerror(errno));
|
|
return;
|
|
}
|
|
incrTranCount(bs);
|
|
} catch (const std::exception& e) {
|
|
SPDLOG_CRITICAL("read public except: {}", e.what());
|
|
}
|
|
}
|
|
|
|
void PublicConn::postHandle() {
|
|
if (closing_) {
|
|
return;
|
|
}
|
|
channel_->SetEvents(EPOLLET | EPOLLIN | EPOLLRDHUP);
|
|
loop_->UpdateToPoller(channel_);
|
|
} |