2016-08-18 137 views
0

我試圖端口的TCP應用程序(特別是tcpsockets),然而即時得到這個錯誤:如何在Windows和MinGW上使用'fcntl'?

error: 'fcntl' was not declared in this scope

我已經寫了這包括

#ifdef WIN32 
#define _WIN32_WINNT 0x0600 //enable 

#include <Ws2tcpip.h> 
#pragma comment(lib, "ws2_32.lib") 

typedef int socklen_t; 
void close(int socket){closesocket(socket);} 

#else 

#include <sys/types.h> 
#include <sys/socket.h> 
#include <netinet/in.h> 
#include <arpa/inet.h> 

#endif 

這解決了參考的大部分,但是fcntl未找到。 我如何找到適當的參考?或者是否有另一種窗口方法可以替代它?

+0

也許你可以告訴我們fcntl被用於什麼,所以我們可以幫助弄清楚什麼是等效的窗口。 –

回答

1

不知道你爲什麼試圖使用本地套接字。但是,如果沒有真正的原因,請轉到QTcpSocket。這是針對套接字的Qt類,適用於所有平臺。

1

fctrl()在Windows上不存在。對於套接字,等效功能是ioctlsocket()。但是,Linux中套接字上的文件控件與Windows中的套接字非常不同,因此並非所有您使用的fctrl()命令都可能移植到Windows,或者可能需要不同的API。