OLD | NEW |
1 #include <sys/socket.h> | 1 #include <sys/socket.h> |
2 #include <fcntl.h> | 2 #include <fcntl.h> |
3 #include <errno.h> | 3 #include <errno.h> |
4 #include "syscall.h" | 4 #include "syscall.h" |
5 | 5 |
6 int socketpair(int domain, int type, int protocol, int fd[2]) | 6 int socketpair(int domain, int type, int protocol, int fd[2]) { |
7 { | 7 int r = socketcall(socketpair, domain, type, protocol, fd, 0, 0); |
8 » int r = socketcall(socketpair, domain, type, protocol, fd, 0, 0); | 8 if (r < 0 && (errno == EINVAL || errno == EPROTONOSUPPORT) && |
9 » if (r<0 && (errno==EINVAL || errno==EPROTONOSUPPORT) | 9 (type & (SOCK_CLOEXEC | SOCK_NONBLOCK))) { |
10 » && (type&(SOCK_CLOEXEC|SOCK_NONBLOCK))) { | 10 r = socketcall(socketpair, domain, type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK), |
11 » » r = socketcall(socketpair, domain, | 11 protocol, fd, 0, 0); |
12 » » » type & ~(SOCK_CLOEXEC|SOCK_NONBLOCK), | 12 if (r < 0) |
13 » » » protocol, fd, 0, 0); | 13 return r; |
14 » » if (r < 0) return r; | 14 if (type & SOCK_CLOEXEC) { |
15 » » if (type & SOCK_CLOEXEC) { | 15 __syscall(SYS_fcntl, fd[0], F_SETFD, FD_CLOEXEC); |
16 » » » __syscall(SYS_fcntl, fd[0], F_SETFD, FD_CLOEXEC); | 16 __syscall(SYS_fcntl, fd[1], F_SETFD, FD_CLOEXEC); |
17 » » » __syscall(SYS_fcntl, fd[1], F_SETFD, FD_CLOEXEC); | 17 } |
18 » » } | 18 if (type & SOCK_NONBLOCK) { |
19 » » if (type & SOCK_NONBLOCK) { | 19 __syscall(SYS_fcntl, fd[0], F_SETFL, O_NONBLOCK); |
20 » » » __syscall(SYS_fcntl, fd[0], F_SETFL, O_NONBLOCK); | 20 __syscall(SYS_fcntl, fd[1], F_SETFL, O_NONBLOCK); |
21 » » » __syscall(SYS_fcntl, fd[1], F_SETFL, O_NONBLOCK); | 21 } |
22 » » } | 22 } |
23 » } | 23 return r; |
24 » return r; | |
25 } | 24 } |
OLD | NEW |