Cygwin: tcp: Support TCP_FASTOPEN

TCP_FASTOPEN is supported since W10 1607.  Fake otherwise.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2020-06-30 14:34:19 +02:00
parent e037192b50
commit 0feb77c260
5 changed files with 93 additions and 4 deletions

View File

@ -718,7 +718,8 @@ class fhandler_socket_wsock: public fhandler_socket
class fhandler_socket_inet: public fhandler_socket_wsock
{
private:
bool oobinline; /* True if option SO_OOBINLINE is set */
bool oobinline; /* True if option SO_OOBINLINE is set */
bool tcp_fastopen; /* True if TCP_FASTOPEN is set on older systems */
protected:
int af_local_connect () { return 0; }

View File

@ -691,7 +691,8 @@ fhandler_socket_wsock::set_socket_handle (SOCKET sock, int af, int type,
fhandler_socket_inet::fhandler_socket_inet () :
fhandler_socket_wsock (),
oobinline (false)
oobinline (false),
tcp_fastopen (false)
{
}
@ -1693,6 +1694,20 @@ fhandler_socket_inet::setsockopt (int level, int optname, const void *optval,
ignore = true;
break;
case TCP_FASTOPEN:
/* Fake FastOpen on older systems. */
if (!wincap.has_tcp_fastopen ())
{
if (type != SOCK_STREAM)
{
set_errno (EOPNOTSUPP);
return -1;
}
ignore = true;
tcp_fastopen = *(int *) optval ? true : false;
}
break;
default:
break;
}
@ -1825,6 +1840,29 @@ fhandler_socket_inet::getsockopt (int level, int optname, const void *optval,
optname = convert_ws1_ip_optname (optname);
break;
case IPPROTO_TCP:
switch (optname)
{
case TCP_FASTOPEN:
/* Fake FastOpen on older systems */
if (!wincap.has_tcp_fastopen ())
{
if (type != SOCK_STREAM)
{
set_errno (EOPNOTSUPP);
return -1;
}
*(int *) optval = tcp_fastopen ? 1 : 0;
*optlen = sizeof (int);
return 0;
}
break;
default:
break;
}
break;
default:
break;
}
@ -1869,6 +1907,10 @@ fhandler_socket_inet::getsockopt (int level, int optname, const void *optval,
onebyte = true;
break;
case TCP_FASTOPEN:
onebyte = true;
break;
default:
break;
}
@ -1881,8 +1923,7 @@ fhandler_socket_inet::getsockopt (int level, int optname, const void *optval,
/* Regression in Vista and later: instead of a 4 byte BOOL value, a
1 byte BOOLEAN value is returned, in contrast to older systems and
the documentation. Since an int type is expected by the calling
application, we convert the result here. For some reason only three
BSD-compatible socket options seem to be affected. */
application, we convert the result here. */
BOOLEAN *in = (BOOLEAN *) optval;
int *out = (int *) optval;
*out = *in;

View File

@ -125,5 +125,6 @@ struct tcphdr {
*/
#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */
#define TCP_MAXSEG 0x04 /* get maximum segment size (r/o on windows) */
#define TCP_FASTOPEN 0x0f /* enable FastOpen on listeners */
#endif

View File

@ -46,6 +46,7 @@ wincaps wincap_vista __attribute__((section (".cygwin_dll_common"), shared)) = {
has_con_broken_il_dl:false,
has_con_esc_rep:false,
has_extended_mem_api:false,
has_tcp_fastopen:false,
},
};
@ -77,6 +78,7 @@ wincaps wincap_7 __attribute__((section (".cygwin_dll_common"), shared)) = {
has_con_broken_il_dl:false,
has_con_esc_rep:false,
has_extended_mem_api:false,
has_tcp_fastopen:false,
},
};
@ -108,6 +110,7 @@ wincaps wincap_8 __attribute__((section (".cygwin_dll_common"), shared)) = {
has_con_broken_il_dl:false,
has_con_esc_rep:false,
has_extended_mem_api:false,
has_tcp_fastopen:false,
},
};
@ -139,6 +142,7 @@ wincaps wincap_8_1 __attribute__((section (".cygwin_dll_common"), shared)) = {
has_con_broken_il_dl:false,
has_con_esc_rep:false,
has_extended_mem_api:false,
has_tcp_fastopen:false,
},
};
@ -170,6 +174,39 @@ wincaps wincap_10_1507 __attribute__((section (".cygwin_dll_common"), shared))
has_con_broken_il_dl:false,
has_con_esc_rep:false,
has_extended_mem_api:false,
has_tcp_fastopen:false,
},
};
wincaps wincap_10_1607 __attribute__((section (".cygwin_dll_common"), shared)) = {
def_guard_pages:2,
mmap_storage_high:0x700000000000LL,
{
is_server:false,
needs_count_in_si_lpres2:false,
needs_query_information:false,
has_gaa_largeaddress_bug:false,
has_broken_alloc_console:true,
has_console_logon_sid:true,
has_precise_system_time:true,
has_microsoft_accounts:true,
has_processor_groups:true,
has_broken_prefetchvm:true,
has_new_pebteb_region:false,
has_broken_whoami:false,
has_unprivileged_createsymlink:false,
has_unbiased_interrupt_time:true,
has_precise_interrupt_time:true,
has_posix_unlink_semantics:false,
has_case_sensitive_dirs:false,
has_posix_rename_semantics:false,
no_msv1_0_s4u_logon_in_wow64:false,
has_con_24bit_colors:false,
has_con_broken_csi3j:false,
has_con_broken_il_dl:false,
has_con_esc_rep:false,
has_extended_mem_api:false,
has_tcp_fastopen:true,
},
};
@ -201,6 +238,7 @@ wincaps wincap_10_1703 __attribute__((section (".cygwin_dll_common"), shared)) =
has_con_broken_il_dl:false,
has_con_esc_rep:false,
has_extended_mem_api:false,
has_tcp_fastopen:true,
},
};
@ -232,6 +270,7 @@ wincaps wincap_10_1709 __attribute__((section (".cygwin_dll_common"), shared)) =
has_con_broken_il_dl:false,
has_con_esc_rep:false,
has_extended_mem_api:false,
has_tcp_fastopen:true,
},
};
@ -263,6 +302,7 @@ wincaps wincap_10_1803 __attribute__((section (".cygwin_dll_common"), shared)) =
has_con_broken_il_dl:false,
has_con_esc_rep:false,
has_extended_mem_api:true,
has_tcp_fastopen:true,
},
};
@ -294,6 +334,7 @@ wincaps wincap_10_1809 __attribute__((section (".cygwin_dll_common"), shared)) =
has_con_broken_il_dl:false,
has_con_esc_rep:false,
has_extended_mem_api:true,
has_tcp_fastopen:true,
},
};
@ -325,6 +366,7 @@ wincaps wincap_10_1903 __attribute__((section (".cygwin_dll_common"), shared)) =
has_con_broken_il_dl:true,
has_con_esc_rep:true,
has_extended_mem_api:true,
has_tcp_fastopen:true,
},
};
@ -378,6 +420,8 @@ wincapc::init ()
caps = &wincap_10_1709;
else if (version.dwBuildNumber >= 15063)
caps = &wincap_10_1703;
else if (version.dwBuildNumber >= 14393)
caps = &wincap_10_1607;
else
caps = & wincap_10_1507;
}

View File

@ -40,6 +40,7 @@ struct wincaps
unsigned has_con_broken_il_dl : 1;
unsigned has_con_esc_rep : 1;
unsigned has_extended_mem_api : 1;
unsigned has_tcp_fastopen : 1;
};
};
@ -103,6 +104,7 @@ public:
bool IMPLEMENT (has_con_broken_il_dl)
bool IMPLEMENT (has_con_esc_rep)
bool IMPLEMENT (has_extended_mem_api)
bool IMPLEMENT (has_tcp_fastopen)
void disable_case_sensitive_dirs ()
{