32 #include "../main.h" |
32 #include "../main.h" |
33 #include "ipaddress.h" |
33 #include "ipaddress.h" |
34 #include "bytestream.h" |
34 #include "bytestream.h" |
35 BEGIN_ZFC_NAMESPACE |
35 BEGIN_ZFC_NAMESPACE |
36 |
36 |
37 enum { MAX_DATAGRAM_LENGTH = 5120 }; |
37 namespace net |
|
38 { |
|
39 constexpr int MAX_DATAGRAM_LENGTH = 5120; |
|
40 struct Datagram; |
|
41 class UDPSocket; |
|
42 } |
38 |
43 |
39 struct Datagram |
44 struct net::Datagram |
40 { |
45 { |
41 ByteArray message; |
46 std::vector<unsigned char> message; |
42 IPAddress address; |
47 net::ip_address address; |
43 }; |
48 }; |
44 |
49 |
45 // ------------------------------------------------------------------------------------------------- |
50 // ------------------------------------------------------------------------------------------------- |
46 // |
51 // |
47 class UDPSocket |
52 class net::UDPSocket |
48 { |
53 { |
49 public: |
54 public: |
50 UDPSocket(); |
55 UDPSocket(); |
51 virtual ~UDPSocket(); |
56 virtual ~UDPSocket(); |
52 |
57 [[nodiscard]] bool bind(port_t port, std::ostream &errors); |
53 bool bind (unsigned short port); |
58 [[nodiscard]] bool read(Datagram& datagram, std::ostream& errors); |
54 bool read (Datagram& datagram); |
59 [[nodiscard]] bool send(const ip_address& address, const std::vector<unsigned char>& data, std::ostream &errors); |
55 bool send (const IPAddress& address, const ByteArray& data); |
60 [[nodiscard]] bool set_blocking(bool a, std::ostream &errors); |
56 bool set_blocking (bool a); |
61 const int file_descriptor; |
57 const String& error_string() const { return m_error; } |
|
58 int file_descriptor() const { return m_socket; } |
|
59 |
|
60 private: |
|
61 static char HuffmanBuffer[131072]; |
|
62 |
|
63 IPAddress m_addr; |
|
64 String m_error; |
|
65 int m_socket; |
|
66 }; |
62 }; |
67 |
63 |
68 END_ZFC_NAMESPACE |
64 END_ZFC_NAMESPACE |