Daniele Bartolini 10 yıl önce
ebeveyn
işleme
80423de912

+ 6 - 6
src/core/network/net_address.h → src/core/network/ip_address.h

@@ -9,19 +9,21 @@
 
 namespace crown
 {
-/// Netwotk address helper
+/// IP address.
 ///
 /// @ingroup Network
-struct NetAddress
+struct IPAddress
 {
+	u32 _addr;
+
 	/// Initializes the address to 127.0.0.1
-	NetAddress()
+	IPAddress()
 		: _addr(0)
 	{
 		set(127, 0, 0, 1);
 	}
 
-	NetAddress(u8 a, u8 b, u8 c, u8 d)
+	IPAddress(u8 a, u8 b, u8 c, u8 d)
 		: _addr(0)
 	{
 		set(a, b, c, d);
@@ -41,8 +43,6 @@ struct NetAddress
 		_addr |= u32(c) << 8;
 		_addr |= u32(d) << 0;
 	}
-
-	u32 _addr;
 };
 
 } // namespace crown

+ 14 - 0
src/core/network/network_types.h

@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2012-2016 Daniele Bartolini and individual contributors.
+ * License: https://github.com/taylor001/crown/blob/master/LICENSE
+ */
+
+#pragma once
+
+/// @defgroup Network Network
+namespace crown
+{
+struct Socket;
+struct IPAddress;
+
+} // namespace crown

+ 14 - 17
src/core/network/socket.h

@@ -5,19 +5,18 @@
 
 #pragma once
 
-#include "config.h"
-#include "types.h"
 #include "error.h"
+#include "ip_address.h"
 #include "macros.h"
-#include "net_address.h"
+#include "platform.h"
+#include "types.h"
 
 #if CROWN_PLATFORM_POSIX
-	#include <sys/socket.h>
-	#include <sys/types.h>
-	#include <netinet/in.h>
-	#include <fcntl.h>
-	#include <unistd.h>
 	#include <errno.h>
+	#include <fcntl.h>      // fcntl
+	#include <netinet/in.h> // htons, htonl, ...
+	#include <sys/socket.h>
+	#include <unistd.h>     // close
 #elif CROWN_PLATFORM_WINDOWS
 	#include <winsock2.h>
 	#include "win_headers.h"
@@ -53,6 +52,12 @@ struct AcceptResult
 /// @ingroup Network
 struct TCPSocket
 {
+#if CROWN_PLATFORM_POSIX
+	int _socket;
+#elif CROWN_PLATFORM_WINDOWS
+	SOCKET _socket;
+#endif
+
 	TCPSocket()
 #if CROWN_PLATFORM_POSIX
 		: _socket(0)
@@ -73,7 +78,7 @@ struct TCPSocket
 #endif
 	}
 
-	ConnectResult connect(const NetAddress& ip, u16 port)
+	ConnectResult connect(const IPAddress& ip, u16 port)
 	{
 		close();
 		open();
@@ -441,14 +446,6 @@ struct TCPSocket
 #endif
 		CE_UNUSED(err);
 	}
-
-private:
-
-#if CROWN_PLATFORM_POSIX
-	int _socket;
-#elif CROWN_PLATFORM_WINDOWS
-	SOCKET _socket;
-#endif
 };
 
 } // namespace crown