From 1571338fdef7adad9d9f5b4a90f08aac0ebe87db Mon Sep 17 00:00:00 2001
From: Edouard DUPIN <yui.heero@gmail.com>
Date: Wed, 28 Sep 2016 21:52:50 +0200
Subject: [PATCH] [DEV] start port of windows socket

---
 enet/Tcp.cpp       |  7 +++++--
 enet/Tcp.h         |  6 +++++-
 enet/TcpClient.cpp |  2 +-
 enet/TcpServer.cpp | 12 +++++++++---
 enet/TcpServer.h   |  9 ++++++---
 lutin_enet.py      |  6 +-----
 6 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/enet/Tcp.cpp b/enet/Tcp.cpp
index 93df7f8..7515e18 100644
--- a/enet/Tcp.cpp
+++ b/enet/Tcp.cpp
@@ -7,14 +7,17 @@
 #include <enet/debug.h>
 #include <enet/Tcp.h>
 #include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
 #include <netdb.h>
 #include <errno.h>
 #include <unistd.h>
 #include <string.h>
 #include <etk/stdTools.h>
+
+#ifndef __TARGET_OS__Windows
+#include <sys/socket.h>
+#include <netinet/in.h>
 #include <netinet/tcp.h>
+#endif
 
 bool enet::Tcp::setTCPNoDelay(bool _enabled) {
 	if (m_socketId >= 0) {
diff --git a/enet/Tcp.h b/enet/Tcp.h
index d79cfe5..2074c05 100644
--- a/enet/Tcp.h
+++ b/enet/Tcp.h
@@ -6,14 +6,18 @@
 #pragma once
 
 #include <etk/types.h>
-#include <poll.h>
 #include <mutex>
+#ifndef __TARGET_OS__Windows
+#include <poll.h>
+#endif
 
 namespace enet {
 	class Tcp {
 		private:
 			int32_t m_socketId; //!< socket linux interface generic
+			#ifndef __TARGET_OS__Windows
 			struct pollfd m_fds[1];
+			#endif
 			std::mutex m_mutex;
 		public:
 			Tcp();
diff --git a/enet/TcpClient.cpp b/enet/TcpClient.cpp
index 8cc554b..533031e 100644
--- a/enet/TcpClient.cpp
+++ b/enet/TcpClient.cpp
@@ -8,13 +8,13 @@
 #include <enet/Tcp.h>
 #include <enet/TcpClient.h>
 #include <sys/types.h>
-#include <sys/socket.h>
 #include <netinet/in.h>
 #include <netdb.h>
 #include <errno.h>
 #include <unistd.h>
 #include <string.h>
 #include <etk/stdTools.h>
+
 #include <sys/socket.h>
 
 enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8_t _ip4, uint16_t _port, uint32_t _numberRetry) {
diff --git a/enet/TcpServer.cpp b/enet/TcpServer.cpp
index 7360c4c..945712f 100644
--- a/enet/TcpServer.cpp
+++ b/enet/TcpServer.cpp
@@ -8,14 +8,20 @@
 #include <enet/Tcp.h>
 #include <enet/TcpServer.h>
 #include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
 #include <errno.h>
 #include <unistd.h>
 #include <string.h>
 #include <etk/stdTools.h>
 
+#ifdef __TARGET_OS__Windows
+	#include <winsock2.h>
+	//https://msdn.microsoft.com/fr-fr/library/windows/desktop/ms737889(v=vs.85).aspx
+#else
+	#include <sys/socket.h>
+	#include <netinet/in.h>
+	#include <netinet/tcp.h>
+	#include <netdb.h>
+#endif
 
 enet::TcpServer::TcpServer() :
   m_socketId(-1),
diff --git a/enet/TcpServer.h b/enet/TcpServer.h
index c07174b..3b5b1dc 100644
--- a/enet/TcpServer.h
+++ b/enet/TcpServer.h
@@ -4,15 +4,18 @@
  * @license APACHE v2.0 (see license file)
  */
 #pragma once
-
-#include <poll.h>
 #include <enet/Tcp.h>
+#ifdef __TARGET_OS__Windows
+	
+#else
+	#include <poll.h>
+#endif
 
 namespace enet {
 	class TcpServer {
 		private:
 			int32_t m_socketId; //!< socket linux interface generic
-			#if 1
+			#ifndef __TARGET_OS__Windows
 				struct pollfd m_fds[1];
 			#endif
 		public:
diff --git a/lutin_enet.py b/lutin_enet.py
index 503e092..95ef303 100644
--- a/lutin_enet.py
+++ b/lutin_enet.py
@@ -31,13 +31,9 @@ def create(target, module_name):
 	    'ememory',
 	    'algue'
 	    ])
-	my_module.add_src_file([
-	    'enet/debug.cpp'
-	    ])
 	my_module.add_path(tools.get_current_path(__file__))
-	if "Windows" in target.get_type():
-		return my_module
 	my_module.add_src_file([
+	    'enet/debug.cpp',
 	    'enet/Udp.cpp',
 	    'enet/Tcp.cpp',
 	    'enet/TcpServer.cpp',