1 #ifndef BLANK_SERVER_CHUNKTRANSMITTER_HPP_
2 #define BLANK_SERVER_CHUNKTRANSMITTER_HPP_
15 class ClientConnection;
17 class ChunkTransmitter {
20 explicit ChunkTransmitter(ClientConnection &);
23 /// Returns true if not transmitting or waiting on acks, so
24 /// the next chunk may be queued without schmutzing up anything.
25 bool Idle() const noexcept;
27 /// Returns true if a transmission is still going on,
28 /// meaning there's at least one packet that needs to
30 bool Transmitting() const noexcept;
31 /// Send the next packet of the current chunk (if any).
34 /// Returns true if there's one or more packets which
35 /// still have to be ack'd by the remote.
36 bool Waiting() const noexcept;
37 /// Mark packet with given sequence number as ack'd.
38 /// If all packets for the current chunk have been ack'd
39 /// the transmission is considered complete.
40 void Ack(std::uint16_t);
41 /// Mark packet with given sequence number as lost.
42 /// Its part of the chunk data should be resent.
43 void Nack(std::uint16_t);
45 /// Cancel the current transmission.
47 /// Start transmitting given chunk.
48 /// If there's a chunk already in transmission it will be
54 void SendData(std::size_t);
58 ClientConnection &conn;
60 std::size_t buffer_size;
61 std::unique_ptr<std::uint8_t[]> buffer;
62 std::size_t buffer_len;
63 std::size_t packet_len;
65 std::size_t num_packets;
67 std::vector<int> data_packets;
69 std::uint32_t trans_id;