diff options
Diffstat (limited to 'ot_socket.c')
| -rw-r--r-- | ot_socket.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/ot_socket.c b/ot_socket.c index 47ed26d..78a16d2 100644 --- a/ot_socket.c +++ b/ot_socket.c | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include <errno.h> | 8 | #include <errno.h> |
| 9 | #include <fcntl.h> | 9 | #include <fcntl.h> |
| 10 | #include <netinet/in.h> | 10 | #include <netinet/in.h> |
| 11 | #include <netinet/tcp.h> | ||
| 11 | #include <string.h> | 12 | #include <string.h> |
| 12 | #include <sys/socket.h> | 13 | #include <sys/socket.h> |
| 13 | #include <unistd.h> | 14 | #include <unistd.h> |
| @@ -120,6 +121,25 @@ static int socket_bind_v6(int s, const ot_ip6 ip, uint16_t port, socket_sharing | |||
| 120 | return bind(s, (struct sockaddr *)&sa, sizeof(sa)); | 121 | return bind(s, (struct sockaddr *)&sa, sizeof(sa)); |
| 121 | } | 122 | } |
| 122 | 123 | ||
| 124 | /* Defer the listening socket reporting it to be ready to accept until enough | ||
| 125 | sensible data is available for an accept+read pair. Where available. */ | ||
| 126 | int socket_defer_accept(int s) { | ||
| 127 | #if defined(TCP_DEFER_ACCEPT) | ||
| 128 | int patience = OT_CLIENT_TIMEOUT; | ||
| 129 | |||
| 130 | return setsockopt(s, IPPROTO_TCP, TCP_DEFER_ACCEPT, &patience, sizeof(patience)); | ||
| 131 | #elif defined(SO_ACCEPTFILTER) | ||
| 132 | struct accept_filter_arg filter; | ||
| 133 | |||
| 134 | memset(&filter, 0, sizeof(filter)); | ||
| 135 | strcpy(filter.af_name, "httpready"); | ||
| 136 | return setsockopt(s, SOL_SOCKET, SO_ACCEPTFILTER, &filter, sizeof(filter)); | ||
| 137 | #else | ||
| 138 | (void)s; | ||
| 139 | return -1; | ||
| 140 | #endif | ||
| 141 | } | ||
| 142 | |||
| 123 | int socket_tcp_listen(const ot_ip6 ip, uint16_t port, socket_sharing sharing) { | 143 | int socket_tcp_listen(const ot_ip6 ip, uint16_t port, socket_sharing sharing) { |
| 124 | int s = socket_v6(SOCK_STREAM); | 144 | int s = socket_v6(SOCK_STREAM); |
| 125 | 145 | ||
