aboutsummaryrefslogtreecommitdiffhomepage
path: root/backends/libmmbackend.c
diff options
context:
space:
mode:
Diffstat (limited to 'backends/libmmbackend.c')
-rw-r--r--backends/libmmbackend.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/backends/libmmbackend.c b/backends/libmmbackend.c
index 6320611..b27ebc5 100644
--- a/backends/libmmbackend.c
+++ b/backends/libmmbackend.c
@@ -53,7 +53,7 @@ int mmbackend_parse_sockaddr(char* host, char* port, struct sockaddr_storage* ad
}
int mmbackend_socket(char* host, char* port, int socktype, uint8_t listener){
- int fd = -1, status, yes = 1, flags;
+ int fd = -1, status, yes = 1;
struct addrinfo hints = {
.ai_family = AF_UNSPEC,
.ai_socktype = socktype,
@@ -106,12 +106,20 @@ int mmbackend_socket(char* host, char* port, int socktype, uint8_t listener){
}
//set nonblocking
- flags = fcntl(fd, F_GETFL, 0);
+ #ifdef _WIN32
+ u_long mode = 1;
+ if(ioctlsocket(fd, FIONBIO, &mode) != NO_ERROR){
+ closesocket(fd);
+ return 1;
+ }
+ #else
+ int flags = fcntl(fd, F_GETFL, 0);
if(fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0){
fprintf(stderr, "Failed to set socket nonblocking\n");
close(fd);
return -1;
}
+ #endif
return fd;
}