From 92426da9977b1ce0c2620a5a949b2be4d0e0143d Mon Sep 17 00:00:00 2001 From: Mo Chen Date: Wed, 21 Jun 2023 11:54:14 -0500 Subject: [PATCH 1/4] Use dynamic dispatch for EventIO --- iocore/dns/CMakeLists.txt | 1 + iocore/dns/DNS.cc | 2 +- iocore/dns/DNSEventIO.cc | 45 +++++++++++++++ iocore/dns/DNSEventIO.h | 47 +++++++++++++++ iocore/dns/Makefile.am | 1 + iocore/dns/P_DNSConnection.h | 5 +- iocore/io_uring/IOUringEventIO.cc | 41 +++++++++++++ iocore/io_uring/IOUringEventIO.h | 40 +++++++++++++ iocore/io_uring/Makefile.am | 2 + iocore/net/AsyncSignalEventIO.cc | 45 +++++++++++++++ iocore/net/AsyncSignalEventIO.h | 39 +++++++++++++ iocore/net/CMakeLists.txt | 4 ++ iocore/net/EventIO.cc | 60 +------------------ iocore/net/EventIO.h | 41 +++---------- iocore/net/Makefile.am | 8 +++ iocore/net/NetAcceptEventIO.cc | 44 ++++++++++++++ iocore/net/NetAcceptEventIO.h | 38 ++++++++++++ iocore/net/NetEvent.h | 5 +- iocore/net/NetHandler.cc | 76 +++--------------------- iocore/net/NetHandler.h | 4 -- iocore/net/P_NetAccept.h | 4 +- iocore/net/P_SSLNetVConnection.h | 2 +- iocore/net/P_UnixNet.h | 7 +++ iocore/net/P_UnixUDPConnection.h | 3 +- iocore/net/QUICNetProcessor_quiche.cc | 2 +- iocore/net/ReadWriteEventIO.cc | 83 +++++++++++++++++++++++++++ iocore/net/ReadWriteEventIO.h | 44 ++++++++++++++ iocore/net/SSLNetVConnection.cc | 3 +- iocore/net/UDPEventIO.cc | 52 +++++++++++++++++ iocore/net/UDPEventIO.h | 41 +++++++++++++ iocore/net/UnixNet.cc | 24 ++++---- iocore/net/UnixUDPNet.cc | 68 +++++++--------------- 32 files changed, 644 insertions(+), 237 deletions(-) create mode 100644 iocore/dns/DNSEventIO.cc create mode 100644 iocore/dns/DNSEventIO.h create mode 100644 iocore/io_uring/IOUringEventIO.cc create mode 100644 iocore/io_uring/IOUringEventIO.h create mode 100644 iocore/net/AsyncSignalEventIO.cc create mode 100644 iocore/net/AsyncSignalEventIO.h create mode 100644 iocore/net/NetAcceptEventIO.cc create mode 100644 iocore/net/NetAcceptEventIO.h create mode 100644 iocore/net/ReadWriteEventIO.cc create mode 100644 iocore/net/ReadWriteEventIO.h create mode 100644 iocore/net/UDPEventIO.cc create mode 100644 iocore/net/UDPEventIO.h diff --git a/iocore/dns/CMakeLists.txt b/iocore/dns/CMakeLists.txt index 44e3b6ec7aa..e70bf020f89 100644 --- a/iocore/dns/CMakeLists.txt +++ b/iocore/dns/CMakeLists.txt @@ -19,6 +19,7 @@ add_library(inkdns STATIC DNS.cc DNSConnection.cc + DNSEventIO.cc Inline.cc SplitDNS.cc ) diff --git a/iocore/dns/DNS.cc b/iocore/dns/DNS.cc index 6a4a0165615..40c2ef9c46d 100644 --- a/iocore/dns/DNS.cc +++ b/iocore/dns/DNS.cc @@ -528,7 +528,7 @@ DNSHandler::open_con(sockaddr const *target, bool failed, int icon, bool over_tc } return false; } else { - if (cur_con.eio.start(pd, &cur_con, EVENTIO_READ) < 0) { + if (cur_con.eio.start(pd, cur_con.fd, EVENTIO_READ) < 0) { Error("[iocore_dns] open_con: Failed to add %d server to epoll list\n", icon); } else { cur_con.num = icon; diff --git a/iocore/dns/DNSEventIO.cc b/iocore/dns/DNSEventIO.cc new file mode 100644 index 00000000000..00406ba27e1 --- /dev/null +++ b/iocore/dns/DNSEventIO.cc @@ -0,0 +1,45 @@ +/** @file + + A brief file description + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include "DNSEventIO.h" +#include "P_DNSConnection.h" + +int +DNSEventIO::start(EventLoop l, int fd, int events) +{ + return start_common(l, fd, events); +} + +void +DNSEventIO::process_event(int flags) +{ + _c.trigger(); // Make sure the DNSHandler for this con knows we triggered + refresh(EVENTIO_READ); +} + +int +DNSEventIO::close() +{ + EventIO::close(); // discard retval + return _c.close(); +} diff --git a/iocore/dns/DNSEventIO.h b/iocore/dns/DNSEventIO.h new file mode 100644 index 00000000000..98c7163e687 --- /dev/null +++ b/iocore/dns/DNSEventIO.h @@ -0,0 +1,47 @@ +/** @file + + A brief file description + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/************************************************************************** + + P_DNSConnection.h + Description: + struct DNSConnection + **************************************************************************/ + +#pragma once + +#include "EventIO.h" + +struct DNSConnection; + +class DNSEventIO : public EventIO +{ +public: + DNSEventIO(DNSConnection &c) : EventIO(), _c(c) {} + int start(EventLoop l, int fd, int events); + void process_event(int flags) override; + int close() override; + +private: + DNSConnection &_c; +}; diff --git a/iocore/dns/Makefile.am b/iocore/dns/Makefile.am index 33ae4180144..7f342f6bf2f 100644 --- a/iocore/dns/Makefile.am +++ b/iocore/dns/Makefile.am @@ -31,6 +31,7 @@ noinst_LIBRARIES = libinkdns.a libinkdns_a_SOURCES = \ DNS.cc \ DNSConnection.cc \ + DNSEventIO.cc \ I_DNS.h \ I_DNSProcessor.h \ I_SplitDNS.h \ diff --git a/iocore/dns/P_DNSConnection.h b/iocore/dns/P_DNSConnection.h index ed372eb9c2b..91fae3699fb 100644 --- a/iocore/dns/P_DNSConnection.h +++ b/iocore/dns/P_DNSConnection.h @@ -30,9 +30,8 @@ #pragma once -#include "I_EventSystem.h" +#include "DNSEventIO.h" #include "I_DNSProcessor.h" -#include "EventIO.h" // // Connection @@ -79,7 +78,7 @@ struct DNSConnection { int num = 0; Options opt; LINK(DNSConnection, link); - EventIO eio; + DNSEventIO eio{*this}; InkRand generator; DNSHandler *handler = nullptr; diff --git a/iocore/io_uring/IOUringEventIO.cc b/iocore/io_uring/IOUringEventIO.cc new file mode 100644 index 00000000000..fc3eb82269e --- /dev/null +++ b/iocore/io_uring/IOUringEventIO.cc @@ -0,0 +1,41 @@ +/** @file + + A brief file description + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include "IOUringEventIO.h" +#if TS_USE_LINUX_IO_URING +#include "I_IO_URING.h" + +int +IOUringEventIO::start(EventLoop l, IOUringContext *h) +{ + _h = h; + int fd = _h->register_eventfd(); + return start_common(l, fd, EVENTIO_READ); +} + +void +IOUringEventIO::process_event(int flags) +{ + _h->service(); +} +#endif diff --git a/iocore/io_uring/IOUringEventIO.h b/iocore/io_uring/IOUringEventIO.h new file mode 100644 index 00000000000..cf0962091c3 --- /dev/null +++ b/iocore/io_uring/IOUringEventIO.h @@ -0,0 +1,40 @@ +/** @file + + A brief file description + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#pragma once +#include "tscore/ink_config.h" +#if TS_USE_LINUX_IO_URING +#include "../net/EventIO.h" + +class IOUringContext; +class IOUringEventIO : public EventIO +{ +public: + IOUringEventIO() : EventIO() {} + int start(EventLoop l, IOUringContext *h); + void process_event(int flags) override; + +private: + IOUringContext *_h; +}; +#endif diff --git a/iocore/io_uring/Makefile.am b/iocore/io_uring/Makefile.am index 6430cdac838..64afb55992c 100644 --- a/iocore/io_uring/Makefile.am +++ b/iocore/io_uring/Makefile.am @@ -25,6 +25,8 @@ AM_CPPFLAGS += \ noinst_LIBRARIES = libinkuring.a libinkuring_a_SOURCES = \ + IOUringEventIO.cc \ + IOUringEventIO.h \ io_uring.cc \ I_IO_URING.h \ P_IO_URING.h diff --git a/iocore/net/AsyncSignalEventIO.cc b/iocore/net/AsyncSignalEventIO.cc new file mode 100644 index 00000000000..941dd31f2da --- /dev/null +++ b/iocore/net/AsyncSignalEventIO.cc @@ -0,0 +1,45 @@ +/**@file + + A brief file description + + @section license License + + Licensed to the Apache Software + Foundation(ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include "AsyncSignalEventIO.h" +#include "I_EThread.h" + +int +AsyncSignalEventIO::start(EventLoop l, int fd, int events) +{ + _fd = fd; + return start_common(l, fd, events); +} + +void +AsyncSignalEventIO::process_event(int flags) +{ +#if HAVE_EVENTFD + uint64_t counter; + ATS_UNUSED_RETURN(read(_fd, &counter, sizeof(uint64_t))); +#else + char dummy[1024]; + ATS_UNUSED_RETURN(read(_fd, &dummy[0], 1024)); +#endif +} diff --git a/iocore/net/AsyncSignalEventIO.h b/iocore/net/AsyncSignalEventIO.h new file mode 100644 index 00000000000..4786df30dc2 --- /dev/null +++ b/iocore/net/AsyncSignalEventIO.h @@ -0,0 +1,39 @@ +/**@file + + A brief file description + + @section license License + + Licensed to the Apache Software + Foundation(ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +#pragma once + +#include "EventIO.h" + +class EThread; + +class AsyncSignalEventIO : public EventIO +{ +public: + int start(EventLoop l, int fd, int events); + + void process_event(int flags) override; + +private: + int _fd; +}; diff --git a/iocore/net/CMakeLists.txt b/iocore/net/CMakeLists.txt index a3fbb97168d..96740421f84 100644 --- a/iocore/net/CMakeLists.txt +++ b/iocore/net/CMakeLists.txt @@ -19,6 +19,7 @@ add_library(inknet STATIC AcceptOptions.cc ALPNSupport.cc + AsyncSignalEventIO.cc BIO_fastopen.cc BoringSSLUtils.cc Connection.cc @@ -28,9 +29,11 @@ add_library(inknet STATIC Net.cc NetHandler.cc NetVCOptions.cc + NetAcceptEventIO.cc NetVConnection.cc PollCont.cc ProxyProtocol.cc + ReadWriteEventIO.cc Socks.cc SSLCertLookup.cc SSLClientCoordinator.cc @@ -57,6 +60,7 @@ add_library(inknet STATIC TLSSessionResumptionSupport.cc TLSSNISupport.cc TLSTunnelSupport.cc + UDPEventIO.cc UDPIOEvent.cc UnixConnection.cc UnixNet.cc diff --git a/iocore/net/EventIO.cc b/iocore/net/EventIO.cc index 7c4b7dafe39..eb95f0a137f 100644 --- a/iocore/net/EventIO.cc +++ b/iocore/net/EventIO.cc @@ -23,50 +23,6 @@ #include "EventIO.h" #include "tscore/ink_assert.h" -#include "P_Net.h" -#include "P_UnixNetProcessor.h" -#include "P_UnixNetVConnection.h" -#include "P_NetAccept.h" -#include "P_DNSConnection.h" -#include "P_UnixUDPConnection.h" -#include "P_UnixPollDescriptor.h" - -int -EventIO::start(EventLoop l, DNSConnection *vc, int events) -{ - type = EVENTIO_DNS_CONNECTION; - data.dnscon = vc; - return start_common(l, vc->fd, events); -} -int -EventIO::start(EventLoop l, NetAccept *vc, int events) -{ - type = EVENTIO_NETACCEPT; - data.na = vc; - return start_common(l, vc->server.fd, events); -} -int -EventIO::start(EventLoop l, NetEvent *ne, int events) -{ - type = EVENTIO_READWRITE_VC; - data.ne = ne; - return start_common(l, ne->get_fd(), events); -} - -int -EventIO::start(EventLoop l, UnixUDPConnection *vc, int events) -{ - type = EVENTIO_UDP_CONNECTION; - data.uc = vc; - return start_common(l, vc->fd, events); -} - -int -EventIO::start(EventLoop l, int afd, NetEvent *ne, int e) -{ - data.ne = ne; - return start_common(l, afd, e); -} int EventIO::start_common(EventLoop l, int afd, int e) @@ -210,19 +166,5 @@ EventIO::close() } stop(); - switch (type) { - default: - ink_assert(!"case"); - // fallthrough - case EVENTIO_DNS_CONNECTION: - return data.dnscon->close(); - break; - case EVENTIO_NETACCEPT: - return data.na->server.close(); - break; - case EVENTIO_READWRITE_VC: - return data.ne->close(); - break; - } - return -1; + return 0; } diff --git a/iocore/net/EventIO.h b/iocore/net/EventIO.h index c5136919707..07b4af1037c 100644 --- a/iocore/net/EventIO.h +++ b/iocore/net/EventIO.h @@ -24,17 +24,12 @@ #pragma once #include "P_UnixPollDescriptor.h" +using EventLoop = PollDescriptor *; + #define USE_EDGE_TRIGGER_EPOLL 1 #define USE_EDGE_TRIGGER_KQUEUE 1 #define USE_EDGE_TRIGGER_PORT 1 -#define EVENTIO_NETACCEPT 1 -#define EVENTIO_READWRITE_VC 2 -#define EVENTIO_DNS_CONNECTION 3 -#define EVENTIO_UDP_CONNECTION 4 -#define EVENTIO_ASYNC_SIGNAL 5 -#define EVENTIO_IO_URING 6 - #if TS_USE_EPOLL #ifndef EPOLLEXCLUSIVE #define EPOLLEXCLUSIVE 0 @@ -61,15 +56,6 @@ #define EVENTIO_ERROR (0x010 | 0x002 | 0x020) // ERR PRI HUP #endif -struct PollDescriptor; -using EventLoop = PollDescriptor *; - -class NetEvent; -class UnixUDPConnection; -class DiskHandler; -struct DNSConnection; -struct NetAccept; - /// Unified API for setting and clearing kernel and epoll events. struct EventIO { int fd = -1; ///< file descriptor, often a system port @@ -78,15 +64,6 @@ struct EventIO { #endif EventLoop event_loop = nullptr; ///< the assigned event loop bool syscall = true; ///< if false, disable all functionality (for QUIC) - int type = 0; ///< class identifier of union data. - union { - void *untyped; - NetEvent *ne; - DNSConnection *dnscon; - NetAccept *na; - UnixUDPConnection *uc; - DiskHandler *dh; - } data; ///< a kind of continuation /** The start methods all logically Setup a class to be called when a file descriptor is available for read or write. @@ -97,11 +74,6 @@ struct EventIO { @param events a mask of flags (for details `man epoll_ctl`) @return int the number of events created, -1 is error */ - int start(EventLoop l, DNSConnection *vc, int events); - int start(EventLoop l, NetAccept *vc, int events); - int start(EventLoop l, NetEvent *ne, int events); - int start(EventLoop l, UnixUDPConnection *vc, int events); - int start(EventLoop l, int fd, NetEvent *ne, int events); int start_common(EventLoop l, int fd, int events); /** Alter the events that will trigger the continuation, for level triggered I/O. @@ -119,8 +91,11 @@ struct EventIO { /// Remove the kernel or epoll event. Returns 0 on success. int stop(); - /// Remove the epoll event and close the connection. Returns 0 on success. - int close(); + virtual int close(); + + // Process one event that has triggered. + virtual void process_event(int flags) = 0; - EventIO() { data.untyped = nullptr; } + EventIO() {} + virtual ~EventIO() {} }; diff --git a/iocore/net/Makefile.am b/iocore/net/Makefile.am index edc95af8425..5780fdbece2 100644 --- a/iocore/net/Makefile.am +++ b/iocore/net/Makefile.am @@ -138,6 +138,8 @@ libinknet_a_SOURCES = \ AcceptOptions.cc \ AcceptOptions.h \ ALPNSupport.cc \ + AsyncSignalEventIO.cc \ + AsyncSignalEventIO.h \ BIO_fastopen.cc \ BIO_fastopen.h \ BoringSSLUtils.cc \ @@ -157,6 +159,8 @@ libinknet_a_SOURCES = \ YamlSNIConfig.h \ YamlSNIConfig.cc \ Net.cc \ + NetAcceptEventIO.h \ + NetAcceptEventIO.cc \ NetHandler.h \ NetHandler.cc \ NetVCOptions.h \ @@ -197,6 +201,8 @@ libinknet_a_SOURCES = \ PollCont.cc \ ProxyProtocol.h \ ProxyProtocol.cc \ + ReadWriteEventIO.h \ + ReadWriteEventIO.cc \ Socks.cc \ SSLCertLookup.cc \ SSLClientCoordinator.cc \ @@ -224,6 +230,8 @@ libinknet_a_SOURCES = \ TLSSNISupport.cc \ TLSTunnelSupport.cc \ TLSCertSwitchSupport.cc \ + UDPEventIO.h \ + UDPEventIO.cc \ UDPIOEvent.cc \ UnixConnection.cc \ UnixNet.cc \ diff --git a/iocore/net/NetAcceptEventIO.cc b/iocore/net/NetAcceptEventIO.cc new file mode 100644 index 00000000000..655506e5626 --- /dev/null +++ b/iocore/net/NetAcceptEventIO.cc @@ -0,0 +1,44 @@ +/** @file + + A brief file description + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include "NetAcceptEventIO.h" +#include "P_NetAccept.h" + +int +NetAcceptEventIO::start(EventLoop l, NetAccept *na, int events) +{ + _na = na; + return start_common(l, _na->server.fd, events); +} +void +NetAcceptEventIO::process_event(int flags) +{ + this_ethread()->schedule_imm(_na); +} + +int +NetAcceptEventIO::close() +{ + EventIO::stop(); // discard retval + return _na->server.close(); +} diff --git a/iocore/net/NetAcceptEventIO.h b/iocore/net/NetAcceptEventIO.h new file mode 100644 index 00000000000..325d7b13c97 --- /dev/null +++ b/iocore/net/NetAcceptEventIO.h @@ -0,0 +1,38 @@ +/** @file + + A brief file description + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#pragma once + +#include "EventIO.h" + +struct NetAccept; + +struct NetAcceptEventIO : public EventIO { + NetAcceptEventIO() : EventIO() {} + int start(EventLoop l, NetAccept *vc, int events); + void process_event(int flags) override; + int close() override; + +private: + NetAccept *_na = nullptr; +}; diff --git a/iocore/net/NetEvent.h b/iocore/net/NetEvent.h index 552d9878e02..3f6b94ef64b 100644 --- a/iocore/net/NetEvent.h +++ b/iocore/net/NetEvent.h @@ -25,9 +25,10 @@ #include -#include "EventIO.h" #include "I_EventSystem.h" #include "P_UnixNetState.h" +#include "EventIO.h" +#include "ReadWriteEventIO.h" class NetHandler; @@ -67,7 +68,7 @@ class NetEvent virtual Ptr &get_mutex() = 0; virtual ContFlags &get_control_flags() = 0; - EventIO ep{}; + ReadWriteEventIO ep{}; NetState read{}; NetState write{}; diff --git a/iocore/net/NetHandler.cc b/iocore/net/NetHandler.cc index 330463374dc..cf5289c6189 100644 --- a/iocore/net/NetHandler.cc +++ b/iocore/net/NetHandler.cc @@ -27,7 +27,6 @@ #include "I_IO_URING.h" #endif -#include "P_DNSConnection.h" #include "P_Net.h" #include "P_UnixNet.h" #include "P_UnixNetProcessor.h" @@ -50,9 +49,10 @@ NetHandler::startIO(NetEvent *ne) int res = 0; PollDescriptor *pd = get_PollDescriptor(this->thread); - if (ne->ep.start(pd, ne, EVENTIO_READ | EVENTIO_WRITE) < 0) { + if (ne->ep.start(pd, ne, get_NetHandler(this->thread), EVENTIO_READ | EVENTIO_WRITE) < 0) { res = errno; - // EEXIST should be ok, though it should have been cleared before we got back here + // 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; @@ -306,25 +306,12 @@ NetHandler::mainNetEvent(int event, Event *e) } } -static void -net_signal_hook_callback(EThread *thread) -{ -#if HAVE_EVENTFD - uint64_t counter; - ATS_UNUSED_RETURN(read(thread->evfd, &counter, sizeof(uint64_t))); -#else - char dummy[1024]; - ATS_UNUSED_RETURN(read(thread->evpipe[0], &dummy[0], 1024)); -#endif -} - int NetHandler::waitForActivity(ink_hrtime timeout) { EventIO *epd = nullptr; #if TS_USE_LINUX_IO_URING IOUringContext *ur = IOUringContext::local_context(); - bool servicedh = false; #endif NET_INCREMENT_DYN_STAT(net_handler_run_stat); @@ -342,67 +329,18 @@ NetHandler::waitForActivity(ink_hrtime timeout) // Get & Process polling result PollDescriptor *pd = get_PollDescriptor(this->thread); - NetEvent *ne = nullptr; for (int x = 0; x < pd->result; x++) { - epd = static_cast get_ev_data(pd, x); - if (epd->type == EVENTIO_READWRITE_VC) { - ne = epd->data.ne; - // Remove triggered NetEvent from cop_list because it won't be timeout before next InactivityCop runs. - if (cop_list.in(ne)) { - cop_list.remove(ne); - } - int flags = get_ev_events(pd, x); - if (flags & (EVENTIO_ERROR)) { - ne->set_error_from_socket(); - } - if (flags & (EVENTIO_READ)) { - ne->read.triggered = 1; - if (!read_ready_list.in(ne)) { - read_ready_list.enqueue(ne); - } - } - if (flags & (EVENTIO_WRITE)) { - ne->write.triggered = 1; - if (!write_ready_list.in(ne)) { - write_ready_list.enqueue(ne); - } - } else if (!(flags & (EVENTIO_READ))) { - Debug("iocore_net_main", "Unhandled epoll event: 0x%04x", flags); - // In practice we sometimes see EPOLLERR and EPOLLHUP through there - // Anything else would be surprising - ink_assert((flags & ~(EVENTIO_ERROR)) == 0); - ne->write.triggered = 1; - if (!write_ready_list.in(ne)) { - write_ready_list.enqueue(ne); - } - } - } else if (epd->type == EVENTIO_DNS_CONNECTION) { - if (epd->data.dnscon != nullptr) { - epd->data.dnscon->trigger(); // Make sure the DNSHandler for this con knows we triggered -#if defined(USE_EDGE_TRIGGER) - epd->refresh(EVENTIO_READ); -#endif - } - } else if (epd->type == EVENTIO_ASYNC_SIGNAL) { - net_signal_hook_callback(this->thread); - } else if (epd->type == EVENTIO_NETACCEPT) { - this->thread->schedule_imm(epd->data.na); -#if TS_USE_LINUX_IO_URING - } else if (epd->type == EVENTIO_IO_URING) { - servicedh = true; -#endif - } + epd = static_cast get_ev_data(pd, x); + int flags = get_ev_events(pd, x); + epd->process_event(flags); ev_next_event(pd, x); } pd->result = 0; process_ready_list(); - #if TS_USE_LINUX_IO_URING - if (servicedh) { - ur->service(); - } + ur->service(); #endif return EVENT_CONT; diff --git a/iocore/net/NetHandler.h b/iocore/net/NetHandler.h index b733fced2b3..9103aeabd34 100644 --- a/iocore/net/NetHandler.h +++ b/iocore/net/NetHandler.h @@ -107,10 +107,6 @@ class NetHandler : public Continuation, public EThread::LoopTailHandler Que(NetEvent, active_queue_link) active_queue; uint32_t active_queue_size = 0; -#ifdef TS_USE_LINUX_IO_URING - EventIO uring_evio; -#endif - /// configuration settings for managing the active and keep-alive queues struct Config { uint32_t max_connections_in = 0; diff --git a/iocore/net/P_NetAccept.h b/iocore/net/P_NetAccept.h index e116affe51c..ddeeb8b5af7 100644 --- a/iocore/net/P_NetAccept.h +++ b/iocore/net/P_NetAccept.h @@ -38,8 +38,8 @@ ****************************************************************************/ #pragma once -#include "EventIO.h" #include "I_NetProcessor.h" +#include "NetAcceptEventIO.h" #include #include "tscore/ink_platform.h" #include "P_Connection.h" @@ -91,7 +91,7 @@ struct NetAccept : public Continuation { int id = -1; Ptr action_; SSLNextProtocolAccept *snpa = nullptr; - EventIO ep; + NetAcceptEventIO ep; HttpProxyPort *proxyPort = nullptr; AcceptOptions opt; diff --git a/iocore/net/P_SSLNetVConnection.h b/iocore/net/P_SSLNetVConnection.h index 9c138da4a05..ff16d37e7e7 100644 --- a/iocore/net/P_SSLNetVConnection.h +++ b/iocore/net/P_SSLNetVConnection.h @@ -463,7 +463,7 @@ class SSLNetVConnection : public UnixNetVConnection, std::unique_ptr _ca_cert_file; std::unique_ptr _ca_cert_dir; - EventIO async_ep{}; + ReadWriteEventIO async_ep{}; // early data related stuff #if TS_HAS_TLS_EARLY_DATA diff --git a/iocore/net/P_UnixNet.h b/iocore/net/P_UnixNet.h index dc1a8d30860..3f1b8454b1b 100644 --- a/iocore/net/P_UnixNet.h +++ b/iocore/net/P_UnixNet.h @@ -30,6 +30,13 @@ #include "PollCont.h" #include "EventIO.h" #include "NetHandler.h" +#include "tscore/ink_platform.h" + +#if TS_USE_LINUX_IO_URING +#include "IOUringEventIO.h" +#endif + +#include "P_DNSConnection.h" #include "P_Net.h" #include "P_NetAccept.h" #include "P_UnixNetProcessor.h" diff --git a/iocore/net/P_UnixUDPConnection.h b/iocore/net/P_UnixUDPConnection.h index abed93ed324..27cdb2da29f 100644 --- a/iocore/net/P_UnixUDPConnection.h +++ b/iocore/net/P_UnixUDPConnection.h @@ -31,6 +31,7 @@ #pragma once #include "P_UDPConnection.h" +#include "UDPEventIO.h" class UnixUDPConnection : public UDPConnectionInternal { @@ -48,7 +49,7 @@ class UnixUDPConnection : public UDPConnectionInternal int onCallbackQueue = 0; Action *callbackAction = nullptr; EThread *ethread = nullptr; - EventIO ep; + UDPEventIO ep; UnixUDPConnection(int the_fd); ~UnixUDPConnection() override; diff --git a/iocore/net/QUICNetProcessor_quiche.cc b/iocore/net/QUICNetProcessor_quiche.cc index 741df02eb2a..fe9e12eaf22 100644 --- a/iocore/net/QUICNetProcessor_quiche.cc +++ b/iocore/net/QUICNetProcessor_quiche.cc @@ -170,7 +170,7 @@ QUICNetProcessor::connect_re(Continuation *cont, sockaddr const *remote_addr, Ne PollDescriptor *pd = pc->pollDescriptor; errno = 0; - int res = con->ep.start(pd, con, EVENTIO_READ); + int res = con->ep.start(pd, con, get_UDPNetHandler(cont->getThreadAffinity()), EVENTIO_READ); if (res < 0) { Debug("udpnet", "Error: %s (%d)", strerror(errno), errno); } diff --git a/iocore/net/ReadWriteEventIO.cc b/iocore/net/ReadWriteEventIO.cc new file mode 100644 index 00000000000..3a45d831ab4 --- /dev/null +++ b/iocore/net/ReadWriteEventIO.cc @@ -0,0 +1,83 @@ +/**@file + + A brief file description + + @section license License + + Licensed to the Apache Software + Foundation(ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include "ReadWriteEventIO.h" +#include "NetHandler.h" + +int +ReadWriteEventIO::start(EventLoop l, NetEvent *ne, NetHandler *nh, int events) +{ + _ne = ne; + _nh = nh; + return start_common(l, ne->get_fd(), events); +} + +int +ReadWriteEventIO::start(EventLoop l, int afd, NetEvent *ne, NetHandler *nh, int events) +{ + _ne = ne; + _nh = nh; + return start_common(l, afd, events); +} + +void +ReadWriteEventIO::process_event(int flags) +{ + // Remove triggered NetEvent from cop_list because it won't be timeout before + // next InactivityCop runs. + if (_nh->cop_list.in(_ne)) { + _nh->cop_list.remove(_ne); + } + if (flags & (EVENTIO_ERROR)) { + _ne->set_error_from_socket(); + } + if (flags & (EVENTIO_READ)) { + _ne->read.triggered = 1; + if (!_nh->read_ready_list.in(_ne)) { + _nh->read_ready_list.enqueue(_ne); + } + } + if (flags & (EVENTIO_WRITE)) { + _ne->write.triggered = 1; + if (!_nh->write_ready_list.in(_ne)) { + _nh->write_ready_list.enqueue(_ne); + } + } else if (!(flags & (EVENTIO_READ))) { + Debug("iocore_net_main", "Unhandled epoll event: 0x%04x", flags); + // In practice we sometimes see EPOLLERR and EPOLLHUP through there + // Anything else would be surprising + ink_assert((flags & ~(EVENTIO_ERROR)) == 0); + _ne->write.triggered = 1; + if (!_nh->write_ready_list.in(_ne)) { + _nh->write_ready_list.enqueue(_ne); + } + } +} + +int +ReadWriteEventIO::close() +{ + EventIO::close(); // discard retval + return _ne->close(); +} diff --git a/iocore/net/ReadWriteEventIO.h b/iocore/net/ReadWriteEventIO.h new file mode 100644 index 00000000000..2b8755b1209 --- /dev/null +++ b/iocore/net/ReadWriteEventIO.h @@ -0,0 +1,44 @@ +/**@file + + A brief file description + + @section license License + + Licensed to the Apache Software + Foundation(ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#pragma once + +#include "EventIO.h" + +class NetHandler; +class NetEvent; + +class ReadWriteEventIO : public EventIO +{ +public: + ReadWriteEventIO() : EventIO() {} + int start(EventLoop l, NetEvent *ne, NetHandler *nh, int events); + int start(EventLoop l, int afd, NetEvent *ne, NetHandler *nh, int events); + void process_event(int flags) override; + int close() override; + +private: + NetEvent *_ne = nullptr; + NetHandler *_nh = nullptr; +}; diff --git a/iocore/net/SSLNetVConnection.cc b/iocore/net/SSLNetVConnection.cc index 376969af069..7428980c94b 100644 --- a/iocore/net/SSLNetVConnection.cc +++ b/iocore/net/SSLNetVConnection.cc @@ -1293,8 +1293,7 @@ SSLNetVConnection::sslServerHandShakeEvent(int &err) // Have to have the read NetState enabled because we are using it for the signal vc read.enabled = true; PollDescriptor *pd = get_PollDescriptor(this_ethread()); - this->async_ep.start(pd, waitfds[0], static_cast(this), EVENTIO_READ); - this->async_ep.type = EVENTIO_READWRITE_VC; + this->async_ep.start(pd, waitfds[0], static_cast(this), get_NetHandler(this->thread), EVENTIO_READ); } } } diff --git a/iocore/net/UDPEventIO.cc b/iocore/net/UDPEventIO.cc new file mode 100644 index 00000000000..2c55c0125a5 --- /dev/null +++ b/iocore/net/UDPEventIO.cc @@ -0,0 +1,52 @@ +/** @file + + A brief file description + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include "UDPEventIO.h" +#include "P_UDPNet.h" + +int +UDPEventIO::start(EventLoop l, UnixUDPConnection *uc, UDPNetHandler *uh, int events) +{ + _uc = uc; + _uh = uh; + return start_common(l, uc->fd, events); +} + +void +UDPEventIO::process_event(int flags) +{ + // TODO: handle EVENTIO_ERROR + if (flags & EVENTIO_READ) { + ink_assert(_uc && _uc->mutex && _uc->continuation); + ink_assert(_uc->refcount >= 1); + _uh->open_list.in_or_enqueue(_uc); // due to the above race + if (_uc->shouldDestroy()) { + _uh->open_list.remove(_uc); + _uc->Release(); + } else { + udpNetInternal.udp_read_from_net(_uh, _uc); + } + } else { + Debug("iocore_udp_main", "Unhandled epoll event: 0x%04x", flags); + } +} diff --git a/iocore/net/UDPEventIO.h b/iocore/net/UDPEventIO.h new file mode 100644 index 00000000000..b5623d37929 --- /dev/null +++ b/iocore/net/UDPEventIO.h @@ -0,0 +1,41 @@ +/** @file + + A brief file description + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#pragma once + +#include "EventIO.h" + +class UDPNetHandler; +class UnixUDPConnection; + +class UDPEventIO : public EventIO +{ +public: + UDPEventIO() : EventIO() {} + int start(EventLoop l, UnixUDPConnection *uc, UDPNetHandler *uh, int events); + void process_event(int flags) override; + +private: + UnixUDPConnection *_uc = nullptr; + UDPNetHandler *_uh = nullptr; +}; diff --git a/iocore/net/UnixNet.cc b/iocore/net/UnixNet.cc index 0b33378cc67..f9529515e44 100644 --- a/iocore/net/UnixNet.cc +++ b/iocore/net/UnixNet.cc @@ -21,6 +21,7 @@ limitations under the License. */ +#include "AsyncSignalEventIO.h" #include "P_Net.h" #include "P_UnixNet.h" #include "tscore/ink_hrtime.h" @@ -44,13 +45,13 @@ const std::bitset NetHandler::config_value_affect NetHandler * get_NetHandler(EThread *t) { - return (NetHandler *)ETHREAD_GET_PTR(t, unix_netProcessor.netHandler_offset); + return static_cast(ETHREAD_GET_PTR(t, unix_netProcessor.netHandler_offset)); } PollCont * get_PollCont(EThread *t) { - return (PollCont *)ETHREAD_GET_PTR(t, unix_netProcessor.pollCont_offset); + return static_cast(ETHREAD_GET_PTR(t, unix_netProcessor.pollCont_offset)); } PollDescriptor * @@ -174,17 +175,18 @@ initialize_thread_for_net(EThread *thread) thread->schedule_every(inactivityCop, HRTIME_SECONDS(cop_freq)); thread->set_tail_handler(nh); - thread->ep = static_cast(ats_malloc(sizeof(EventIO))); - new (thread->ep) EventIO(); - thread->ep->type = EVENTIO_ASYNC_SIGNAL; + #if HAVE_EVENTFD - thread->ep->start(pd, thread->evfd, nullptr, EVENTIO_READ); +#if TS_USE_LINUX_IO_URING + auto ep = new IOUringEventIO(); + ep->start(pd, IOUringContext::local_context()); #else - thread->ep->start(pd, thread->evpipe[0], nullptr, EVENTIO_READ); + auto ep = new AsyncSignalEventIO(); + ep->start(pd, thread->evfd, EVENTIO_READ); #endif - -#if TS_USE_LINUX_IO_URING - nh->uring_evio.type = EVENTIO_IO_URING; - nh->uring_evio.start(pd, IOUringContext::local_context()->register_eventfd(), nullptr, EVENTIO_READ); +#else + auto ep = new AsyncSignalEventIO(); + ep->start(pd, thread->evpipe[0], EVENTIO_READ); #endif + thread->ep = ep; } diff --git a/iocore/net/UnixUDPNet.cc b/iocore/net/UnixUDPNet.cc index 6f7ce146d4c..20ced13e27f 100644 --- a/iocore/net/UnixUDPNet.cc +++ b/iocore/net/UnixUDPNet.cc @@ -34,13 +34,17 @@ #define __APPLE_USE_RFC_3542 #endif -#include "P_DNSConnection.h" +#include "AsyncSignalEventIO.h" +#include "I_AIO.h" +#if TS_USE_LINUX_IO_URING +#include "I_IO_URING.h" +#endif #include "P_Net.h" #include "P_UDPNet.h" #include "tscore/ink_inet.h" - #include "tscore/ink_sock.h" #include +#include "P_UnixNet.h" #ifndef UDP_SEGMENT // This is needed because old glibc may not have the constant even if Kernel supports it. @@ -253,14 +257,19 @@ initialize_thread_for_udp_net(EThread *thread) g_udp_numSendRetries = g_udp_numSendRetries < 0 ? 0 : g_udp_numSendRetries; thread->set_tail_handler(nh); - thread->ep = static_cast(ats_malloc(sizeof(EventIO))); - new (thread->ep) EventIO(); - thread->ep->type = EVENTIO_ASYNC_SIGNAL; #if HAVE_EVENTFD - thread->ep->start(upd, thread->evfd, nullptr, EVENTIO_READ); +#if TS_USE_LINUX_IO_URING + auto ep = new IOUringEventIO(); + ep->start(upd, IOUringContext::local_context()); #else - thread->ep->start(upd, thread->evpipe[0], nullptr, EVENTIO_READ); + auto ep = new AsyncSignalEventIO(); + ep->start(upd, thread->evfd, EVENTIO_READ); #endif +#else + auto ep = new AsyncSignalEventIO(); + ep->start(upd, thread->evpipe[0], EVENTIO_READ); +#endif + thread->ep = ep; } EventType @@ -1238,7 +1247,7 @@ UDPNetProcessor::UDPBind(Continuation *cont, sockaddr const *addr, int fd, int s pc = get_UDPPollCont(n->ethread); pd = pc->pollDescriptor; - n->ep.start(pd, n, EVENTIO_READ); + n->ep.start(pd, n, get_UDPNetHandler(cont->getThreadAffinity()), EVENTIO_READ); cont->handleEvent(NET_EVENT_DATAGRAM_OPEN, n); return ACTION_RESULT_DONE; @@ -1696,18 +1705,6 @@ UDPQueue::SendMultipleUDPPackets(UDPPacket **p, uint16_t n) #undef LINK -static void -net_signal_hook_callback(EThread *thread) -{ -#if HAVE_EVENTFD - uint64_t counter; - ATS_UNUSED_RETURN(read(thread->evfd, &counter, sizeof(uint64_t))); -#else - char dummy[1024]; - ATS_UNUSED_RETURN(read(thread->evpipe[0], &dummy[0], 1024)); -#endif -} - UDPNetHandler::UDPNetHandler(Cfg &&cfg) : udpOutQueue(cfg.enable_gso), _cfg{std::move(cfg)} { nextCheck = Thread::get_hrtime_updated() + HRTIME_MSECONDS(1000); @@ -1778,34 +1775,9 @@ UDPNetHandler::waitForActivity(ink_hrtime timeout) int i = 0; EventIO *epd = nullptr; for (i = 0; i < pc->pollDescriptor->result; i++) { - epd = static_cast get_ev_data(pc->pollDescriptor, i); - if (epd->type == EVENTIO_UDP_CONNECTION) { - // TODO: handle EVENTIO_ERROR - if (get_ev_events(pc->pollDescriptor, i) & EVENTIO_READ) { - uc = epd->data.uc; - ink_assert(uc && uc->mutex && uc->continuation); - ink_assert(uc->refcount >= 1); - open_list.in_or_enqueue(uc); // due to the above race - if (uc->shouldDestroy()) { - open_list.remove(uc); - uc->Release(); - } else { - udpNetInternal.udp_read_from_net(this, uc); - } - } else { - Debug("iocore_udp_main", "Unhandled epoll event: 0x%04x", get_ev_events(pc->pollDescriptor, i)); - } - } else if (epd->type == EVENTIO_DNS_CONNECTION) { - // TODO: handle DNS conn if there is ET_UDP - if (epd->data.dnscon != nullptr) { - epd->data.dnscon->trigger(); -#if defined(USE_EDGE_TRIGGER) - epd->refresh(EVENTIO_READ); -#endif - } - } else if (epd->type == EVENTIO_ASYNC_SIGNAL) { - net_signal_hook_callback(this->thread); - } + epd = static_cast get_ev_data(pc->pollDescriptor, i); + int flags = get_ev_events(pc->pollDescriptor, i); + epd->process_event(flags); } // end for // remove dead UDP connections From 9294c6c990d220d35a46a13b8dfee3311c66529a Mon Sep 17 00:00:00 2001 From: Mo Chen Date: Mon, 17 Jul 2023 17:58:15 -0500 Subject: [PATCH 2/4] Remove unused EventIO::close() --- iocore/dns/DNSEventIO.cc | 7 ------- iocore/dns/DNSEventIO.h | 1 - iocore/net/EventIO.cc | 11 ----------- iocore/net/EventIO.h | 25 ++++++++++++------------- iocore/net/NetAcceptEventIO.cc | 7 ------- iocore/net/NetAcceptEventIO.h | 1 - iocore/net/ReadWriteEventIO.cc | 7 ------- iocore/net/ReadWriteEventIO.h | 1 - 8 files changed, 12 insertions(+), 48 deletions(-) diff --git a/iocore/dns/DNSEventIO.cc b/iocore/dns/DNSEventIO.cc index 00406ba27e1..1e68ef4ff09 100644 --- a/iocore/dns/DNSEventIO.cc +++ b/iocore/dns/DNSEventIO.cc @@ -36,10 +36,3 @@ DNSEventIO::process_event(int flags) _c.trigger(); // Make sure the DNSHandler for this con knows we triggered refresh(EVENTIO_READ); } - -int -DNSEventIO::close() -{ - EventIO::close(); // discard retval - return _c.close(); -} diff --git a/iocore/dns/DNSEventIO.h b/iocore/dns/DNSEventIO.h index 98c7163e687..9e8c8304e23 100644 --- a/iocore/dns/DNSEventIO.h +++ b/iocore/dns/DNSEventIO.h @@ -40,7 +40,6 @@ class DNSEventIO : public EventIO DNSEventIO(DNSConnection &c) : EventIO(), _c(c) {} int start(EventLoop l, int fd, int events); void process_event(int flags) override; - int close() override; private: DNSConnection &_c; diff --git a/iocore/net/EventIO.cc b/iocore/net/EventIO.cc index eb95f0a137f..34f4d965fe8 100644 --- a/iocore/net/EventIO.cc +++ b/iocore/net/EventIO.cc @@ -157,14 +157,3 @@ EventIO::stop() } return 0; } - -int -EventIO::close() -{ - if (!this->syscall) { - return 0; - } - - stop(); - return 0; -} diff --git a/iocore/net/EventIO.h b/iocore/net/EventIO.h index 07b4af1037c..684dc5ca33f 100644 --- a/iocore/net/EventIO.h +++ b/iocore/net/EventIO.h @@ -65,17 +65,6 @@ struct EventIO { EventLoop event_loop = nullptr; ///< the assigned event loop bool syscall = true; ///< if false, disable all functionality (for QUIC) - /** The start methods all logically Setup a class to be called - when a file descriptor is available for read or write. - The type of the classes vary. Generally the file descriptor - is pulled from the class, but there is one option that lets - the file descriptor be expressed directly. - @param l the event loop - @param events a mask of flags (for details `man epoll_ctl`) - @return int the number of events created, -1 is error - */ - int start_common(EventLoop l, int fd, int events); - /** Alter the events that will trigger the continuation, for level triggered I/O. @param events add with positive mask(+EVENTIO_READ), or remove with negative mask (-EVENTIO_READ) @return int the number of events created, -1 is error @@ -91,11 +80,21 @@ struct EventIO { /// Remove the kernel or epoll event. Returns 0 on success. int stop(); - virtual int close(); - // Process one event that has triggered. virtual void process_event(int flags) = 0; EventIO() {} virtual ~EventIO() {} + +protected: + /** The start methods all logically Setup a class to be called + when a file descriptor is available for read or write. + The type of the classes vary. Generally the file descriptor + is pulled from the class, but there is one option that lets + the file descriptor be expressed directly. + @param l the event loop + @param events a mask of flags (for details `man epoll_ctl`) + @return int the number of events created, -1 is error + */ + int start_common(EventLoop l, int fd, int events); }; diff --git a/iocore/net/NetAcceptEventIO.cc b/iocore/net/NetAcceptEventIO.cc index 655506e5626..21db723745f 100644 --- a/iocore/net/NetAcceptEventIO.cc +++ b/iocore/net/NetAcceptEventIO.cc @@ -35,10 +35,3 @@ NetAcceptEventIO::process_event(int flags) { this_ethread()->schedule_imm(_na); } - -int -NetAcceptEventIO::close() -{ - EventIO::stop(); // discard retval - return _na->server.close(); -} diff --git a/iocore/net/NetAcceptEventIO.h b/iocore/net/NetAcceptEventIO.h index 325d7b13c97..0e525bba07e 100644 --- a/iocore/net/NetAcceptEventIO.h +++ b/iocore/net/NetAcceptEventIO.h @@ -31,7 +31,6 @@ struct NetAcceptEventIO : public EventIO { NetAcceptEventIO() : EventIO() {} int start(EventLoop l, NetAccept *vc, int events); void process_event(int flags) override; - int close() override; private: NetAccept *_na = nullptr; diff --git a/iocore/net/ReadWriteEventIO.cc b/iocore/net/ReadWriteEventIO.cc index 3a45d831ab4..0e86d69b10c 100644 --- a/iocore/net/ReadWriteEventIO.cc +++ b/iocore/net/ReadWriteEventIO.cc @@ -74,10 +74,3 @@ ReadWriteEventIO::process_event(int flags) } } } - -int -ReadWriteEventIO::close() -{ - EventIO::close(); // discard retval - return _ne->close(); -} diff --git a/iocore/net/ReadWriteEventIO.h b/iocore/net/ReadWriteEventIO.h index 2b8755b1209..2152e3715fc 100644 --- a/iocore/net/ReadWriteEventIO.h +++ b/iocore/net/ReadWriteEventIO.h @@ -36,7 +36,6 @@ class ReadWriteEventIO : public EventIO int start(EventLoop l, NetEvent *ne, NetHandler *nh, int events); int start(EventLoop l, int afd, NetEvent *ne, NetHandler *nh, int events); void process_event(int flags) override; - int close() override; private: NetEvent *_ne = nullptr; From cc7753ea97ea8648cd83325c2fc5fa7c9f8210a5 Mon Sep 17 00:00:00 2001 From: Mo Chen Date: Wed, 19 Jul 2023 14:07:25 -0500 Subject: [PATCH 3/4] NetHandler: use this instead of going the long way --- iocore/net/NetHandler.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/iocore/net/NetHandler.cc b/iocore/net/NetHandler.cc index cf5289c6189..757d373c4e2 100644 --- a/iocore/net/NetHandler.cc +++ b/iocore/net/NetHandler.cc @@ -49,10 +49,9 @@ NetHandler::startIO(NetEvent *ne) int res = 0; PollDescriptor *pd = get_PollDescriptor(this->thread); - if (ne->ep.start(pd, ne, get_NetHandler(this->thread), EVENTIO_READ | EVENTIO_WRITE) < 0) { + if (ne->ep.start(pd, ne, this, EVENTIO_READ | EVENTIO_WRITE) < 0) { res = errno; - // EEXIST should be ok, though it should have been cleared before we got - // back here + // 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; From b124ea1c83526b2a4399a66ea1267cdccf4ee625 Mon Sep 17 00:00:00 2001 From: Mo Chen Date: Fri, 28 Jul 2023 13:48:28 -0500 Subject: [PATCH 4/4] Fix PR according to review --- iocore/dns/DNSEventIO.cc | 5 +---- iocore/net/AsyncSignalEventIO.cc | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/iocore/dns/DNSEventIO.cc b/iocore/dns/DNSEventIO.cc index 1e68ef4ff09..479aa839922 100644 --- a/iocore/dns/DNSEventIO.cc +++ b/iocore/dns/DNSEventIO.cc @@ -1,7 +1,4 @@ -/** @file - - A brief file description - +/** @section license License Licensed to the Apache Software Foundation (ASF) under one diff --git a/iocore/net/AsyncSignalEventIO.cc b/iocore/net/AsyncSignalEventIO.cc index 941dd31f2da..f6f615456cc 100644 --- a/iocore/net/AsyncSignalEventIO.cc +++ b/iocore/net/AsyncSignalEventIO.cc @@ -37,9 +37,9 @@ AsyncSignalEventIO::process_event(int flags) { #if HAVE_EVENTFD uint64_t counter; - ATS_UNUSED_RETURN(read(_fd, &counter, sizeof(uint64_t))); + static_cast(read(_fd, &counter, sizeof(uint64_t))); #else char dummy[1024]; - ATS_UNUSED_RETURN(read(_fd, &dummy[0], 1024)); + static_cast(read(_fd, &dummy[0], 1024)); #endif }