1.头文件
windows: #include <process.h> #include <Windows.h>
#include <winsock2.h>
#pragma comment(lib,"ws2_32.lib")
linux: #include <unistd.h> #include <pthread.h>
#include <sys/socket.h>
#include <netinet/in.h>
2.线程处理
windows: _beginthreadex _endthreadex
linux: pthread_create pthread_exit
3.锁
windows: CRITICAL_SECTION gCenterLock; InitializeCriticalSection(&gCenterLock); DeleteCriticalSection(&gCenterLock);
linux: pthread_mutex_t gCenterLock; pthread_mutex_init(&gCenterLock, NULL); pthread_mutex_destroy(&gCenterLock);
4.select
struct timeval timeout = {3,0};
fd_set fd;
FD_ZERO(&fd);
FD_SET(m_sock,&fd);
windows: select(NULL,&fd,NULL,NULL,&timeout);
linux: select(m_sock+1,&fd, NULL,NULL,&timeout);
5.sleep
windows: Sleep() ms为单位
linux: sleep() s 为单位 usleep() 微秒为单位