1 /*
2     SPDX-FileCopyrightText: 2010 Joris Guisson <joris.guisson@gmail.com>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #ifndef UTP_OUTPUTQUEUE_H
8 #define UTP_OUTPUTQUEUE_H
9 
10 #include "connection.h"
11 #include "packetbuffer.h"
12 #include <QList>
13 #include <deque>
14 #include <net/serversocket.h>
15 
16 namespace utp
17 {
18 /**
19  * Manages the send queue of all UTP server sockets
20  */
21 class OutputQueue
22 {
23 public:
24     OutputQueue();
25     virtual ~OutputQueue();
26 
27     /**
28      * Add an entry to the queue.
29      * @param data The packet
30      * @param conn The connection this packet belongs to
31      * @return The number of queued packets
32      */
33     int add(const PacketBuffer &packet, Connection::WPtr conn);
34 
35     /**
36      * Attempt to send the queue on a socket
37      * @param sock The socket
38      */
39     void send(net::ServerSocket *sock);
40 
41 private:
42     struct Entry {
43         PacketBuffer data;
44         Connection::WPtr conn;
45 
EntryEntry46         Entry(const PacketBuffer &data, Connection::WPtr conn)
47             : data(data)
48             , conn(conn)
49         {
50         }
51     };
52 
53 #ifndef DO_NOT_USE_DEQUE
54     std::deque<Entry> queue;
55 #else
56     QList<Entry> queue;
57 #endif
58     QMutex mutex;
59 };
60 
61 }
62 
63 #endif // UTP_OUTPUTQUEUE_H
64