Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions iocore/net/P_SSLNetVConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class SSLNetVConnection : public UnixNetVConnection

public:
int sslStartHandShake(int event, int &err) override;
void clear() override;
void free(EThread *t) override;

virtual void
Expand Down
62 changes: 62 additions & 0 deletions iocore/net/P_UnixNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,24 @@ class NetHandler : public Continuation
void remove_from_active_queue(UnixNetVConnection *vc);
void configure_per_thread();

/**
Start to handle read & write event on a UnixNetVConnection.
Initial the socket fd of netvc for polling system.
Only be called when holding the mutex of this NetHandler.

@param netvc UnixNetVConnection to be managed by this NetHandler.
@return 0 on success, -ERRNO on failure.
*/
int startIO(UnixNetVConnection *netvc);
/**
Stop to handle read & write event on a UnixNetVConnection.
Remove the socket fd of netvc from polling system.
Only be called when holding the mutex of this NetHandler.

@param netvc UnixNetVConnection to be released.
*/
void stopIO(UnixNetVConnection *netvc);

NetHandler();

private:
Expand Down Expand Up @@ -639,4 +657,48 @@ EventIO::stop()
return 0;
}

TS_INLINE int
NetHandler::startIO(UnixNetVConnection *netvc)
{
ink_assert(this->mutex->thread_holding == this_ethread());
ink_assert(netvc->thread == this_ethread());
int res = 0;

PollDescriptor *pd = get_PollDescriptor(trigger_event->ethread);
if (netvc->ep.start(pd, netvc, EVENTIO_READ | EVENTIO_WRITE) < 0) {
res = errno;
// EEXIST should be ok, though it should have been cleared before we got back here
if (errno != EEXIST) {
Debug("iocore_net", "NetHandler::startIO : failed on EventIO::start, errno = [%d](%s)", errno, strerror(errno));
return -res;
}
}

if (netvc->read.triggered == 1) {
read_ready_list.enqueue(netvc);
}
netvc->nh = this;
return res;
}

TS_INLINE void
NetHandler::stopIO(UnixNetVConnection *netvc)
{
ink_release_assert(netvc->nh == this);

netvc->ep.stop();

read_ready_list.remove(netvc);
write_ready_list.remove(netvc);
if (netvc->read.in_enabled_list) {
read_enable_list.remove(netvc);
netvc->read.in_enabled_list = 0;
}
if (netvc->write.in_enabled_list) {
write_enable_list.remove(netvc);
netvc->write.in_enabled_list = 0;
}

netvc->nh = nullptr;
}
#endif
1 change: 1 addition & 0 deletions iocore/net/P_UnixNetVConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class UnixNetVConnection : public NetVConnection
* This is logic is invoked when the NetVC object is created in a new thread context
*/
virtual int populate(Connection &con, Continuation *c, void *arg);
virtual void clear();
virtual void free(EThread *t);

ink_hrtime get_inactivity_timeout() override;
Expand Down
49 changes: 16 additions & 33 deletions iocore/net/SSLNetVConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -847,40 +847,8 @@ SSLNetVConnection::do_io_close(int lerrno)
}

void
SSLNetVConnection::free(EThread *t)
SSLNetVConnection::clear()
{
got_remote_addr = false;
got_local_addr = false;
read.vio.mutex.clear();
write.vio.mutex.clear();
this->mutex.clear();
action_.mutex.clear();
this->ep.stop();
this->con.close();
flags = 0;

SET_CONTINUATION_HANDLER(this, (SSLNetVConnHandler)&SSLNetVConnection::startEvent);

if (nh) {
nh->read_ready_list.remove(this);
nh->write_ready_list.remove(this);
nh = nullptr;
}

read.triggered = 0;
write.triggered = 0;
read.enabled = 0;
write.enabled = 0;
read.vio._cont = nullptr;
write.vio._cont = nullptr;
read.vio.vc_server = nullptr;
write.vio.vc_server = nullptr;

closed = 0;
options.reset();

ink_assert(con.fd == NO_FD);

if (ssl != nullptr) {
SSL_free(ssl);
ssl = nullptr;
Expand All @@ -901,6 +869,21 @@ SSLNetVConnection::free(EThread *t)
free_handshake_buffers();
sslTrace = false;

super::clear();
}
void
SSLNetVConnection::free(EThread *t)
{
ink_release_assert(t == this_ethread());

// close socket fd
con.close();

clear();
SET_CONTINUATION_HANDLER(this, (SSLNetVConnHandler)&SSLNetVConnection::startEvent);
ink_assert(con.fd == NO_FD);
ink_assert(t == this_ethread());

if (from_accept_thread) {
sslNetVCAllocator.free(this);
} else {
Expand Down
18 changes: 18 additions & 0 deletions iocore/net/UnixNetAccept.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ net_accept(NetAccept *na, void *ep, bool blockable)
vc->action_ = *na->action_;
vc->set_is_transparent(na->opt.f_inbound_transparent);
vc->set_context(NET_VCONNECTION_IN);
#ifdef USE_EDGE_TRIGGER
// Set the vc as triggered and place it in the read ready queue later in case there is already data on the socket.
if (na->server.http_accept_filter) {
vc->read.triggered = 1;
}
#endif
SET_CONTINUATION_HANDLER(vc, (NetVConnHandler)&UnixNetVConnection::acceptEvent);

if (e->ethread->is_event_type(na->opt.etype)) {
Expand Down Expand Up @@ -292,6 +298,12 @@ NetAccept::do_blocking_accept(EThread *t)
vc->apply_options();
vc->set_context(NET_VCONNECTION_IN);
vc->accept_object = this;
#ifdef USE_EDGE_TRIGGER
// Set the vc as triggered and place it in the read ready queue later in case there is already data on the socket.
if (server.http_accept_filter) {
vc->read.triggered = 1;
}
#endif
SET_CONTINUATION_HANDLER(vc, (NetVConnHandler)&UnixNetVConnection::acceptEvent);
// eventProcessor.schedule_imm(vc, getEtype());
eventProcessor.schedule_imm_signal(vc, opt.etype);
Expand Down Expand Up @@ -440,6 +452,12 @@ NetAccept::acceptFastEvent(int event, void *ep)
vc->apply_options();
vc->set_context(NET_VCONNECTION_IN);
vc->action_ = *action_;
#ifdef USE_EDGE_TRIGGER
// Set the vc as triggered and place it in the read ready queue later in case there is already data on the socket.
if (server.http_accept_filter) {
vc->read.triggered = 1;
}
#endif
SET_CONTINUATION_HANDLER(vc, (NetVConnHandler)&UnixNetVConnection::acceptEvent);
// We must be holding the lock already to do later do_io_read's
SCOPED_MUTEX_LOCK(lock, vc->mutex, e->ethread);
Expand Down
Loading