Skip to content

Commit

Permalink
Refactor the read and write functions in Unix and SSL NetVC (#11794)
Browse files Browse the repository at this point in the history
  • Loading branch information
maskit authored Nov 4, 2024
1 parent 8671ddb commit b9779fd
Show file tree
Hide file tree
Showing 8 changed files with 508 additions and 542 deletions.
6 changes: 3 additions & 3 deletions include/iocore/net/NetEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class NetEvent
public:
NetEvent() = default;
virtual ~NetEvent() {}
virtual void net_read_io(NetHandler *nh, EThread *lthread) = 0;
virtual void net_write_io(NetHandler *nh, EThread *lthread) = 0;
virtual void free_thread(EThread *t) = 0;
virtual void net_read_io(NetHandler *nh) = 0;
virtual void net_write_io(NetHandler *nh) = 0;
virtual void free_thread(EThread *t) = 0;

// since we want this class to be independent from VConnection, Continutaion. There should be
// a pure virtual function which connect sub class and NetHandler.
Expand Down
4 changes: 2 additions & 2 deletions src/iocore/net/NetHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ NetHandler::process_ready_list()
if (ne->closed) {
free_netevent(ne);
} else if (ne->read.enabled && ne->read.triggered) {
ne->net_read_io(this, this->thread);
ne->net_read_io(this);
} else if (!ne->read.enabled) {
read_ready_list.remove(ne);
}
Expand All @@ -293,7 +293,7 @@ NetHandler::process_ready_list()
if (ne->closed) {
free_netevent(ne);
} else if (ne->write.enabled && ne->write.triggered) {
ne->net_write_io(this, this->thread);
ne->net_write_io(this);
} else if (!ne->write.enabled) {
write_ready_list.remove(ne);
}
Expand Down
2 changes: 1 addition & 1 deletion src/iocore/net/P_QUICNetVConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class QUICNetVConnection : public UnixNetVConnection,
bool getSSLHandShakeComplete() const override;

// NetEvent
virtual void net_read_io(NetHandler *nh, EThread *lthread) override;
virtual void net_read_io(NetHandler *nh) override;

// NetVConnection
int populate_protocol(std::string_view *results, int n) const override;
Expand Down
4 changes: 2 additions & 2 deletions src/iocore/net/P_SSLNetVConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class SSLNetVConnection : public UnixNetVConnection,

int sslServerHandShakeEvent(int &err);
int sslClientHandShakeEvent(int &err);
void net_read_io(NetHandler *nh, EThread *lthread) override;
void net_read_io(NetHandler *nh) override;
int64_t load_buffer_and_write(int64_t towrite, MIOBufferAccessor &buf, int64_t &total_written, int &needs) override;
void do_io_close(int lerrno = -1) override;

Expand Down Expand Up @@ -376,7 +376,7 @@ class SSLNetVConnection : public UnixNetVConnection,
UnixNetVConnection *_migrateFromSSL();
void _propagateHandShakeBuffer(UnixNetVConnection *target, EThread *t);

int _ssl_read_from_net(EThread *lthread, int64_t &ret);
int _ssl_read_from_net(int64_t &ret);
ssl_error_t _ssl_read_buffer(void *buf, int64_t nbytes, int64_t &nread);
ssl_error_t _ssl_write_buffer(const void *buf, int64_t nbytes, int64_t &nwritten);
ssl_error_t _ssl_connect();
Expand Down
14 changes: 3 additions & 11 deletions src/iocore/net/P_UnixNetVConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ class UnixNetVConnection : public NetVConnection, public NetEvent
}

