Use MSG_NONBLOCKING for recv/send

This commit is contained in:
cpq 2020-12-12 16:48:47 +00:00
parent a0765ade6b
commit c5b1c08d05
2 changed files with 12 additions and 4 deletions

View File

@ -2245,6 +2245,10 @@ typedef int SOCKET;
#define FD(C_) ((SOCKET)(long) (C_)->fd)
#endif
#ifndef MSG_NONBLOCKING
#define MSG_NONBLOCKING 0
#endif
union usa {
struct sockaddr sa;
struct sockaddr_in sin;
@ -2297,7 +2301,7 @@ static int mg_sock_recv(struct mg_connection *c, void *buf, int len,
c->peer.port = usa.sin.sin_port;
}
} else {
n = recv(FD(c), buf, len, 0);
n = recv(FD(c), buf, len, MSG_NONBLOCKING);
}
*fail = (n == 0) || (n < 0 && mg_sock_failed());
return n;
@ -2310,7 +2314,7 @@ static int mg_sock_send(struct mg_connection *c, const void *buf, int len,
union usa usa = tousa(&c->peer);
n = sendto(FD(c), buf, len, 0, &usa.sa, sizeof(usa.sin));
} else {
n = send(FD(c), buf, len, 0);
n = send(FD(c), buf, len, MSG_NONBLOCKING);
}
*fail = (n == 0) || (n < 0 && mg_sock_failed());
return n;

View File

@ -26,6 +26,10 @@ typedef int SOCKET;
#define FD(C_) ((SOCKET)(long) (C_)->fd)
#endif
#ifndef MSG_NONBLOCKING
#define MSG_NONBLOCKING 0
#endif
union usa {
struct sockaddr sa;
struct sockaddr_in sin;
@ -78,7 +82,7 @@ static int mg_sock_recv(struct mg_connection *c, void *buf, int len,
c->peer.port = usa.sin.sin_port;
}
} else {
n = recv(FD(c), buf, len, 0);
n = recv(FD(c), buf, len, MSG_NONBLOCKING);
}
*fail = (n == 0) || (n < 0 && mg_sock_failed());
return n;
@ -91,7 +95,7 @@ static int mg_sock_send(struct mg_connection *c, const void *buf, int len,
union usa usa = tousa(&c->peer);
n = sendto(FD(c), buf, len, 0, &usa.sa, sizeof(usa.sin));
} else {
n = send(FD(c), buf, len, 0);
n = send(FD(c), buf, len, MSG_NONBLOCKING);
}
*fail = (n == 0) || (n < 0 && mg_sock_failed());
return n;