Socket相關(guān)程序:從Windows移植到Linux
socket相關(guān)程序從windows移植到linux下需要注意的
1)頭文件
windows下winsock.h/winsock2.h
linux下sys/socket.h
錯(cuò)誤處理:errno.h
2)初始化
windows下需要用WSAStartup
linux下不需要
3)關(guān)閉socket
windows下closesocket(...)
linux下close(...)
4)類(lèi)型
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)獲取錯(cuò)誤碼
windows下getlasterror()/WSAGetLastError()
linux下errno變量
6)設(shè)置非阻塞
windows下ioctlsocket()
linux下fcntl()
7)send函數(shù)最后一個(gè)參數(shù)
windows下一般設(shè)置為0
linux下最好設(shè)置為MSG_NOSIGNAL,如果不設(shè)置,在發(fā)送出錯(cuò)后有可 能會(huì)導(dǎo)致程序退出。
8)毫秒級(jí)時(shí)間獲取
windows下GetTickCount()
linux下gettimeofday()
多線(xiàn)程
多線(xiàn)程: (win)process.h --〉(linux)pthread.h
_beginthread --> pthread_create
_endthread --> pthread_exit
相關(guān)文章:
1. Mac電腦安裝Windows10教程2. Win10怎么更改文件類(lèi)型 windows如何修改文件類(lèi)型3. Windows 7應(yīng)用教程:玩轉(zhuǎn)Win7之圖標(biāo)的排列4. Windows Vista:微軟的一個(gè)新神話(huà)?5. 蘋(píng)果MAC機(jī)上安裝Windows 7系統(tǒng)圖文全攻略6. Windows7系統(tǒng)下Windows Virtual PC怎么用?7. Windows10如何設(shè)置世界之窗瀏覽器的字號(hào)大小?8. 虛擬機(jī)如何安裝Windows 11系統(tǒng)?用虛擬機(jī)安裝Windows 11方法配置教程9. Win8如何關(guān)閉Windows Media Player網(wǎng)絡(luò)共享服務(wù)?10. Windows系統(tǒng)怎么固定U盤(pán)的盤(pán)符?電腦固定U盤(pán)盤(pán)符教程

網(wǎng)公網(wǎng)安備