This is an automated email from the ASF dual-hosted git repository. scw00 pushed a commit to branch quic-latest in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit ba5ff998aef294820ea59c1d4363c5d9a423a56f Author: scw00 <[email protected]> AuthorDate: Tue Feb 6 14:01:38 2018 +0800 add QUICPollEvent to packet UDPPacket and QVC --- iocore/net/I_UDPPacket.h | 6 ----- iocore/net/P_QUICNet.h | 28 ++++++++++++++++++---- iocore/net/QUICNet.cc | 52 ++++++++++++++++++++++++----------------- iocore/net/QUICPacketHandler.cc | 12 ++++++---- 4 files changed, 62 insertions(+), 36 deletions(-) diff --git a/iocore/net/I_UDPPacket.h b/iocore/net/I_UDPPacket.h index fd047e5..df899ff 100644 --- a/iocore/net/I_UDPPacket.h +++ b/iocore/net/I_UDPPacket.h @@ -62,12 +62,6 @@ public: IpEndpoint to; // what address to send to int from_size; - typedef union udppacket_data { - void *ptr; - uint32_t u32; - uint64_t u64; - } udppacket_data_t; - udppacket_data_t data; LINK(UDPPacket, link); }; diff --git a/iocore/net/P_QUICNet.h b/iocore/net/P_QUICNet.h index 7231207..297ddbe 100644 --- a/iocore/net/P_QUICNet.h +++ b/iocore/net/P_QUICNet.h @@ -29,11 +29,28 @@ #include "ts/ink_platform.h" #include "P_Net.h" + class NetHandler; typedef int (NetHandler::*NetContHandler)(int, void *); void initialize_thread_for_quic_net(EThread *thread); +struct QUICPollEvent { + typedef union data_t { + void *ptr; + uint32_t u32; + uint64_t u64; + } data_t; + + void free(); + + data_t data; + UDPPacketInternal *packet; + + SLINK(QUICPollEvent, alink); + LINK(QUICPollEvent, link); +}; + struct QUICPollCont : public Continuation { NetHandler *net_handler; PollDescriptor *pollDescriptor; @@ -45,16 +62,16 @@ struct QUICPollCont : public Continuation { public: // Atomic Queue to save incoming packets - ASLL(UDPPacketInternal, alink) inQueue; + ASLL(QUICPollEvent, alink) inQueue; // Internal Queue to save Long Header Packet - Que(UDPPacket, link) longInQueue; + Que(UDPPacketInternal, link) longInQueue; // Internal Queue to save Short Header Packet - Que(UDPPacket, link) shortInQueue; + Que(UDPPacketInternal, link) shortInQueue; private: - void _process_short_header_packet(UDPPacketInternal *p, NetHandler *nh); - void _process_long_header_packet(UDPPacketInternal *p, NetHandler *nh); + void _process_short_header_packet(QUICPollEvent *e, NetHandler *nh); + void _process_long_header_packet(QUICPollEvent *e, NetHandler *nh); }; static inline QUICPollCont * @@ -63,4 +80,5 @@ get_QUICPollCont(EThread *t) return (QUICPollCont *)ETHREAD_GET_PTR(t, quic_NetProcessor.quicPollCont_offset); } +extern ClassAllocator<QUICPollEvent> quicPollEventAllocator; #endif diff --git a/iocore/net/QUICNet.cc b/iocore/net/QUICNet.cc index 33763b8..68c3bee 100644 --- a/iocore/net/QUICNet.cc +++ b/iocore/net/QUICNet.cc @@ -23,6 +23,14 @@ #include "P_Net.h" +ClassAllocator<QUICPollEvent> quicPollEventAllocator("quicPollEvent"); + +void +QUICPollEvent::free() +{ + quicPollEventAllocator.free(this); +} + QUICPollCont::QUICPollCont(Ptr<ProxyMutex> &m) : Continuation(m.get()), net_handler(nullptr) { SET_HANDLER(&QUICPollCont::pollEvent); @@ -38,15 +46,16 @@ QUICPollCont::~QUICPollCont() } void -QUICPollCont::_process_long_header_packet(UDPPacketInternal *p, NetHandler *nh) +QUICPollCont::_process_long_header_packet(QUICPollEvent *e, NetHandler *nh) { - QUICNetVConnection *vc; - QUICPacketType ptype; uint8_t *buf; - + QUICPacketType ptype; + UDPPacketInternal *p = e->packet; // FIXME: VC is nullptr ? - vc = static_cast<QUICNetVConnection *>(p->data.ptr); - buf = (uint8_t *)p->getIOBlockChain()->buf(); + QUICNetVConnection *vc = static_cast<QUICNetVConnection *>(e->data.ptr); + buf = (uint8_t *)p->getIOBlockChain()->buf(); + + e->free(); if (!QUICTypeUtil::has_connection_id(reinterpret_cast<const uint8_t *>(buf))) { // TODO: Some packets may not have connection id p->free(); @@ -85,13 +94,14 @@ QUICPollCont::_process_long_header_packet(UDPPacketInternal *p, NetHandler *nh) } void -QUICPollCont::_process_short_header_packet(UDPPacketInternal *p, NetHandler *nh) +QUICPollCont::_process_short_header_packet(QUICPollEvent *e, NetHandler *nh) { - QUICNetVConnection *vc; uint8_t *buf; + UDPPacketInternal *p = e->packet; + QUICNetVConnection *vc = static_cast<QUICNetVConnection *>(e->data.ptr); + buf = (uint8_t *)p->getIOBlockChain()->buf(); - vc = static_cast<QUICNetVConnection *>(p->data.ptr); - buf = (uint8_t *)p->getIOBlockChain()->buf(); + e->free(); if (!QUICTypeUtil::has_connection_id(reinterpret_cast<const uint8_t *>(buf))) { // TODO: Some packets may not have connection id p->free(); @@ -124,22 +134,22 @@ QUICPollCont::pollEvent(int, Event *) { ink_assert(this->mutex->thread_holding == this_thread()); uint8_t *buf; - UDPPacketInternal *p = nullptr; - NetHandler *nh = get_NetHandler(this->mutex->thread_holding); + QUICPollEvent *e; + NetHandler *nh = get_NetHandler(this->mutex->thread_holding); // Process the ASLL - SList(UDPPacketInternal, alink) aq(inQueue.popall()); - Queue<UDPPacketInternal> result; - while ((p = aq.pop())) { - result.push(p); + SList(QUICPollEvent, link) aq(inQueue.popall()); + Queue<QUICPollEvent> result; + while ((e = aq.pop())) { + result.push(e); } - while ((p = result.pop())) { - buf = (uint8_t *)p->getIOBlockChain()->buf(); + while ((e = result.pop())) { + buf = (uint8_t *)e->packet->getIOBlockChain()->buf(); if (QUICTypeUtil::has_long_header(buf)) { // Long Header Packet with Connection ID, has a valid type value. - this->_process_long_header_packet(p, nh); + this->_process_long_header_packet(e, nh); } else { // Short Header Packet with Connection ID, has a valid type value. - this->_process_short_header_packet(p, nh); + this->_process_short_header_packet(e, nh); } } @@ -154,5 +164,5 @@ initialize_thread_for_quic_net(EThread *thread) new ((ink_dummy_for_new *)quicpc) QUICPollCont(thread->mutex, nh); - thread->schedule_every(quicpc, -UDP_PERIOD); + thread->schedule_every(quicpc, -HRTIME_MSECONDS(UDP_PERIOD)); } diff --git a/iocore/net/QUICPacketHandler.cc b/iocore/net/QUICPacketHandler.cc index a09c394..5eb9966 100644 --- a/iocore/net/QUICPacketHandler.cc +++ b/iocore/net/QUICPacketHandler.cc @@ -124,7 +124,8 @@ QUICPacketHandlerIn::init_accept(EThread *t = nullptr) void QUICPacketHandlerIn::_recv_packet(int event, UDPPacket *udp_packet) { - EThread *eth; + EThread *eth = nullptr; + QUICPollEvent *qe = nullptr; QUICNetVConnection *vc = nullptr; IOBufferBlock *block = udp_packet->getIOBlockChain(); @@ -185,10 +186,13 @@ QUICPacketHandlerIn::_recv_packet(int event, UDPPacket *udp_packet) eth = vc->thread; } - // Push the packet into QUICPollCont - udp_packet->data.ptr = vc; + qe = quicPollEventAllocator.alloc(); + + qe->data.ptr = vc; // should we use dynamic_cast ?? - get_QUICPollCont(eth)->inQueue.push(static_cast<UDPPacketInternal *>(udp_packet)); + qe->packet = static_cast<UDPPacketInternal *>(udp_packet); + // Push the packet into QUICPollCont + get_QUICPollCont(eth)->inQueue.push(qe); } // TODO: Should be called via eventProcessor? -- To stop receiving notification emails like this one, please contact [email protected].
