diff --git a/socket/socket_fastopen.c b/socket/socket_fastopen.c new file mode 100644 index 0000000..3363c2c --- /dev/null +++ b/socket/socket_fastopen.c @@ -0,0 +1,18 @@ +#include "socket.h" +#include +#include +#include +#include + +int socket_fastopen(int s) { +#ifdef TCP_FASTOPEN + return setsockopt(s,SOL_TCP,TCP_FASTOPEN,(int[]){ 5 }, sizeof(int)); +#else +#ifdef ENOPROTOOPT + errno=ENOPROTOOPT; +#else + errno=ENOSYS; +#endif + return -1; +#endif +} diff --git a/socket/socket_fastopen_connect4.c b/socket/socket_fastopen_connect4.c new file mode 100644 index 0000000..621f58c --- /dev/null +++ b/socket/socket_fastopen_connect4.c @@ -0,0 +1,20 @@ +#include "socket.h" +#include +#include +#include +#include + +ssize_t socket_fastopen_connect4(int s,const char* ip,uint16 port,const char* buf,size_t len) { +#ifndef MSG_FASTOPEN + int r; + { +#else + int r=socket_send4_flag(s,buf,len,ip,port,MSG_FASTOPEN); + if (r==-1 && errno==ENOTCONN) { +#endif + /* apparently the kernel does not support TCP fast open */ + r=socket_connect4(s,ip,port); + if (r==0) return write(s,buf,len); + } + return r; +} diff --git a/socket/socket_fastopen_connect6.c b/socket/socket_fastopen_connect6.c new file mode 100644 index 0000000..32d0340 --- /dev/null +++ b/socket/socket_fastopen_connect6.c @@ -0,0 +1,20 @@ +#include "socket.h" +#include +#include +#include +#include + +ssize_t socket_fastopen_connect6(int s,const char* ip,uint16 port,uint32_t scope_id,const char* buf,size_t len) { +#ifndef MSG_FASTOPEN + int r; + { +#else + int r=socket_send6_flag(s,buf,len,ip,port,scope_id,MSG_FASTOPEN); + if (r==-1 && errno==ENOTCONN) { +#endif + /* apparently the kernel does not support TCP fast open */ + r=socket_connect6(s,ip,port,scope_id); + if (r==0) return write(s,buf,len); + } + return r; +}