support MSG_FASTOPEN on old kernels

This commit is contained in:
Aleksey Filippov 2015-02-17 15:27:01 +01:00
parent 8dd08e2cd2
commit 4e986caa2a
2 changed files with 8 additions and 2 deletions

View File

@ -482,9 +482,12 @@ struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type) {
return NULL; return NULL;
} }
#ifndef MSG_FASTOPEN
# define MSG_FASTOPEN 0x20000000
#endif
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
const struct sockaddr *dest_addr, socklen_t addrlen) { const struct sockaddr *dest_addr, socklen_t addrlen) {
#ifdef MSG_FASTOPEN
if (flags & MSG_FASTOPEN) { if (flags & MSG_FASTOPEN) {
if (!connect(sockfd, dest_addr, addrlen) && errno != EINPROGRESS) { if (!connect(sockfd, dest_addr, addrlen) && errno != EINPROGRESS) {
return -1; return -1;
@ -493,6 +496,5 @@ ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
addrlen = 0; addrlen = 0;
flags &= ~MSG_FASTOPEN; flags &= ~MSG_FASTOPEN;
} }
#endif
return true_sendto(sockfd, buf, len, flags, dest_addr, addrlen); return true_sendto(sockfd, buf, len, flags, dest_addr, addrlen);
} }

View File

@ -7,6 +7,10 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <netdb.h> #include <netdb.h>
#ifndef MSG_FASTOPEN
# define MSG_FASTOPEN 0x20000000
#endif
void error(const char *msg) void error(const char *msg)
{ {
perror(msg); perror(msg);