Skip to content

Commit

Permalink
parse redbean
Browse files Browse the repository at this point in the history
  • Loading branch information
HereAdvertise authored Jul 9, 2024
1 parent 6e07ed1 commit f7c7ed6
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pgmoon/redbean.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,26 @@ do
if events[self.unix_socket] & CANREAD == 0 then
return nil, "close"
end
self.buf = self.buf .. assert(unix.recv(self.unix_socket, size - #self.buf))
local rec = unix.recv(self.unix_socket, size - #self.buf)
if rec then
self.buf = self.buf .. rec
else
collectgarbage()
self.buf = self.buf .. assert(unix.recv(self.unix_socket, 4096))
end
end
local res = self.buf:sub(1, size)
self.buf = self.buf:sub(size + 1)
return res
end
while not self.buf:find("\n") do
self.buf = self.buf .. assert(unix.recv(self.unix_socket, 4096))
local rec = unix.recv(self.unix_socket, 4096)
if rec then
self.buf = self.buf .. rec
else
collectgarbage()
self.buf = self.buf .. assert(unix.recv(self.unix_socket, 4096))
end
end
local pos = self.buf:find("\n")
local res = self.buf:sub(1, pos - 1):gsub("\r", "")
Expand Down Expand Up @@ -114,4 +126,4 @@ do
end
return {
RedbeanSocket = RedbeanSocket
}
}

0 comments on commit f7c7ed6

Please sign in to comment.