mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
picoev, x.vweb: small fixes and backport changes from vweb (#20584)
This commit is contained in:
parent
2874e7cac0
commit
d88ca11a4c
18 changed files with 319 additions and 129 deletions
|
@ -99,7 +99,7 @@ fn fatal_socket_error(fd int) bool {
|
|||
}
|
||||
|
||||
// listen creates a listening tcp socket and returns its file descriptor
|
||||
fn listen(config Config) int {
|
||||
fn listen(config Config) !int {
|
||||
// not using the `net` modules sockets, because not all socket options are defined
|
||||
fd := C.socket(config.family, net.SocketType.tcp, 0)
|
||||
assert fd != -1
|
||||
|
@ -110,16 +110,23 @@ fn listen(config Config) int {
|
|||
|
||||
// Setting flags for socket
|
||||
flag := 1
|
||||
assert C.setsockopt(fd, C.SOL_SOCKET, C.SO_REUSEADDR, &flag, sizeof(int)) == 0
|
||||
flag_zero := 0
|
||||
net.socket_error(C.setsockopt(fd, C.SOL_SOCKET, C.SO_REUSEADDR, &flag, sizeof(int)))!
|
||||
|
||||
if config.family == .ip6 {
|
||||
// set socket to dualstack so connections to both ipv4 and ipv6 addresses
|
||||
// can be accepted
|
||||
net.socket_error(C.setsockopt(fd, C.IPPROTO_IPV6, C.IPV6_V6ONLY, &flag_zero, sizeof(int)))!
|
||||
}
|
||||
|
||||
$if linux {
|
||||
// epoll socket options
|
||||
assert C.setsockopt(fd, C.SOL_SOCKET, C.SO_REUSEPORT, &flag, sizeof(int)) == 0
|
||||
assert C.setsockopt(fd, C.IPPROTO_TCP, C.TCP_QUICKACK, &flag, sizeof(int)) == 0
|
||||
assert C.setsockopt(fd, C.IPPROTO_TCP, C.TCP_DEFER_ACCEPT, &config.timeout_secs,
|
||||
sizeof(int)) == 0
|
||||
net.socket_error(C.setsockopt(fd, C.SOL_SOCKET, C.SO_REUSEPORT, &flag, sizeof(int)))!
|
||||
net.socket_error(C.setsockopt(fd, C.IPPROTO_TCP, C.TCP_QUICKACK, &flag, sizeof(int)))!
|
||||
net.socket_error(C.setsockopt(fd, C.IPPROTO_TCP, C.TCP_DEFER_ACCEPT, &config.timeout_secs,
|
||||
sizeof(int)))!
|
||||
queue_len := max_queue
|
||||
assert C.setsockopt(fd, C.IPPROTO_TCP, C.TCP_FASTOPEN, &queue_len, sizeof(int)) == 0
|
||||
net.socket_error(C.setsockopt(fd, C.IPPROTO_TCP, C.TCP_FASTOPEN, &queue_len, sizeof(int)))!
|
||||
}
|
||||
|
||||
// addr settings
|
||||
|
@ -128,12 +135,8 @@ fn listen(config Config) int {
|
|||
addr := addrs[0]
|
||||
alen := addr.len()
|
||||
|
||||
net.socket_error_message(C.bind(fd, voidptr(&addr), alen), 'binding to ${saddr} failed') or {
|
||||
panic(err)
|
||||
}
|
||||
net.socket_error_message(C.listen(fd, C.SOMAXCONN), 'listening on ${saddr} with maximum backlog pending queue of ${C.SOMAXCONN}, failed') or {
|
||||
panic(err)
|
||||
}
|
||||
net.socket_error_message(C.bind(fd, voidptr(&addr), alen), 'binding to ${saddr} failed')!
|
||||
net.socket_error_message(C.listen(fd, C.SOMAXCONN), 'listening on ${saddr} with maximum backlog pending queue of ${C.SOMAXCONN}, failed')!
|
||||
|
||||
setup_sock(fd) or {
|
||||
config.err_cb(config.user_data, picohttpparser.Request{}, mut &picohttpparser.Response{},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue