Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/net_ #22380

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions vlib/net/socket_options.c.v
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
module net

#include <errno.h>
$if windows {
#include <winsock2.h>
#include <ws2tcpip.h>
} $else $if freebsd || macos {
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
} $else {
#include <netinet/tcp.h>
#include <sys/resource.h>
}

pub enum SocketOption {
// TODO: SO_ACCEPT_CONN is not here because windows doesn't support it
// and there is no easy way to define it
Expand All @@ -19,6 +33,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
Loading