Просмотр исходного кода

Doxygen documented the Address class.

Also made a few minor fixes:
- Address IP/port are no longer unitialized when using the empty constructor(normally this is no problem, but stuff like this can come to haunt you)
- Address data is now protected, to ensure that no polycode user accidentally modifies the variables directly. Friend classing is used to give Socket access to internal data.
cib 13 лет назад
Родитель
Сommit
ad93e133ff

+ 1 - 1
Core/Contents/Include/PolyPeer.h

@@ -108,7 +108,7 @@ namespace Polycode {
 			/**
 			* Send raw binary data to the target address.
 			*
-			* @param target The network address to send the data to.
+			* @param target The network Address to send the data to.
 			* @param data The binary data to send as a C byte array. Length must be supplied by size parameter.
 			* @param size The size in bytes of the sent binary data.
 			* @param type A number representing the packet type, used to define the purpose of the packet.

+ 61 - 3
Core/Contents/Include/PolySocket.h

@@ -59,29 +59,87 @@ THE SOFTWARE.
 #endif
 
 namespace Polycode {
-		
+
+	/**
+	* A typical network address, defined by IP and port.
+	*/
 	class _PolyExport Address  {
 		public:
+
+		/**
+		* Constructor.
+		* @param ipAsString An IP address represented as string,
+		*                   for example "197.0.0.1"
+		* @param port The UDP/TCP port of the address, given in
+		*             host byte order.
+		*/
 		Address(String ipAsString, unsigned int port);
+
+		/**
+		* Constructor.
+		* @param ip An IP address given as integer in host byte
+		*           order.
+		* @param port The UDP/TCP port of the address, given in
+		*             host byte order.
+		*/
 		Address(unsigned int ip, unsigned int port);
+
+		/**
+		* Constructor, leaving the address uninitalized.
+		*
+		* Address IP and port will default to 0.
+		*/
 		Address();
 		~Address();
 		
+		/**
+		* Copy the address IP and port from add2 into this.
+		* @param add2 The address to copy into this.
+		*/
 		inline void operator = (const Address &add2) {
 			setAddress(add2.uintAddress, add2.port);
 		}
 		
+		/**
+		* @return 1 if the address IP and port match, 0 otherwise.
+		*/
 		inline bool operator == ( const Address& add2)  {
 			return (uintAddress == add2.uintAddress && port == add2.port);
 		}
 			
-		
+		/**
+		* Update the address IP and port.
+		* @param ipAsString An IP address represented as string,
+		*                   for example "197.0.0.1"
+		* @param port The UDP/TCP port of the address, given in
+		*             host byte order.
+		*/
 		void setAddress(String ipAsString, unsigned int port);
+
+		/**
+		* Update the address IP and port.
+		* @param ip An IP address given as integer in host byte
+		*           order.
+		* @param port The UDP/TCP port of the address, given in
+		*             host byte order.
+		*/
 		void setAddress(unsigned int ip, unsigned int port);
 		
+		// TODO: A way to get the IP/port without exposing internal members.
+		//       The problem here is that the IP internally is converted to
+		//       network byte order, but the API seems to work with host byte
+		//       order, so I'm unsure in which byte order the IP/port should
+		//       be returned.
+
+		protected:
 		unsigned int uintAddress;
 		unsigned int port;
-		sockaddr_in sockAddress;		
+
+		sockaddr_in sockAddress;
+
+		// This class already uses socket API structs internally,
+		// so it's no far stretch to make it tied to the Socket class.
+		friend class Socket;
 	};
 	
 	

+ 1 - 2
Core/Contents/Source/PolySocket.cpp

@@ -38,8 +38,7 @@ Address::Address(unsigned int ip, unsigned int port) {
 	setAddress(ip, port);
 }
 
-Address::Address() {
-	
+Address::Address()  : uintAddress(0), port(0) {
 }
 
 void Address::setAddress(unsigned int ip, unsigned int port) {