sources/network/udpsocket.h

branch
protocol5
changeset 195
be953e1621d9
parent 191
2e6cbacafdc7
--- a/sources/network/udpsocket.h	Wed Jan 27 12:41:50 2021 +0200
+++ b/sources/network/udpsocket.h	Wed Jan 27 19:48:41 2021 +0200
@@ -1,5 +1,5 @@
 /*
-	Copyright 2014 - 2016 Teemu Piippo
+	Copyright 2014 - 2021 Teemu Piippo
 	All rights reserved.
 
 	Redistribution and use in source and binary forms, with or without
@@ -34,35 +34,31 @@
 #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;
-	IPAddress address;
+	std::vector<unsigned char> message;
+	net::ip_address address;
 };
 
 // -------------------------------------------------------------------------------------------------
 //
-class UDPSocket
+class net::UDPSocket
 {
 public:
 	UDPSocket();
 	virtual ~UDPSocket();
-
-	bool bind (unsigned short port);
-	bool read (Datagram& datagram);
-	bool send (const IPAddress& address, const ByteArray& data);
-	bool set_blocking (bool a);
-	const String& error_string() const { return m_error; }
-	int file_descriptor() const { return m_socket; }
-
-private:
-	static char HuffmanBuffer[131072];
-
-	IPAddress m_addr;
-	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 std::vector<unsigned char>& 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