Răsfoiți Sursa

T20L8071 #comment 暂时将WSA的接口声明,后续作为重头再实现

gifur 5 ani în urmă
părinte
comite
a0ff9ab53a

+ 4 - 1
CMakeLists.txt

@@ -310,7 +310,10 @@ set(CPACK_PACKAGE_VERSION_MAJOR ${RVC_VERSION_MAJOR})
 set(CPACK_PACKAGE_VERSION_MINOR ${RVC_VERSION_MINOR})
 set(CPACK_PACKAGE_VERSION_PATCH ${RVC_VERSION_REVISION})
 
-set(CPACK_COMPONENTS_ALL headers libraries symbols scripts)
+#set(CPACK_COMPONENTS_ALL headers libraries symbols scripts)
+#TODO: to comfirm
+set(CPACK_COMPONENTS_ALL libraries symbols scripts)
+
 
 if(MSVC)
 	if( NOT CPACK_GENERATOR)

+ 1 - 1
CMakeSettings.json

@@ -18,7 +18,7 @@
       "configurationType": "Debug",
       "buildRoot": "${projectDir}\\out\\build\\${name}",
       "installRoot": "${projectDir}\\out\\install\\${name}",
-      "cmakeCommandArgs": "-D BUILD_TESTING=ON",
+      "cmakeCommandArgs": "-D BUILD_TESTING=OFF",
       "buildCommandArgs": "",
       "ctestCommandArgs": "-C Debug",
       "inheritEnvironments": [ "msvc_x86" ],

+ 5 - 5
libtoolkit/bus.c

@@ -7,11 +7,11 @@
 #include "list.h"
 #include "bus_internal.h"
 
