make server network async, implement connecting

This commit is contained in:
Lion Kortlepel
2024-03-10 14:40:54 +01:00
parent 4e304f798e
commit 5d56d529bc
3 changed files with 108 additions and 68 deletions

View File

@@ -19,10 +19,12 @@ public:
void run();
private:
void start_read();
/// Reads a single packet from the TCP stream. Blocks all other reads (not writes).
bmp::Packet tcp_read();
void tcp_read(std::function<void(bmp::Packet&&)> handler);
/// Writes the packet to the TCP stream. Blocks all other writes.
void tcp_write(bmp::Packet& packet);
void tcp_write(bmp::Packet&& packet, std::function<void(boost::system::error_code)> handler = nullptr);
/// Reads a packet from the given UDP socket, returning the client's endpoint as an out-argument.
bmp::Packet udp_read(ip::udp::endpoint& out_ep);
@@ -40,6 +42,10 @@ private:
ip::tcp::socket m_tcp_socket { m_io };
ip::udp::socket m_udp_socket { m_io };
// these two tmp fields are used for temporary reading into by read, don't use anywhere else please
bmp::Packet m_tmp_packet {};
std::vector<uint8_t> m_tmp_header_buffer {};
bmp::State m_state {};
uint64_t m_udp_magic {};