1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

net: allow more fine grained control over socket shutdowns

This commit is contained in:
Delyan Angelov
2023-01-25 12:32:05 +02:00
parent b34c55ffd6
commit d2e5c721a0
7 changed files with 49 additions and 33 deletions

View File

@@ -3,23 +3,23 @@ module unix
import time
import net
const (
error_ewouldblock = C.EWOULDBLOCK
)
const error_ewouldblock = C.EWOULDBLOCK
fn C.SUN_LEN(ptr &C.sockaddr_un) int
fn C.strncpy(&char, &char, int)
// Shutdown shutsdown a socket and closes it
fn shutdown(handle int) ! {
$if windows {
C.shutdown(handle, C.SD_BOTH)
net.socket_error(C.closesocket(handle))!
} $else {
C.shutdown(handle, C.SHUT_RDWR)
net.socket_error(C.close(handle))!
}
// shutdown shutsdown a socket, given its file descriptor `handle`.
// By default it shuts it down in both directions, both for reading
// and for writing. You can change that using `net.shutdown(handle, how: .read)`
// or `net.shutdown(handle, how: .write)`
pub fn shutdown(handle int, config net.ShutdownConfig) int {
return net.shutdown(handle, config)
}
// close a socket, given its file descriptor `handle`.
pub fn close(handle int) ! {
net.close(handle)!
}
// Select waits for an io operation (specified by parameter `test`) to be available

View File

@@ -49,7 +49,8 @@ fn new_stream_socket() !StreamSocket {
}
fn (mut s StreamSocket) close() ! {
return shutdown(s.handle)
shutdown(s.handle)
return close(s.handle)
}
fn (mut s StreamSocket) @select(test Select, timeout time.Duration) !bool {