Skip to content

Commit

Permalink
update receive
Browse files Browse the repository at this point in the history
  • Loading branch information
HereAdvertise authored Jul 13, 2024
1 parent ab5c8b4 commit 1726fe4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pgmoon/redbean.moon
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ class RedbeanSocket
receive: (pattern) =>
CANREAD = unix.POLLIN | unix.POLLRDNORM | unix.POLLRDBAND
size = tonumber(pattern)
buf = ""
if size
events = assert unix.poll @unix_socket: unix.POLLIN, @timeout
return nil, "timeout" unless events[@unix_socket]
return nil, "close" if events[@unix_socket] & CANREAD == 0
return unix.recv @unix_socket, size
""
while #buf < size
rec = unix.recv @unix_socket, size - #buf
if #rec == 0
break
else
buf ..= rec
buf

close: =>
assert unix.close @unix_socket
Expand Down

0 comments on commit 1726fe4

Please sign in to comment.