net: add more SocketOptions enum values, make public fn new_tcp_socket (#22378)

This commit is contained in:
Carlos Esquerdo Bernat 2024-10-01 10:42:30 +02:00 committed by GitHub
parent d1fdcfbab4
commit e598db12d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View file

@ -19,6 +19,11 @@ pub enum SocketOption {
send_timeout = C.SO_SNDTIMEO
socket_type = C.SO_TYPE
ipv6_only = C.IPV6_V6ONLY
ip_proto_ipv6 = C.IPPROTO_IPV6
// reuse_port = C.SO_REUSEPORT // TODO make it work in windows
// tcp_fastopen = C.TCP_FASTOPEN // TODO make it work in windows
// tcp_quickack = C.TCP_QUICKACK // TODO make it work in os != linux
// tcp_defer_accept = C.TCP_DEFER_ACCEPT // TODO make it work in windows
}
pub const opts_bool = [SocketOption.broadcast, .debug, .dont_route, .error, .keep_alive, .oob_inline]

View file

@ -355,7 +355,7 @@ pub:
}
pub fn listen_tcp(family AddrFamily, saddr string, options ListenOptions) !&TcpListener {
if family != .ip && family != .ip6 {
if family !in [.ip, .ip6] {
return error('listen_tcp only supports ip and ip6')
}
mut s := new_tcp_socket(family) or { return error('${err.msg()}; could not create new socket') }
@ -515,7 +515,7 @@ struct TcpSocket {
// This is a workaround for issue https://github.com/vlang/v/issues/20858
// `noline` ensure that in `-prod` mode(CFLAG = `-O3 -flto`), gcc does not generate wrong instruction sequence
@[noinline]
fn new_tcp_socket(family AddrFamily) !TcpSocket {
pub fn new_tcp_socket(family AddrFamily) !TcpSocket {
handle := $if is_coroutine ? {
socket_error(C.photon_socket(family, SocketType.tcp, 0))!
} $else {