mirror of
https://github.com/vlang/v.git
synced 2025-09-15 07:22:27 +03:00
net: fix non-blocking read/write (#20438)
This commit is contained in:
parent
410bd9db71
commit
a9ebab06da
9 changed files with 260 additions and 94 deletions
|
@ -9,3 +9,20 @@ pub:
|
|||
pub fn (s &Socket) address() !Addr {
|
||||
return addr_from_socket_handle(s.handle)
|
||||
}
|
||||
|
||||
// set_blocking will change the state of the socket to either blocking,
|
||||
// when state is true, or non blocking (false).
|
||||
pub fn set_blocking(handle int, state bool) ! {
|
||||
$if windows {
|
||||
t := if state { u32(0) } else { u32(1) }
|
||||
socket_error(C.ioctlsocket(handle, fionbio, &t))!
|
||||
} $else {
|
||||
mut flags := C.fcntl(handle, C.F_GETFL, 0)
|
||||
if state {
|
||||
flags &= ~C.O_NONBLOCK
|
||||
} else {
|
||||
flags |= C.O_NONBLOCK
|
||||
}
|
||||
socket_error(C.fcntl(handle, C.F_SETFL, flags))!
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue