mirror of
https://github.com/cesanta/mongoose.git
synced 2025-08-06 13:37:34 +08:00
Use MSG_NONBLOCKING for recv/send
This commit is contained in:
parent
a0765ade6b
commit
c5b1c08d05
@ -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;
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user