Skip to content

Commit

Permalink
kernel: unix socket: Support nonblocking writes
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsuki committed Jan 11, 2024
1 parent 601fceb commit 53bcdb8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions kernel/modules/socket/unix/unix.v
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn (mut this UnixSocket) read(_handle voidptr, buf voidptr, loc u64, _count u64)
return i64(count)
}

fn (mut this UnixSocket) write(handle voidptr, buf voidptr, loc u64, _count u64) ?i64 {
fn (mut this UnixSocket) write(_handle voidptr, buf voidptr, loc u64, _count u64) ?i64 {
mut count := _count

mut peer := this.peer
Expand All @@ -129,9 +129,15 @@ fn (mut this UnixSocket) write(handle voidptr, buf voidptr, loc u64, _count u64)
peer.l.release()
}

handle := unsafe { &file.Handle(_handle) }

// If pipe is full, block or return if nonblock
for katomic.load(peer.used) == peer.capacity {
// We don't do nonblock yet
if handle.flags & resource.o_nonblock != 0 {
errno.set(errno.ewouldblock)
return none
}

peer.l.release()
mut events := [&peer.event]
event.await(mut events, true) or {
Expand Down

0 comments on commit 53bcdb8

Please sign in to comment.