'How use 'fcntl' on Windows with and MinGW?
I'm trying to port a TCP application (specifically tcpsockets), however im getting this error:
error: 'fcntl' was not declared in this scope
I already wrote those includes
#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
Which solved most part of the references, however fcntl was not found.
How can I find a proper reference to it? Or naybe is there another windows method that could replace it?
Solution 1:[1]
fcntl() does not exist on Windows. For sockets, the equivalent function is ioctlsocket(). However, file controls on sockets in Linux are very different than in Windows, so not all of the fcntl() commands you are using may port to Windows, or may require different APIs.
Solution 2:[2]
Not sure why you are trying to use native sockets. But if there's no real reason, have a look at QTcpSocket instead. It's the Qt class for sockets and works on all platforms.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Felix |