-#define BUS_RESULT_DATA		1				// ==BUS_TYPE_PACKET, 回调callback.on_pkt,  未启用
-#define BUS_RESULT_INFO		2				// ==BUS_TYPE_INFO, 回调callback.on_inf
-#define BUS_RESULT_EVENT	3				// ==BUS_TYPE_EVENT, 回调callback.on_evt ,  未启用
-#define BUS_RESULT_SYSTEM	4				// ==BUS_TYPE_SYSTEM, 回调callback.on_sys
-#define BUS_RESULT_MSG		5				// 发送包消息, 回调callback.on_msg
+#define BUS_RESULT_DATA		1				// ==BUS_TYPE_PACKET, callback: callback.on_pkt,  no use
+#define BUS_RESULT_INFO		2				// ==BUS_TYPE_INFO, callback: callback.on_inf
+#define BUS_RESULT_EVENT  	3				// ==BUS_TYPE_EVENT, callback: callback.on_evt ,  no use
+#define BUS_RESULT_SYSTEM	4				// ==BUS_TYPE_SYSTEM, callback: callback.on_sys
+#define BUS_RESULT_MSG		5				// send package msg, callback: callback.on_msg
 #define BUS_RESULT_UNKNOWN	6
 
 typedef struct msg_t {

+ 4 - 1
libtoolkit/spinlock.h

@@ -5,8 +5,11 @@
 
 #include "config.h"
 
-#include <intrin.h>
+#if _WIN32
+  #include <intrin.h>
+#endif
 #include <assert.h>
+#include <winpr/interlocked.h>
 
 #ifdef __cplusplus
 extern "C" {

+ 163 - 0
winpr/include/winpr/winsock.h

@@ -142,6 +142,59 @@ typedef struct sockaddr_storage SOCKADDR_STORAGE;
 
 #define SOCKET_ERROR (-1)
 
+//
+// Define socket-level options.
+//
+
+//#define SO_DEBUG        0x0001      // turn on debugging info recording
+//#define SO_ACCEPTCONN   0x0002      // socket has had listen()
+//#define SO_REUSEADDR    0x0004      // allow local address reuse
+//#define SO_KEEPALIVE    0x0008      // keep connections alive
+//#define SO_DONTROUTE    0x0010      // just use interface addresses
+//#define SO_BROADCAST    0x0020      // permit sending of broadcast msgs
+//#define SO_USELOOPBACK  0x0040      // bypass hardware when possible
+//#define SO_LINGER       0x0080      // linger on close if data present
+//#define SO_OOBINLINE    0x0100      // leave received OOB data in line
+
+#define SO_DONTLINGER   (int)(~SO_LINGER)
+//#define SO_EXCLUSIVEADDRUSE \
+//    ((int)(~SO_REUSEADDR))          // disallow local address reuse
+//
+//#define SO_SNDBUF       0x1001      // send buffer size
+//#define SO_RCVBUF       0x1002      // receive buffer size
+//#define SO_SNDLOWAT     0x1003      // send low-water mark
+//#define SO_RCVLOWAT     0x1004      // receive low-water mark
+//#define SO_SNDTIMEO     0x1005      // send timeout
+//#define SO_RCVTIMEO     0x1006      // receive timeout
+//#define SO_ERROR        0x1007      // get error status and clear
+//#define SO_TYPE         0x1008      // get socket type
+//#define SO_BSP_STATE    0x1009      // get socket 5-tuple state
+//
+//#define SO_GROUP_ID     0x2001      // ID of a socket group
+//#define SO_GROUP_PRIORITY 0x2002    // the relative priority within a group
+//#define SO_MAX_MSG_SIZE 0x2003      // maximum message size
+//
+//#define SO_CONDITIONAL_ACCEPT 0x3002 // enable true conditional accept:
+//// connection is not ack-ed to the
+//// other side until conditional
+//// function returns CF_ACCEPT
+//#define SO_PAUSE_ACCEPT 0x3003      // pause accepting new connections
+//#define SO_COMPARTMENT_ID 0x3004    // get/set the compartment for a socket
+
+#define SO_UPDATE_ACCEPT_CONTEXT    0x700B
+
+/*
+ * WinSock 2 extension -- manifest constants for WSASocket()
+ */
+#define WSA_FLAG_OVERLAPPED           0x01
+#define WSA_FLAG_MULTIPOINT_C_ROOT    0x02
+#define WSA_FLAG_MULTIPOINT_C_LEAF    0x04
+#define WSA_FLAG_MULTIPOINT_D_ROOT    0x08
+#define WSA_FLAG_MULTIPOINT_D_LEAF    0x10
+#define WSA_FLAG_ACCESS_SYSTEM_SECURITY 0x40
+
+#define WSA_IO_PENDING          (ERROR_IO_PENDING)
+
 typedef struct WSAData
 {
 	WORD wVersion;
@@ -170,6 +223,14 @@ typedef struct in6_addr IN6_ADDR;
 typedef struct in6_addr* PIN6_ADDR;
 typedef struct in6_addr* LPIN6_ADDR;
 
+typedef struct sockaddr SOCKADDR;
+typedef struct sockaddr *PSOCKADDR;
+typedef struct sockaddr *LPSOCKADDR;
+
+typedef struct linger LINGER;
+typedef struct linger *PLINGER;
+typedef struct linger *LPLINGER;
+
 struct sockaddr_in6_old
 {
 	SHORT sin6_family;
@@ -257,6 +318,11 @@ typedef struct _WSAPROTOCOL_INFOW
 	WCHAR szProtocol[WSAPROTOCOL_LEN + 1];
 } WSAPROTOCOL_INFOW, *LPWSAPROTOCOL_INFOW;
 
+typedef struct _WSANETWORKEVENTS {
+    long lNetworkEvents;
+    int iErrorCode[FD_MAX_EVENTS];
+} WSANETWORKEVENTS, FAR * LPWSANETWORKEVENTS;
+
 typedef void(CALLBACK* LPWSAOVERLAPPED_COMPLETION_ROUTINE)(DWORD dwError, DWORD cbTransferred,
                                                            LPWSAOVERLAPPED lpOverlapped,
                                                            DWORD dwFlags);
@@ -272,6 +338,72 @@ typedef UINT32 GROUP;
 #define SIOCSIPMSFILTER SIO_SET_MULTICAST_FILTER
 #define SIOCGIPMSFILTER SIO_GET_MULTICAST_FILTER
 
+#define IOCPARM_MASK    0x7f            /* parameters must be < 128 bytes */
+#define IOC_VOID        0x20000000      /* no parameters */
+
+/*
+ * WinSock 2 extension -- manifest constants for WSAIoctl()
+ */
+#define IOC_UNIX                      0x00000000
+#define IOC_WS2                       0x08000000
+#define IOC_PROTOCOL                  0x10000000
+#define IOC_VENDOR                    0x18000000
+
+#define _WSAIO(x,y)                   (IOC_VOID|(x)|(y))
+#define _WSAIOR(x,y)                  (IOC_OUT|(x)|(y))
+#define _WSAIOW(x,y)                  (IOC_IN|(x)|(y))
+#define _WSAIORW(x,y)                 (IOC_INOUT|(x)|(y))
+
+
+#define SIO_GET_EXTENSION_FUNCTION_POINTER  _WSAIORW(IOC_WS2,6)
+/*
+ * MS Transport Provider IOCTL to control
+ * reporting PORT_UNREACHABLE messages
+ * on UDP sockets via recv/WSARecv/etc.
+ * Path TRUE in input buffer to enable (default if supported),
+ * FALSE to disable.
+ */
+#define SIO_UDP_CONNRESET           _WSAIOW(IOC_VENDOR,12)
+
+
+
+// MSWSock.h
+
+#define SO_CONNECT_TIME             0x700C
+
+typedef
+BOOL
+(PASCAL FAR * LPFN_ACCEPTEX)(
+		 SOCKET sListenSocket,
+		 SOCKET sAcceptSocket,
+		 PVOID lpOutputBuffer,
+		 DWORD dwReceiveDataLength,
+		 DWORD dwLocalAddressLength,
+		 DWORD dwRemoteAddressLength,
+		 LPDWORD lpdwBytesReceived,
+		 LPOVERLAPPED lpOverlapped
+);
+
+#define WSAID_ACCEPTEX \
+        {0xb5367df1,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}
+
+typedef
+VOID
+(PASCAL FAR * LPFN_GETACCEPTEXSOCKADDRS)(
+		 PVOID lpOutputBuffer,
+		 DWORD dwReceiveDataLength,
+		 DWORD dwLocalAddressLength,
+		 DWORD dwRemoteAddressLength,
+		struct sockaddr **LocalSockaddr,
+		 LPINT LocalSockaddrLength,
+		struct sockaddr **RemoteSockaddr,
+		 LPINT RemoteSockaddrLength
+);
+
+#define WSAID_GETACCEPTEXSOCKADDRS \
+        {0xb5367df2,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}
+
+
 #ifdef UNICODE
 #define WSAPROTOCOL_INFO WSAPROTOCOL_INFOW
 #define LPWSAPROTOCOL_INFO LPWSAPROTOCOL_INFOW
@@ -311,6 +443,37 @@ extern "C"
 	                       LPWSAOVERLAPPED lpOverlapped,
 	                       LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine);
 
+	WINPR_API int WSASend(SOCKET s, LPWSABUF lpBuffers,
+		DWORD dwBufferCount,
+		LPDWORD lpNumberOfBytesSent,
+		DWORD dwFlags,
+		LPWSAOVERLAPPED lpOverlapped,
+		LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine);
+
+	WINPR_API int WSARecv( SOCKET s, LPWSABUF lpBuffers,
+			DWORD dwBufferCount,
+			LPDWORD lpNumberOfBytesRecvd,
+			LPDWORD lpFlags,
+			LPWSAOVERLAPPED lpOverlapped,
+			LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine);
+
+	WINPR_API int WSASendTo(SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, LPDWORD lpNumberOfBytesSent,
+			DWORD dwFlags, const struct sockaddr FAR * lpTo, int iTolen, LPWSAOVERLAPPED lpOverlapped,
+			LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine);
+
+	WINPR_API int WSARecvFrom(SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, LPDWORD lpNumberOfBytesRecvd,
+			LPDWORD lpFlags, struct sockaddr FAR * lpFrom, LPINT lpFromlen, LPWSAOVERLAPPED lpOverlapped,
+			LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine);
+
+	WINPR_API BOOL AcceptEx (SOCKET sListenSocket, SOCKET sAcceptSocket, PVOID lpOutputBuffer,
+	        DWORD dwReceiveDataLength, DWORD dwLocalAddressLength, DWORD dwRemoteAddressLength,
+	        LPDWORD lpdwBytesReceived, LPOVERLAPPED lpOverlapped);
+
+	WINPR_API BOOL WSAGetOverlappedResult(SOCKET s, LPWSAOVERLAPPED lpOverlapped,
+										  LPDWORD lpcbTransfer, BOOL fWait, LPDWORD lpdwFlags);
+
+	WINPR_API int WSAEnumNetworkEvents(SOCKET s, WSAEVENT hEventObject, LPWSANETWORKEVENTS lpNetworkEvents);
+
 	WINPR_API SOCKET _accept(SOCKET s, struct sockaddr* addr, int* addrlen);
 	WINPR_API int _bind(SOCKET s, const struct sockaddr* addr, int namelen);
 	WINPR_API int closesocket(SOCKET s);

+ 45 - 0
winpr/include/winpr/wtypes.h.in

@@ -554,4 +554,49 @@ typedef const BYTE* LPCBYTE;
 #define _ftelli64(fp) ftello(fp)
 #endif
 
+#ifndef _WIN32
+typedef struct _WSABUF {
+	ULONG len;     /* the length of the buffer */
+	CHAR  *buf; /* the pointer to the buffer */
+} WSABUF, *LPWSABUF;
+
+#endif
+
+#ifndef _WIN32
+/* Conflicts with libstdc++ header macros */
+//#define __in
+//#define __out
+#define __out_z
+#define __inout
+#define __inout_z
+#define __in_opt
+#define __in_z_opt
+#define __out_opt
+#define __inout_opt
+#define __inout_z_opt
+#define __checkReturn
+#define WINADVAPI
+#define __in_ecount_opt(size)
+#define _cdecl
+#define __stdcall
+#define __cdecl
+#define NTAPI
+#define IN
+#define OUT
+#define PASCAL
+#define OPTIONAL
+#define WINAPI
+#define CALLBACK
+#define UNALIGNED
+#endif
+
+
+#ifndef _WIN32
+
+#define _alloca alloca
+#define _fwrite_nolock fwrite
+#define _fflush_nolock fflush
+
+#endif
+
 #endif /* WINPR_WTYPES_H */

+ 66 - 0
winpr/libwinpr/winsock/winsock.c

@@ -297,6 +297,9 @@ INT winpr_inet_pton(INT Family, PCSTR pszAddrString, PVOID pAddrBuf)
 #include <netinet/tcp.h>
 #include <net/if.h>
 
+#include "../log.h"
+#define TAG WINPR_TAG("winsock")
+
 #ifndef MSG_NOSIGNAL
 #define MSG_NOSIGNAL 0
 #endif
@@ -1001,6 +1004,69 @@ int WSAIoctl(SOCKET s, DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuff
 	return 0;
 }
 
+int WSASend(SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount,
+            LPDWORD lpNumberOfBytesSent, DWORD dwFlags, LPWSAOVERLAPPED lpOverlapped,
+            LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
+{
+    //TODO: implement it.
+	WLog_WARN(TAG, "The called function <%s> is not implemented yet!", __FUNCTION__);
+    return SOCKET_ERROR;
+}
+
+int WSARecv( SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, LPDWORD lpNumberOfBytesRecvd,
+             LPDWORD lpFlags, LPWSAOVERLAPPED lpOverlapped,
+             LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
+{
+    //TODO: implement it.
+	WLog_WARN(TAG, "The called function <%s> is not implemented yet!", __FUNCTION__);
+    return SOCKET_ERROR ;
+}
+
+int WSAEnumNetworkEvents(SOCKET s, WSAEVENT hEventObject, LPWSANETWORKEVENTS lpNetworkEvents)
+{
+	//TODO: implement it.
+	WLog_WARN(TAG, "The called function <%s> is not implemented yet!", __FUNCTION__);
+	return 0;
+}
+
+int WSASendTo(SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, LPDWORD lpNumberOfBytesSent,
+			  DWORD dwFlags, const struct sockaddr FAR * lpTo, int iTolen, LPWSAOVERLAPPED lpOverlapped,
+			  LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
+)
+{
+	//TODO: implement it.
+	WLog_WARN(TAG, "The called function <%s> is not implemented yet!", __FUNCTION__);
+	return 0;
+}
+
+int WSARecvFrom(SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, LPDWORD lpNumberOfBytesRecvd,
+						  LPDWORD lpFlags, struct sockaddr FAR * lpFrom, LPINT lpFromlen, LPWSAOVERLAPPED lpOverlapped,
+						  LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
+)
+{
+	//TODO: implement it.
+	WLog_WARN(TAG, "The called function <%s> is not implemented yet!", __FUNCTION__);
+	return 0;
+}
+
+BOOL AcceptEx (SOCKET sListenSocket, SOCKET sAcceptSocket, PVOID lpOutputBuffer,
+                         DWORD dwReceiveDataLength, DWORD dwLocalAddressLength, DWORD dwRemoteAddressLength,
+                         LPDWORD lpdwBytesReceived, LPOVERLAPPED lpOverlapped)
+{
+    //TODO: implement it.
+	WLog_WARN(TAG, "The called function <%s> is not implemented yet!", __FUNCTION__);
+    return FALSE;
+}
+
+BOOL WSAGetOverlappedResult(SOCKET s, LPWSAOVERLAPPED lpOverlapped,
+							LPDWORD lpcbTransfer, BOOL fWait, LPDWORD lpdwFlags)
+{
+	//TODO: implement it.
+	WLog_WARN(TAG, "The called function <%s> is not implemented yet!", __FUNCTION__);
+	return FALSE;
+}
+
+
 SOCKET _accept(SOCKET s, struct sockaddr* addr, int* addrlen)
 {
 	int status;