File indexing completed on 2025-01-05 04:37:33

0001 /*
0002     SPDX-FileCopyrightText: 2010 Joris Guisson <joris.guisson@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef UTP_OUTPUTQUEUE_H
0008 #define UTP_OUTPUTQUEUE_H
0009 
0010 #include "connection.h"
0011 #include "packetbuffer.h"
0012 
0013 #include <QList>
0014 #include <QRecursiveMutex>
0015 
0016 #include <deque>
0017 #include <net/serversocket.h>
0018 
0019 namespace utp
0020 {
0021 /**
0022  * Manages the send queue of all UTP server sockets
0023  */
0024 class OutputQueue
0025 {
0026 public:
0027     OutputQueue();
0028     virtual ~OutputQueue();
0029 
0030     /**
0031      * Add an entry to the queue.
0032      * @param data The packet
0033      * @param conn The connection this packet belongs to
0034      * @return The number of queued packets
0035      */
0036     int add(const PacketBuffer &packet, Connection::WPtr conn);
0037 
0038     /**
0039      * Attempt to send the queue on a socket
0040      * @param sock The socket
0041      */
0042     void send(net::ServerSocket *sock);
0043 
0044 private:
0045     struct Entry {
0046         PacketBuffer data;
0047         Connection::WPtr conn;
0048 
0049         Entry(const PacketBuffer &data, Connection::WPtr conn)
0050             : data(data)
0051             , conn(conn)
0052         {
0053         }
0054     };
0055 
0056 #ifndef DO_NOT_USE_DEQUE
0057     std::deque<Entry> queue;
0058 #else
0059     QList<Entry> queue;
0060 #endif
0061     QRecursiveMutex mutex;
0062 };
0063 
0064 }
0065 
0066 #endif // UTP_OUTPUTQUEUE_H