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)類型
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()
多線程
多線程: (win)process.h --〉(linux)pthread.h
_beginthread --> pthread_create
_endthread --> pthread_exit
相關(guān)文章:
1. 微軟Windows Server VNext預(yù)覽版25276發(fā)布(附ISO鏡像下載)2. Windows7快捷鍵沖突3. windows10系統(tǒng)分區(qū)怎么分?4. 安全卸載windows20005. Windows11怎么設(shè)置區(qū)域?win11設(shè)置區(qū)域方法教程6. 淺談Windows Vista的硬件要求7. 教你繞過(guò)tpm2.0限制 進(jìn)行Windows11系統(tǒng)的安裝和運(yùn)行8. 關(guān)于64位Windows Vista版本9. Windows10如何阻止用戶從開始菜單卸載應(yīng)用程序?10. 調(diào)整注冊(cè)表讓W(xué)indows7預(yù)覽窗口更清晰

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