You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jv...@apache.org on 2026/10/21 18:21:56 UTC
(trafficserver) branch master updated: Remove unused asynchronous UDP library (#13823)
This is an automated email from the ASF dual-hosted git repository.
JosiahWI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 32209e8858 Remove unused asynchronous UDP library (#13823)
32209e8858 is described below
commit 32209e8858001859a509a07733baa72ad8579746
Author: JosiahWI <41...@users.noreply.github.com>
AuthorDate: Wed Oct 21 13:21:49 2026 -0500
Remove unused asynchronous UDP library (#13823)
This patch removes code that seems to have been unused for a long time.
---
include/iocore/net/UDPNet.h | 27 ---
src/iocore/net/CMakeLists.txt | 1 -
src/iocore/net/P_CompletionUtil.h | 126 --------------
src/iocore/net/P_UDPIOEvent.h | 110 -------------
src/iocore/net/UDPIOEvent.cc | 27 ---
src/iocore/net/UnixUDPNet.cc | 336 --------------------------------------
6 files changed, 627 deletions(-)
diff --git a/include/iocore/net/UDPNet.h b/include/iocore/net/UDPNet.h
index 6cf7f360c6..5ea26695de 100644
--- a/include/iocore/net/UDPNet.h
+++ b/include/iocore/net/UDPNet.h
@@ -75,33 +75,6 @@ public:
created successfully, or ACTION_IO_ERROR if not.
*/
Action *UDPBind(Continuation *c, sockaddr const *addr, int fd = -1, int send_bufsize = 0, int recv_bufsize = 0);
-
- // Regarding sendto_re, sendmsg_re, recvfrom_re:
- // * You may be called back on 'c' with completion or error status.
- // * 'token' is an opaque which can be used by caller to match up the I/O
- // with the completion event.
- // * If IOBufferBlock * is passed in the interface, it is reference
- // counted internally.
- // * For recvfrom_re, data is written beginning at IOBufferBlock::end() and
- // the IOBufferBlock is not fill()'ed until I/O actually occurs. This
- // kind of implies that you can only have one outstanding I/O per
- // IOBufferBlock
- // Callback:
- // * callback signature is: handleEvent(int event,CompletionEvent *cevent);
- // where event is one of:
- // NET_EVENT_DATAGRAM_WRITE_COMPLETE
- // NET_EVENT_DATAGRAM_WRITE_ERROR
- // * You can get the value of 'token' that you passed in by calling
- // completionUtil::getHandle(cevent);
- // * You can get other info about the completed operation through use
- // of the completionUtil class.
- Action *sendto_re(Continuation *c, void *token, int fd, sockaddr const *toaddr, int toaddrlen, IOBufferBlock *buf, int len);
- // I/O buffers referenced by msg must be pinned by the caller until
- // continuation is called back.
- Action *sendmsg_re(Continuation *c, void *token, int fd, struct msghdr *msg);
-
- Action *recvfrom_re(Continuation *c, void *token, int fd, sockaddr *fromaddr, socklen_t *fromaddrlen, IOBufferBlock *buf, int len,
- bool useReadCont = true, int timeout = 0);
};
extern UDPNetProcessor &udpNet;
diff --git a/src/iocore/net/CMakeLists.txt b/src/iocore/net/CMakeLists.txt
index dc185d310f..7b370dded4 100644
--- a/src/iocore/net/CMakeLists.txt
+++ b/src/iocore/net/CMakeLists.txt
@@ -64,7 +64,6 @@ add_library(
TLSTunnelSupport.cc
TLSCertCompression.cc
UDPEventIO.cc
- UDPIOEvent.cc
UnixConnection.cc
UnixNet.cc
UnixNetAccept.cc
diff --git a/src/iocore/net/P_CompletionUtil.h b/src/iocore/net/P_CompletionUtil.h
deleted file mode 100644
index 66cbc08ea9..0000000000
--- a/src/iocore/net/P_CompletionUtil.h
+++ /dev/null
@@ -1,126 +0,0 @@
-/** @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
-// platform specific wrappers for dealing with I/O completion events
-// passed into and back from the I/O core.
-
-#include "P_UDPIOEvent.h"
-#include "iocore/eventsystem/Event.h"
-#include "iocore/eventsystem/IOBuffer.h"
-
-#if TS_USE_TLS_ASYNC
-#include <openssl/async.h>
-#endif
-
-class completionUtil
-{
-public:
- static Event *create();
- static void destroy(Event *e);
- static void setThread(Event *e, EThread *t);
- static void setContinuation(Event *e, Continuation *c);
- static void *getHandle(Event *e);
- static void setHandle(Event *e, void *handle);
- static void setInfo(Event *e, int fd, const Ptr<IOBufferBlock> &buf, int actual, int errno_);
- static void setInfo(Event *e, int fd, struct msghdr *msg, int actual, int errno_);
- static int getBytesTransferred(Event *e);
- static IOBufferBlock *getIOBufferBlock(Event *e);
- static Continuation *getContinuation(Event *e);
- static int getError(Event *e);
- static void releaseReferences(Event *e);
-};
-
-TS_INLINE Event *
-completionUtil::create()
-{
- UDPIOEvent *u = UDPIOEventAllocator.alloc();
- return u;
-}
-TS_INLINE void
-completionUtil::destroy(Event *e)
-{
- ink_assert(e != nullptr);
- UDPIOEvent *u = static_cast<UDPIOEvent *>(e);
- UDPIOEvent::free(u);
-}
-TS_INLINE void
-completionUtil::setThread(Event *e, EThread *t)
-{
- UDPIOEvent *u = static_cast<UDPIOEvent *>(e);
- u->ethread = t;
-}
-TS_INLINE void
-completionUtil::setContinuation(Event *e, Continuation *c)
-{
- UDPIOEvent *u = static_cast<UDPIOEvent *>(e);
- *static_cast<Action *>(u) = c;
-}
-TS_INLINE void *
-completionUtil::getHandle(Event *e)
-{
- UDPIOEvent *u = static_cast<UDPIOEvent *>(e);
- return u->getHandle();
-}
-TS_INLINE void
-completionUtil::setHandle(Event *e, void *handle)
-{
- UDPIOEvent *u = static_cast<UDPIOEvent *>(e);
- u->setHandle(handle);
-}
-TS_INLINE void
-completionUtil::setInfo(Event *e, int fd, const Ptr<IOBufferBlock> &buf, int actual, int errno_)
-{
- UDPIOEvent *u = static_cast<UDPIOEvent *>(e);
- u->setInfo(fd, buf, actual, errno_);
-}
-TS_INLINE void
-completionUtil::setInfo(Event *e, int fd, struct msghdr *msg, int actual, int errno_)
-{
- UDPIOEvent *u = static_cast<UDPIOEvent *>(e);
- u->setInfo(fd, msg, actual, errno_);
-}
-TS_INLINE int
-completionUtil::getBytesTransferred(Event *e)
-{
- UDPIOEvent *u = static_cast<UDPIOEvent *>(e);
- return u->getBytesTransferred();
-}
-TS_INLINE IOBufferBlock *
-completionUtil::getIOBufferBlock(Event *e)
-{
- UDPIOEvent *u = static_cast<UDPIOEvent *>(e);
- return u->getIOBufferBlock();
-}
-TS_INLINE Continuation *
-completionUtil::getContinuation(Event *e)
-{
- UDPIOEvent *u = static_cast<UDPIOEvent *>(e);
- return u->getContinuation();
-}
-TS_INLINE int
-completionUtil::getError(Event *e)
-{
- UDPIOEvent *u = static_cast<UDPIOEvent *>(e);
- return u->getError();
-}
diff --git a/src/iocore/net/P_UDPIOEvent.h b/src/iocore/net/P_UDPIOEvent.h
deleted file mode 100644
index 075ad7ddee..0000000000
--- a/src/iocore/net/P_UDPIOEvent.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/** @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
-// ugly -- just encapsulate the I/O result so that it can be passed
-// back to the caller via continuation handler.
-
-#include "iocore/eventsystem/Event.h"
-#include "iocore/eventsystem/IOBuffer.h"
-class UDPIOEvent : public Event
-{
-public:
- UDPIOEvent() : b(nullptr){};
- ~UDPIOEvent() override{};
-
- void
- setInfo(int fd_, const Ptr<IOBufferBlock> &b_, int bytesTransferred_, int errno_)
- {
- fd = fd_;
- b = b_;
- bytesTransferred = bytesTransferred_;
- err = errno_;
- };
-
- void
- setInfo(int fd_, struct msghdr *m_, int bytesTransferred_, int errno_)
- {
- fd = fd_;
- m = m_;
- bytesTransferred = bytesTransferred_;
- err = errno_;
- };
-
- void
- setHandle(void *v)
- {
- handle = v;
- }
-
- void *
- getHandle()
- {
- return handle;
- }
-
- int
- getBytesTransferred() const
- {
- return bytesTransferred;
- }
-
- IOBufferBlock *
- getIOBufferBlock() const
- {
- return b.get();
- }
-
- int
- getError() const
- {
- return err;
- }
-
- Continuation *
- getContinuation() const
- {
- return continuation;
- }
-
- void free();
- static void free(UDPIOEvent *e);
-
-private:
- void *operator new(size_t size); // undefined
- int fd = -1;
- int err = 0; // error code
- struct msghdr *m = nullptr;
- void *handle = nullptr; // some extra data for the client handler
- Ptr<IOBufferBlock> b; // holds buffer that I/O will go to
- int bytesTransferred = 0; // actual bytes transferred
-};
-
-extern ClassAllocator<UDPIOEvent, false> UDPIOEventAllocator;
-TS_INLINE void
-UDPIOEvent::free(UDPIOEvent *e)
-{
- e->b = nullptr;
- e->mutex = nullptr;
- UDPIOEventAllocator.free(e);
-}
diff --git a/src/iocore/net/UDPIOEvent.cc b/src/iocore/net/UDPIOEvent.cc
deleted file mode 100644
index f25767d83d..0000000000
--- a/src/iocore/net/UDPIOEvent.cc
+++ /dev/null
@@ -1,27 +0,0 @@
-/** @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 "tscore/Allocator.h"
-#include "P_UDPIOEvent.h"
-
-ClassAllocator<UDPIOEvent, false> UDPIOEventAllocator("UDPIOEventAllocator");
diff --git a/src/iocore/net/UnixUDPNet.cc b/src/iocore/net/UnixUDPNet.cc
index 48f329be46..a6b942deaf 100644
--- a/src/iocore/net/UnixUDPNet.cc
+++ b/src/iocore/net/UnixUDPNet.cc
@@ -38,7 +38,6 @@
#include "P_UnixPollDescriptor.h"
#include "P_UnixUDPConnection.h"
#include "P_UDPNet.h"
-#include "P_CompletionUtil.h"
#include "records/RecCore.h"
#include "iocore/net/AsyncSignalEventIO.h"
#include "iocore/net/Net.h"
@@ -705,341 +704,6 @@ UDPNetProcessorInternal::udp_callback(UDPNetHandler *, UDPConnection *xuc, EThre
}
}
-#define UNINITIALIZED_EVENT_PTR (Event *)0xdeadbeef
-
-// cheesy implementation of a asynchronous read and callback for Unix
-class UDPReadContinuation : public Continuation
-{
-public:
- UDPReadContinuation(Event *completionToken);
- UDPReadContinuation();
- ~UDPReadContinuation() override;
- inline void free();
- inline void init_token(Event *completionToken);
- inline void init_read(int fd, IOBufferBlock *buf, int len, struct sockaddr *fromaddr, socklen_t *fromaddrlen);
-
- void
- set_timer(int seconds)
- {
- timeout_interval = HRTIME_SECONDS(seconds);
- }
-
- void cancel();
- int readPollEvent(int event, Event *e);
-
- Action *
- getAction()
- {
- return event;
- }
-
- void setupPollDescriptor();
-
-private:
- Event *event = UNINITIALIZED_EVENT_PTR; // the completion event token created
- // on behalf of the client
- Ptr<IOBufferBlock> readbuf{nullptr};
- int readlen = 0;
- struct sockaddr_in6 *fromaddr = nullptr;
- socklen_t *fromaddrlen = nullptr;
- int fd = NO_FD; // fd we are reading from
- int ifd = NO_FD; // poll fd index
- ink_hrtime period = 0; // polling period
- ink_hrtime elapsed_time = 0;
- ink_hrtime timeout_interval = 0;
-};
-
-ClassAllocator<UDPReadContinuation, false> udpReadContAllocator("udpReadContAllocator");
-
-UDPReadContinuation::UDPReadContinuation(Event *completionToken)
- : Continuation(nullptr),
- event(completionToken),
- readbuf(nullptr),
-
- fd(-1),
- ifd(-1)
-
-{
- if (completionToken->continuation) {
- this->mutex = completionToken->continuation->mutex;
- } else {
- this->mutex = new_ProxyMutex();
- }
-}
-
-UDPReadContinuation::UDPReadContinuation() : Continuation(nullptr) {}
-
-inline void
-UDPReadContinuation::free()
-{
- ink_assert(event != nullptr);
- completionUtil::destroy(event);
- event = nullptr;
- readbuf = nullptr;
- readlen = 0;
- fromaddrlen = nullptr;
- fd = -1;
- ifd = -1;
- period = 0;
- elapsed_time = 0;
- timeout_interval = 0;
- mutex = nullptr;
- udpReadContAllocator.free(this);
-}
-
-inline void
-UDPReadContinuation::init_token(Event *completionToken)
-{
- if (completionToken->continuation) {
- this->mutex = completionToken->continuation->mutex;
- } else {
- this->mutex = new_ProxyMutex();
- }
- event = completionToken;
-}
-
-inline void
-UDPReadContinuation::init_read(int rfd, IOBufferBlock *buf, int len, struct sockaddr *fromaddr_, socklen_t *fromaddrlen_)
-{
- ink_assert(rfd >= 0 && buf != nullptr && fromaddr_ != nullptr && fromaddrlen_ != nullptr);
- fd = rfd;
- readbuf = buf;
- readlen = len;
- fromaddr = ats_ip6_cast(fromaddr_);
- fromaddrlen = fromaddrlen_;
- SET_HANDLER(&UDPReadContinuation::readPollEvent);
- period = -HRTIME_MSECONDS(net_event_period);
- setupPollDescriptor();
- this_ethread()->schedule_every(this, period);
-}
-
-UDPReadContinuation::~UDPReadContinuation()
-{
- if (event != UNINITIALIZED_EVENT_PTR) {
- ink_assert(event != nullptr);
- completionUtil::destroy(event);
- event = nullptr;
- }
-}
-
-void
-UDPReadContinuation::cancel()
-{
- // I don't think this actually cancels it correctly right now.
- event->cancel();
-}
-
-void
-UDPReadContinuation::setupPollDescriptor()
-{
-#if TS_USE_EPOLL
- Pollfd *pfd;
- EThread *et = static_cast<EThread *>(this_thread());
- PollCont *pc = get_PollCont(et);
- if (pc->nextPollDescriptor == nullptr) {
- pc->nextPollDescriptor = new PollDescriptor();
- }
- pfd = pc->nextPollDescriptor->alloc();
- pfd->fd = fd;
- ifd = pfd - pc->nextPollDescriptor->pfd;
- ink_assert(pc->nextPollDescriptor->nfds > ifd);
- pfd->events = POLLIN;
- pfd->revents = 0;
-#endif
-}
-
-int
-UDPReadContinuation::readPollEvent(int event_, Event *e)
-{
- (void)event_;
- (void)e;
-
- // PollCont *pc = get_PollCont(e->ethread);
- Continuation *c;
-
- if (event->cancelled) {
- e->cancel();
- free();
- return EVENT_DONE;
- }
-
- // See if the request has timed out
- if (timeout_interval) {
- elapsed_time += -period;
- if (elapsed_time >= timeout_interval) {
- c = completionUtil::getContinuation(event);
- // TODO: Should we deal with the return code?
- c->handleEvent(NET_EVENT_DATAGRAM_READ_ERROR, event);
- e->cancel();
- free();
- return EVENT_DONE;
- }
- }
-
- c = completionUtil::getContinuation(event);
- // do read
- socklen_t tmp_fromlen = *fromaddrlen;
- UnixSocket sock{fd};
- int rlen = sock.recvfrom(readbuf->end(), readlen, 0, ats_ip_sa_cast(fromaddr), &tmp_fromlen);
-
- completionUtil::setThread(event, e->ethread);
- // call back user with their event
- if (rlen > 0) {
- // do callback if read is successful
- *fromaddrlen = tmp_fromlen;
- completionUtil::setInfo(event, fd, readbuf, rlen, errno);
- readbuf->fill(rlen);
- // TODO: Should we deal with the return code?
- c->handleEvent(NET_EVENT_DATAGRAM_READ_COMPLETE, event);
- e->cancel();
- free();
-
- return EVENT_DONE;
- } else if (rlen < 0 && rlen != -EAGAIN) {
- // signal error.
- *fromaddrlen = tmp_fromlen;
- completionUtil::setInfo(event, fd, readbuf, rlen, errno);
- c = completionUtil::getContinuation(event);
- // TODO: Should we deal with the return code?
- c->handleEvent(NET_EVENT_DATAGRAM_READ_ERROR, event);
- e->cancel();
- free();
-
- return EVENT_DONE;
- } else {
- completionUtil::setThread(event, nullptr);
- }
-
- if (event->cancelled) {
- e->cancel();
- free();
-
- return EVENT_DONE;
- }
- // reestablish poll
- setupPollDescriptor();
-
- return EVENT_CONT;
-}
-
-/* recvfrom:
- * Unix:
- * assert(buf->write_avail() >= len);
- * *actual_len = recvfrom(fd,addr,buf->end(),len)
- * if successful then
- * buf->fill(*actual_len);
- * return ACTION_RESULT_DONE
- * else if nothing read
- * *actual_len is 0
- * create "UDP read continuation" C with 'cont's lock
- * set user callback to 'cont'
- * return C's action.
- * else
- * return error;
- */
-Action *
-UDPNetProcessor::recvfrom_re(Continuation *cont, void *token, int fd, struct sockaddr *fromaddr, socklen_t *fromaddrlen,
- IOBufferBlock *buf, int len, bool useReadCont, int timeout)
-{
- (void)useReadCont;
- ink_assert(buf->write_avail() >= len);
- int actual;
- Event *event = completionUtil::create();
-
- completionUtil::setContinuation(event, cont);
- completionUtil::setHandle(event, token);
- UnixSocket sock{fd};
- actual = sock.recvfrom(buf->end(), len, 0, fromaddr, fromaddrlen);
-
- if (actual > 0) {
- completionUtil::setThread(event, this_ethread());
- completionUtil::setInfo(event, sock.get_fd(), make_ptr(buf), actual, errno);
- buf->fill(actual);
- cont->handleEvent(NET_EVENT_DATAGRAM_READ_COMPLETE, event);
- completionUtil::destroy(event);
- return ACTION_RESULT_DONE;
- } else if (actual == 0 || actual == -EAGAIN) {
- UDPReadContinuation *c = udpReadContAllocator.alloc();
- c->init_token(event);
- c->init_read(sock.get_fd(), buf, len, fromaddr, fromaddrlen);
- if (timeout) {
- c->set_timer(timeout);
- }
- return event;
- } else {
- completionUtil::setThread(event, this_ethread());
- completionUtil::setInfo(event, sock.get_fd(), make_ptr(buf), actual, errno);
- cont->handleEvent(NET_EVENT_DATAGRAM_READ_ERROR, event);
- completionUtil::destroy(event);
- return ACTION_IO_ERROR;
- }
-}
-
-/* sendmsg:
- * Unix:
- * *actual_len = sendmsg(fd,msg,default-flags);
- * if successful,
- * return ACTION_RESULT_DONE
- * else
- * return error
- */
-Action *
-UDPNetProcessor::sendmsg_re(Continuation *cont, void *token, int fd, struct msghdr *msg)
-{
- int actual;
- Event *event = completionUtil::create();
-
- completionUtil::setContinuation(event, cont);
- completionUtil::setHandle(event, token);
-
- UnixSocket sock{fd};
- actual = sock.sendmsg(msg, 0);
- if (actual >= 0) {
- completionUtil::setThread(event, this_ethread());
- completionUtil::setInfo(event, sock.get_fd(), msg, actual, errno);
- cont->handleEvent(NET_EVENT_DATAGRAM_WRITE_COMPLETE, event);
- completionUtil::destroy(event);
- return ACTION_RESULT_DONE;
- } else {
- completionUtil::setThread(event, this_ethread());
- completionUtil::setInfo(event, sock.get_fd(), msg, actual, errno);
- cont->handleEvent(NET_EVENT_DATAGRAM_WRITE_ERROR, event);
- completionUtil::destroy(event);
- return ACTION_IO_ERROR;
- }
-}
-
-/* sendto:
- * If this were implemented, it might be implemented like this:
- * Unix:
- * call sendto(fd,addr,buf->reader()->start(),len);
- * if successful,
- * buf->consume(len);
- * return ACTION_RESULT_DONE
- * else
- * return error
- *
- */
-Action *
-UDPNetProcessor::sendto_re(Continuation *cont, void *token, int fd, struct sockaddr const *toaddr, int toaddrlen,
- IOBufferBlock *buf, int len)
-{
- (void)token;
- ink_assert(buf->read_avail() >= len);
- UnixSocket sock{fd};
- int nbytes_sent = sock.sendto(buf->start(), len, 0, toaddr, toaddrlen);
-
- if (nbytes_sent >= 0) {
- ink_assert(nbytes_sent == len);
- buf->consume(nbytes_sent);
- cont->handleEvent(NET_EVENT_DATAGRAM_WRITE_COMPLETE, reinterpret_cast<void *>(-1));
- return ACTION_RESULT_DONE;
- } else {
- cont->handleEvent(NET_EVENT_DATAGRAM_WRITE_ERROR, reinterpret_cast<void *>(nbytes_sent));
- return ACTION_IO_ERROR;
- }
-}
-
bool
UDPNetProcessor::CreateUDPSocket(int *resfd, sockaddr const *remote_addr, Action **status, NetVCOptions const &opt)
{