sources/network/udpsocket.h

changeset 189
248d0b85cbda
parent 186
9330b93d9946
child 190
90bf9049e5eb
--- a/sources/network/udpsocket.h	Wed Jan 27 19:01:37 2021 +0200
+++ b/sources/network/udpsocket.h	Wed Jan 27 19:27:23 2021 +0200
@@ -34,9 +34,14 @@
 #include "bytestream.h"
 BEGIN_ZFC_NAMESPACE
 
-enum { MAX_DATAGRAM_LENGTH = 5120 };
+namespace net
+{
+	constexpr int MAX_DATAGRAM_LENGTH = 5120;
+	struct Datagram;
+	class UDPSocket;
+}
 
-struct Datagram
+struct net::Datagram
 {
 	ByteArray message;
 	net::ip_address address;
@@ -44,24 +49,16 @@
 
 // -------------------------------------------------------------------------------------------------
 //
-class UDPSocket
+class net::UDPSocket
 {
 public:
 	UDPSocket();
 	virtual ~UDPSocket();
-
-	bool bind (unsigned short port);
-	bool read (Datagram& datagram);
-	bool send (const net::ip_address& address, const ByteArray& data);
-	bool set_blocking (bool a);
-	const std::string& error_string() const { return m_error; }
-	int file_descriptor() const { return m_socket; }
-
-private:
-	static char HuffmanBuffer[131072];
-
-	std::string m_error;
-	int m_socket;
+	[[nodiscard]] bool bind(port_t port, std::ostream &errors);
+	[[nodiscard]] bool read(Datagram& datagram, std::ostream& errors);
+	[[nodiscard]] bool send(const ip_address& address, const ByteArray& data, std::ostream &errors);
+	[[nodiscard]] bool set_blocking(bool a, std::ostream &errors);
+	const int file_descriptor;
 };
 
 END_ZFC_NAMESPACE
\ No newline at end of file

mercurial