Browse Source

fix windows compiler bug, not support unix socket

jarodruan 2 years ago
parent
commit
f1122f165f

+ 2 - 1
util/include/util/tc_socket.h

@@ -569,8 +569,9 @@ public:
 	*/
 	static void parseAddrWithPort(const string& host, int port, struct sockaddr_in& addr);
 	static void parseAddrWithPort(const string& host, int port, struct sockaddr_in6& addr);
+#if !TARGET_PLATFORM_WINDOWS
 	static void parseUnixLocalAddr(const char* sPathName, struct sockaddr_un& addr);
-
+#endif
 	/**
     * @brief 判断当前socket是否处于EAGAIN/WSAEWOULDBLOCK(异步send/recv函数返回值时判断)
     *

+ 11 - 0
util/include/util/tc_transceiver.h

@@ -18,6 +18,7 @@
 #define TC_CPP_TRANSCEIVER_H
 
 #include <list>
+#include "util/tc_platform.h"
 #include "util/tc_network_buffer.h"
 #include "util/tc_clientsocket.h"
 #include "util/tc_epoller.h"
@@ -367,13 +368,23 @@ public:
 	 */
 	inline bool isConnectIPv6() const  { return !isUnixLocal() && getConnectEndpoint().isIPv6(); }
 
+#if !TARGET_PLATFORM_WINDOWS
+
 	/**
 	 * is unix local
 	 * @return
 	 */
 	inline bool isUnixLocal() const  { return getConnectEndpoint().isUnixLocal(); }
+#else
 
 	/**
+	 * is unix local
+	 * @return
+	 */
+	inline bool isUnixLocal() const  { return false; }
+
+#endif
+	/**
      * 设置连接超时时间(tcp下才有效)
      */
     void setConnTimeout(int connTimeout) { _connTimeout = connTimeout; }

+ 2 - 1
util/src/epoll_windows/src/epoll.cpp

@@ -6,6 +6,7 @@
 #include <cassert>
 #include <mutex>
 #include <iostream>
+#include <algorithm>
 
 using namespace std;
 
@@ -619,7 +620,7 @@ int epoll_wait(epoll_t port_handle, struct epoll_event *events, int maxevents, i
 
     /* Compute how much overlapped entries can be dequeued at most. */
     int tmp_count = ARRAY_COUNT(entries);
-    DWORD max_entries = min(tmp_count, maxevents);
+    DWORD max_entries = std::min(tmp_count, maxevents);
     ULONG count = 0;
 
     DWORD result = GetQueuedCompletionStatusEx(port_data->getHandle(), entries, max_entries, &count, gqcs_timeout, TRUE);

+ 9 - 2
util/src/tc_socket.cpp

@@ -374,13 +374,16 @@ TC_Socket::addr_type TC_Socket::createSockAddr(const char *str)
 TC_Socket::addr_type TC_Socket::createSockAddr(const TC_Endpoint &ep)
 {
 	TC_Socket::addr_type addr;
-
+#if !TARGET_PLATFORM_WINDOWS
 	if(ep.isUnixLocal())
 	{
 		addr.first.reset((sockaddr *) new sockaddr_un());
 		addr.second = sizeof(struct sockaddr_un);
 	}
-	else if (TC_Socket::addressIsIPv6(ep.getHost()))
+	else 
+#endif
+
+    if (TC_Socket::addressIsIPv6(ep.getHost()))
 	{
 		addr.first.reset( (sockaddr *)new sockaddr_in6());
 		addr.second = sizeof(struct sockaddr_in6);
@@ -408,6 +411,8 @@ void TC_Socket::parseAddrWithPort(const string& host, int port, struct sockaddr_
     }
 }
 
+#if !TARGET_PLATFORM_WINDOWS
+
 void TC_Socket::parseUnixLocalAddr(const char* sPathName, struct sockaddr_un& addr)
 {
 	memset(&addr, 0x00, sizeof(addr));
@@ -415,6 +420,8 @@ void TC_Socket::parseUnixLocalAddr(const char* sPathName, struct sockaddr_un& ad
 	strncpy(addr.sun_path, sPathName, sizeof(addr.sun_path));
 }
 
+#endif
+
 void TC_Socket::parseAddrWithPort(const string& host, int port, struct sockaddr_in6& addr)
 {
 	memset(&addr, 0, sizeof(struct sockaddr_in6));

+ 2 - 0
util/src/tc_transceiver.cpp

@@ -287,11 +287,13 @@ namespace tars
 
 	void TC_Transceiver::parseConnectAddress()
 	{
+#if !TARGET_PLATFORM_WINDOWS
 		if(isUnixLocal())
 		{
 			TC_Socket::parseUnixLocalAddr(getConnectEndpoint().getHost().c_str(), *(sockaddr_un*)_serverAddr.first.get());
 		}
 		else
+#endif
 		{
 			if (isConnectIPv6())
 			{