如何在 Windows 上与 MinGW 一起使用“fcntl”?

Dan*_*tos 5 c++ sockets

我正在尝试移植 TCP 应用程序(特别是tcpsockets),但是我收到此错误:

错误:“fcntl”未在此范围内声明

我已经写了这些包括

#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
Run Code Online (Sandbox Code Playgroud)

这解决了大部分参考文献,但fcntl没有找到。我怎样才能找到它的正确参考?或者也许有另一种 Windows 方法可以替代它?

Rem*_*eau 3

fcntl()Windows 上不存在。对于套接字,等效函数是ioctlsocket()fcntl()但是,Linux 中套接字上的文件控制与 Windows 中的文件控制非常不同,因此并非您使用的所有命令都可以移植到 Windows,或者它们可能需要不同的 API。

  • mingw 中没有这个函数为什么会有 `fcntl.h` 头文件 (2认同)