Overte C++ Documentation
ControlPacket.h
1 //
2 // ControlPacket.h
3 // libraries/networking/src/udt
4 //
5 // Created by Stephen Birarda on 2015-07-24.
6 // Copyright 2015 High Fidelity, Inc.
7 // Copyright 2021 Vircadia contributors.
8 //
9 // Distributed under the Apache License, Version 2.0.
10 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
11 //
12 
13 #pragma once
14 
15 #ifndef hifi_ControlPacket_h
16 #define hifi_ControlPacket_h
17 
18 #include <vector>
19 
20 #include "BasePacket.h"
21 #include "Packet.h"
22 
23 namespace udt {
24 
25 class ControlPacket : public BasePacket {
26  Q_OBJECT
27 public:
28  using ControlBitAndType = uint32_t;
29 
30  enum Type : uint16_t {
31  ACK,
32  Handshake,
33  HandshakeACK,
34  HandshakeRequest
35  };
36 
37  static std::unique_ptr<ControlPacket> create(Type type, qint64 size = -1);
38  static std::unique_ptr<ControlPacket> fromReceivedPacket(std::unique_ptr<char[]> data, qint64 size,
39  const SockAddr& senderSockAddr);
40  // Current level's header size
41  static int localHeaderSize();
42  // Cumulated size of all the headers
43  static int totalHeaderSize();
44  // The maximum payload size this packet can use to fit in MTU
45  static int maxPayloadSize();
46 
47  Type getType() const { return _type; }
48  void setType(Type type);
49 
50 private:
51  Q_DISABLE_COPY(ControlPacket)
52  ControlPacket(Type type, qint64 size = -1);
53  ControlPacket(std::unique_ptr<char[]> data, qint64 size, const SockAddr& senderSockAddr);
54  ControlPacket(ControlPacket&& other);
55 
56  ControlPacket& operator=(ControlPacket&& other);
57 
58  // Header read/write
59  void readType();
60  void writeType();
61 
62  Type _type;
63 };
64 
65 } // namespace udt
66 
67 
68 #endif // hifi_ControlPacket_h