// NetEvent
virtual void net_read_io(NetHandler *nh, EThread *lthread) override;
virtual void net_write_io(NetHandler *nh, EThread *lthread) override;
virtual void net_read_io(NetHandler *nh) override;
virtual void net_write_io(NetHandler *nh) override;
virtual void free_thread(EThread *t) override;
virtual int
close() override
Expand Down Expand Up @@ -195,7 +195,7 @@ class UnixNetVConnection : public NetVConnection, public NetEvent
int readSignalAndUpdate(int event);
void readReschedule(NetHandler *nh);
void writeReschedule(NetHandler *nh);
void netActivity(EThread *lthread);
void netActivity();
/**
* If the current object's thread does not match the t argument, create a new
* NetVC in the thread t context based on the socket and ssl information in the
Expand Down Expand Up @@ -234,8 +234,6 @@ class UnixNetVConnection : public NetVConnection, public NetEvent
int set_tcp_congestion_control(int side) override;
void apply_options() override;

friend void write_to_net_io(NetHandler *, UnixNetVConnection *, EThread *);

// set_context() should be called before calling this member function.
void mark_as_tunnel_endpoint() override;

Expand Down Expand Up @@ -376,9 +374,3 @@ UnixNetVConnection::get_action() const
{
return &action_;
}

// declarations for local use (within the net module)

void write_to_net(NetHandler *nh, UnixNetVConnection *vc, EThread *thread);
void write_to_net_io(NetHandler *nh, UnixNetVConnection *vc, EThread *thread);
void net_activity(UnixNetVConnection *vc, EThread *thread);
6 changes: 3 additions & 3 deletions src/iocore/net/QUICNetVConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ QUICNetVConnection::handle_received_packet(UDPPacket *packet)
{
size_t buf_len{0};
uint8_t *buf = packet->get_entire_chain_buffer(&buf_len);
net_activity(this, this_ethread());
this->netActivity();
quiche_recv_info recv_info = {
&packet->from.sa,
static_cast<socklen_t>(packet->from.isIp4() ? sizeof(packet->from.sin) : sizeof(packet->from.sin6)),
Expand Down Expand Up @@ -522,7 +522,7 @@ QUICNetVConnection::is_handshake_completed() const
}

void
QUICNetVConnection::net_read_io(NetHandler * /* nh ATS_UNUSED */, EThread * /* lthread ATS_UNUSED */)
QUICNetVConnection::net_read_io(NetHandler * /* nh ATS_UNUSED */)
{
SCOPED_MUTEX_LOCK(lock, this->mutex, this_ethread());
this->handleEvent(QUIC_EVENT_PACKET_READ_READY, nullptr);
Expand Down Expand Up @@ -714,7 +714,7 @@ QUICNetVConnection::_handle_write_ready()
segment_size = max_udp_payload_size;
}
this->_packet_handler->send_packet(this->_udp_con, this->con.addr, udp_payload, segment_size, &send_at_hint);
net_activity(this, this_ethread());
this->netActivity();
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/iocore/net/SSLNetVConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ debug_certificate_name(const char *msg, X509_NAME *name)
}

int
SSLNetVConnection::_ssl_read_from_net(EThread *lthread, int64_t &ret)
SSLNetVConnection::_ssl_read_from_net(int64_t &ret)
{
NetState *s = &this->read;
MIOBufferAccessor &buf = s->vio.buffer;
Expand Down Expand Up @@ -221,7 +221,7 @@ SSLNetVConnection::_ssl_read_from_net(EThread *lthread, int64_t &ret)
bytes_read += nread;
if (nread > 0) {
buf.writer()->fill(nread); // Tell the buffer, we've used the bytes
this->netActivity(lthread);
this->netActivity();
}
break;
case SSL_ERROR_WANT_WRITE:
Expand Down Expand Up @@ -275,7 +275,7 @@ SSLNetVConnection::_ssl_read_from_net(EThread *lthread, int64_t &ret)
Dbg(dbg_ctl_ssl, "bytes_read=%" PRId64, bytes_read);

s->vio.ndone += bytes_read;
this->netActivity(lthread);
this->netActivity();

ret = bytes_read;

Expand Down Expand Up @@ -454,19 +454,19 @@ SSLNetVConnection::update_rbio(bool move_to_socket)

// changed by YTS Team, yamsat
void
SSLNetVConnection::net_read_io(NetHandler *nh, EThread *lthread)
SSLNetVConnection::net_read_io(NetHandler *nh)
{
int ret;
int64_t r = 0;
int64_t bytes = 0;
NetState *s = &this->read;

if (HttpProxyPort::TRANSPORT_BLIND_TUNNEL == this->attributes) {
this->super::net_read_io(nh, lthread);
this->super::net_read_io(nh);
return;
}

MUTEX_TRY_LOCK(lock, s->vio.mutex, lthread);
MUTEX_TRY_LOCK(lock, s->vio.mutex, nh->thread);
if (!lock.is_locked()) {
readReschedule(nh);
return;
Expand All @@ -475,7 +475,7 @@ SSLNetVConnection::net_read_io(NetHandler *nh, EThread *lthread)
// The closed flag should be stable once we get the s->vio.mutex in that case
// (the global session pool mutex).
if (this->closed) {
this->super::net_read_io(nh, lthread);
this->super::net_read_io(nh);
return;
}
// If the key renegotiation failed it's over, just signal the error and finish.
Expand Down Expand Up @@ -614,7 +614,7 @@ SSLNetVConnection::net_read_io(NetHandler *nh, EThread *lthread)
// this comment if you know
int ssl_read_errno = 0;
do {
ret = this->_ssl_read_from_net(lthread, r);
ret = this->_ssl_read_from_net(r);
if (ret == SSL_READ_READY || ret == SSL_READ_ERROR_NONE) {
bytes += r;
}
Expand Down
Loading

0 comments on commit b9779fd

Please sign in to comment.