Skip to content

Commit

Permalink
net: add more SocketOptions enum values, make public fn new_tcp_socket (
Browse files Browse the repository at this point in the history
  • Loading branch information
esquerbatua authored Oct 1, 2024
1 parent d1fdcfb commit e598db1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions vlib/net/socket_options.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions vlib/net/tcp.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -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') }
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e598db1

Please sign in to comment.