mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-19 19:40:56 +00:00
Use MSG_NONBLOCKING for recv/send
This commit is contained in:
1 parent
a0765ade6b
commit
c5b1c08d05
2 files changed
+12
-4
No files matched your search
+6
-2
@@ -2245,6 +2245,10 @@ typedef int SOCKET;
|
|||||||
#define FD(C_) ((SOCKET)(long) (C_)->fd)
|
#define FD(C_) ((SOCKET)(long) (C_)->fd)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef MSG_NONBLOCKING
|
||||||
|
#define MSG_NONBLOCKING 0
|
||||||
|
#endif
|
||||||
|
|
||||||
union usa {
|
union usa {
|
||||||
struct sockaddr sa;
|
struct sockaddr sa;
|
||||||
struct sockaddr_in sin;
|
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;
|
c->peer.port = usa.sin.sin_port;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
n = recv(FD(c), buf, len, 0);
|
n = recv(FD(c), buf, len, MSG_NONBLOCKING);
|
||||||
}
|
}
|
||||||
*fail = (n == 0) || (n < 0 && mg_sock_failed());
|
*fail = (n == 0) || (n < 0 && mg_sock_failed());
|
||||||
return n;
|
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);
|
union usa usa = tousa(&c->peer);
|
||||||
n = sendto(FD(c), buf, len, 0, &usa.sa, sizeof(usa.sin));
|
n = sendto(FD(c), buf, len, 0, &usa.sa, sizeof(usa.sin));
|
||||||
} else {
|
} else {
|
||||||
n = send(FD(c), buf, len, 0);
|
n = send(FD(c), buf, len, MSG_NONBLOCKING);
|
||||||
}
|
}
|
||||||
*fail = (n == 0) || (n < 0 && mg_sock_failed());
|
*fail = (n == 0) || (n < 0 && mg_sock_failed());
|
||||||
return n;
|
return n;
|
||||||
|
|||||||
+6
-2
@@ -26,6 +26,10 @@ typedef int SOCKET;
|
|||||||
#define FD(C_) ((SOCKET)(long) (C_)->fd)
|
#define FD(C_) ((SOCKET)(long) (C_)->fd)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef MSG_NONBLOCKING
|
||||||
|
#define MSG_NONBLOCKING 0
|
||||||
|
#endif
|
||||||
|
|
||||||
union usa {
|
union usa {
|
||||||
struct sockaddr sa;
|
struct sockaddr sa;
|
||||||
struct sockaddr_in sin;
|
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;
|
c->peer.port = usa.sin.sin_port;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
n = recv(FD(c), buf, len, 0);
|
n = recv(FD(c), buf, len, MSG_NONBLOCKING);
|
||||||
}
|
}
|
||||||
*fail = (n == 0) || (n < 0 && mg_sock_failed());
|
*fail = (n == 0) || (n < 0 && mg_sock_failed());
|
||||||
return n;
|
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);
|
union usa usa = tousa(&c->peer);
|
||||||
n = sendto(FD(c), buf, len, 0, &usa.sa, sizeof(usa.sin));
|
n = sendto(FD(c), buf, len, 0, &usa.sa, sizeof(usa.sin));
|
||||||
} else {
|
} else {
|
||||||
n = send(FD(c), buf, len, 0);
|
n = send(FD(c), buf, len, MSG_NONBLOCKING);
|
||||||
}
|
}
|
||||||
*fail = (n == 0) || (n < 0 && mg_sock_failed());
|
*fail = (n == 0) || (n < 0 && mg_sock_failed());
|
||||||
return n;
|
return n;
|
||||||
|
|||||||
Reference in new issue
Block a user