Skip to content

Commit

Permalink
transpile code to Lua
Browse files Browse the repository at this point in the history
  • Loading branch information
HereAdvertise authored Jul 13, 2024
1 parent 1726fe4 commit b202e78
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pgmoon/redbean.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ do
receive = function(self, pattern)
local CANREAD = unix.POLLIN | unix.POLLRDNORM | unix.POLLRDBAND
local size = tonumber(pattern)
local buf = ""
if size then
local events = assert(unix.poll({
[self.unix_socket] = unix.POLLIN
Expand All @@ -56,9 +57,16 @@ do
if events[self.unix_socket] & CANREAD == 0 then
return nil, "close"
end
return unix.recv(self.unix_socket, size)
while #buf < size do
local rec = unix.recv(self.unix_socket, size - #buf)
if #rec == 0 then
break
else
buf = buf .. rec
end
end
end
return ""
return buf
end,
close = function(self)
return assert(unix.close(self.unix_socket))
Expand Down

0 comments on commit b202e78

Please sign in to comment.