X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fnet%2FChunkTransmitter.hpp;fp=src%2Fnet%2FChunkTransmitter.hpp;h=44f6bd87106a009a630bb6af990d90b56ab0b0a0;hb=ae5a7e7d8517fac406a88e9bf98fd3d5bb1728b9;hp=0000000000000000000000000000000000000000;hpb=8e7e042296946ba2aed73b77ab02feb267eb17d4;p=blank.git diff --git a/src/net/ChunkTransmitter.hpp b/src/net/ChunkTransmitter.hpp new file mode 100644 index 0000000..44f6bd8 --- /dev/null +++ b/src/net/ChunkTransmitter.hpp @@ -0,0 +1,73 @@ +#ifndef BLANK_NET_CHUNKTRANSMITTER_HPP_ +#define BLANK_NET_CHUNKTRANSMITTER_HPP_ + +#include +#include +#include + + +namespace blank { + +class Chunk; +class ClientConnection; + +class ChunkTransmitter { + +public: + explicit ChunkTransmitter(ClientConnection &); + ~ChunkTransmitter(); + + /// Returns true if not transmitting or waiting on acks, so + /// the next chunk may be queued without schmutzing up anything. + bool Idle() const noexcept; + + /// Returns true if a transmission is still going on, + /// meaning there's at least one packet that needs to + /// be sent. + bool Transmitting() const noexcept; + /// Send the next packet of the current chunk (if any). + void Transmit(); + + /// Returns true if there's one or more packets which + /// still have to be ack'd by the remote. + bool Waiting() const noexcept; + /// Mark packet with given sequence number as ack'd. + /// If all packets for the current chunk have been ack'd + /// the transmission is considered complete. + void Ack(std::uint16_t); + /// Mark packet with given sequence number as lost. + /// Its part of the chunk data should be resent. + void Nack(std::uint16_t); + + /// Cancel the current transmission. + void Abort(); + /// Start transmitting given chunk. + /// If there's a chunk already in transmission it will be + /// cancelled. + void Send(Chunk &); + +private: + void SendBegin(); + void SendData(std::size_t); + void Release(); + +private: + ClientConnection &conn; + Chunk *current; + std::size_t buffer_size; + std::unique_ptr buffer; + std::size_t buffer_len; + std::size_t packet_len; + std::size_t cursor; + std::size_t num_packets; + int begin_packet; + std::vector data_packets; + int confirm_wait; + std::uint32_t trans_id; + bool compressed; + +}; + +} + +#endif