mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-28 23:49:44 +08:00
Use socketpair syscall when available
This commit is contained in:
parent
7ea3293aba
commit
d1d8a77bf6
@ -2593,6 +2593,13 @@ static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) {
|
||||
|
||||
#if MG_ENABLE_SOCKETPAIR
|
||||
bool mg_socketpair(int *s1, int *s2) {
|
||||
#if MG_ARCH == MG_ARCH_UNIX
|
||||
int sp[2], ret = 0;
|
||||
if (socketpair(AF_INET, SOCK_DGRAM, 0) == 0) {
|
||||
*s1 = sp[0], *s2 = sp[1], ret = 1;
|
||||
}
|
||||
return ret;
|
||||
#else
|
||||
union usa sa, sa2;
|
||||
SOCKET sp[2] = {INVALID_SOCKET, INVALID_SOCKET};
|
||||
socklen_t len = sizeof(sa.sin);
|
||||
@ -2619,6 +2626,7 @@ bool mg_socketpair(int *s1, int *s2) {
|
||||
}
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -356,6 +356,13 @@ static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) {
|
||||
|
||||
#if MG_ENABLE_SOCKETPAIR
|
||||
bool mg_socketpair(int *s1, int *s2) {
|
||||
#if MG_ARCH == MG_ARCH_UNIX
|
||||
int sp[2], ret = 0;
|
||||
if (socketpair(AF_INET, SOCK_DGRAM, 0) == 0) {
|
||||
*s1 = sp[0], *s2 = sp[1], ret = 1;
|
||||
}
|
||||
return ret;
|
||||
#else
|
||||
union usa sa, sa2;
|
||||
SOCKET sp[2] = {INVALID_SOCKET, INVALID_SOCKET};
|
||||
socklen_t len = sizeof(sa.sin);
|
||||
@ -382,6 +389,7 @@ bool mg_socketpair(int *s1, int *s2) {
|
||||
}
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user