mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
net: add more SocketOptions enum values, make public fn new_tcp_socket (#22378)
This commit is contained in:
parent
d1fdcfbab4
commit
e598db12d3
2 changed files with 7 additions and 2 deletions
|
@ -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]
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue