⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sock_os.h

📁 这个sokcet库
💻 H
字号:


#ifndef  SOCK_OS_H
#define  SOCK_OS_H

#define IP4_LEN  (16)
#define SEVER_PORT (5060)
#define SOCK_MAX_LISTEN_NUM (10)
			
#if defined(WIN32)
	#include "winsock2.h"
    #include "windows.h"
    #include "stdio.h"
    #include <direct.h>
    #include "string.h"
	#include "assert.h"
	#include "time.h"
	
	#define TIMER_CALLBACK CALLBACK    // 设置回调

	typedef void (TIMER_CALLBACK* EV_TIMER_FUN)(UINT wTimerID, UINT msg,
											DWORD dwUser,DWORD dw1,DWORD dw2);
	#define SOCKET_INVALID          -1
	#define SOCK_ERROR -1
	#define SOCK_SUCCESS  0
	
	#define   snprintf   (_snprintf)	
	typedef struct sockaddr_in SOCKADDR_IN;
    typedef struct sockaddr SOCKADDR;
	
	typedef  int socket_int;
	#define	 SOCKET_CLOSE	closesocket
	
	#define   LIN_ASSERT(x)  assert(x)//断言 ,VX没有 
	
#elif defined(VXWORKS)
	#include "stdio.h"
	#include "stdlib.h"
	#include "string.h"
    #include "semLib.h"
    #include "socket.h"
    #include "in.h"
    #include "time.h"
	
	#define TIMER_CALLBACK        // 设置回调
	typedef unsigned int            UINT;
    typedef long                    LONG;
    typedef unsigned char           UCHAR;
    typedef unsigned long           DWORD;
    typedef unsigned long long      UINT64;
    typedef long long int           INT64;
    typedef unsigned char           BYTE;
    typedef unsigned short          WORD;
    typedef unsigned short          USHORT;
    typedef UINT                    WPARAM;
    typedef LONG                    LPARAM;
    typedef DWORD                  COLORREF;

    typedef void (TIMER_CALLBACK* EV_TIMER_FUN)(UINT wTimerID, UINT msg,
											DWORD dwUser,DWORD dw1,DWORD dw2);

	#define SOCK_ERROR -1
	#define SOCK_SUCCESS 0
	 #define SOCKET_CLOSE    close
	
	typedef struct sockaddr_in SOCKADDR_IN;
    typedef struct sockaddr SOCKADDR;
	typedef socket_int int;

#elif defined(LINUX)
	#include <stdio.h>
    #include <stdlib.h>
    #include <stdarg.h>
    #include <string.h>
    #include <assert.h>
    #include <pthread.h> //pthread_create
    #include <unistd.h> //usleep
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <net/if.h>
    #include <arpa/inet.h>
    #include <netdb.h> //gethostbyname
    #include <semaphore.h>
    #include <time.h>
    #include <signal.h>
    #include <sys/ioctl.h>

	typedef int                     BOOL;
    #define TRUE                    1    
    #define FALSE                   0

    typedef unsigned int            UINT;
    typedef long                    LONG;
    typedef unsigned char           UCHAR;
    typedef unsigned long           DWORD;
    typedef unsigned long long      UINT64;
    typedef long long int           INT64;
    typedef unsigned char           BYTE;
    typedef unsigned short          WORD;
	typedef unsigned short          USHORT;
    typedef UINT                    WPARAM;
    typedef LONG                    LPARAM;
    typedef DWORD                   COLORREF;
	
	typedef void*           LPVOID;
	
	#define SOCK_ERROR          -1
	#define SOCK_SUCCESS         0

	typedef struct sockaddr_in SOCKADDR_IN;
    typedef struct sockaddr SOCKADDR;
	
	typedef socket_int int;
	#define SOCKET_CLOSE    close

	#define LIN_ASSERT(x) assert(x)         //断言
	
	#define SOCK_CALLBACK;        // 设置回调

	 typedef void (*EV_TIMER_FUN)(sigval_t t);
#endif 


#ifdef __cplusplus
extern "C" {
#endif

#if defined(WIN32)
	
	int inet_pton(int family,const char *strptr,void *addrptr);
	const char* inet_ntop(int family,const void *addrptr,char *strptr,size_t len);
	
#endif

	int WIN32_SOCKET_WSASTARTUP(void);
	int Udp_SocketSever_Create(void);
	int Udp_SocketCli_Create(char *server_addr);
	int Tcp_SocketSever_Creat(void);
	int Tcp_SocketCli_Create(char *server_addr);
/************************************************************************/
/*            以后逐渐扩大这个库函数;                                  */
/************************************************************************/
	

	
#ifdef __cplusplus
}
#endif



#endif // sock_os_h

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -