Socket相關(guān)程序:從Windows移植到Linux
socket相關(guān)程序從windows移植到linux下需要注意的
1)頭文件
windows下winsock.h/winsock2.h
linux下sys/socket.h
錯誤處理:errno.h
2)初始化
windows下需要用WSAStartup
linux下不需要
3)關(guān)閉socket
windows下closesocket(...)
linux下close(...)
4)類型
windows下SOCKET
linux下int
如我用到的一些宏:
#ifdef WIN32
typedef int socklen_t;
typedef int ssize_t;
#endif
#ifdef __LINUX__
typedef int SOCKET;
typedef unsigned char BYTE;
typedef unsigned long DWORD;
#define FALSE 0
#define SOCKET_ERROR (-1)
#endif
5)獲取錯誤碼
windows下getlasterror()/WSAGetLastError()
linux下errno變量
6)設(shè)置非阻塞
windows下ioctlsocket()
linux下fcntl()
7)send函數(shù)最后一個參數(shù)
windows下一般設(shè)置為0
linux下最好設(shè)置為MSG_NOSIGNAL,如果不設(shè)置,在發(fā)送出錯后有可 能會導(dǎo)致程序退出。
8)毫秒級時間獲取
windows下GetTickCount()
linux下gettimeofday()
多線程
多線程: (win)process.h --〉(linux)pthread.h
_beginthread --> pthread_create
_endthread --> pthread_exit
相關(guān)文章:
1. windows10游戲特別優(yōu)化版在哪下載2. 世界上最流行的操作系統(tǒng)不是Linux或者Windows,而是MINIX3. GPT分區(qū)安裝Windows系統(tǒng)失敗怎么解決4. Windows XP 鍵盤快捷鍵概述5. Win10系統(tǒng)Windows.edb文件可以刪除嗎?6. 怎么更改Windows11鼠標(biāo)指針大小和樣式?7. windows11開啟剪貼板自動復(fù)制方法介紹8. 如何從Windows 10升級到Windows 11?Win10升級到Win11的正確圖文步驟9. Windows10禁用服務(wù)主機(jī)技巧分享10. 了解Windows 7中第一次提供的系統(tǒng)故障自修復(fù)功能
