Skip to content

Commit

Permalink
revert last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
HereAdvertise authored Jul 10, 2024
1 parent 11473d7 commit ff83ce7
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions pgmoon/redbean.moon
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,26 @@ class RedbeanSocket
sent, err

receive: (...) =>
pattern = flatten ...
buf = ""
@buf = "" unless @buf

CANREAD = unix.POLLIN | unix.POLLRDNORM | unix.POLLRDBAND
size = tonumber pattern
size = ...
if size
events = assert unix.poll @unix_socket: unix.POLLIN
return nil, "timeout" unless events[@unix_socket]
return nil, "close" if events[@unix_socket] & CANREAD == 0
if size > 81920
size = 81920
rec = unix.recv @unix_socket, size
if rec
buf = rec
else
collectgarbage!
buf = assert unix.recv @unix_socket, size
return buf

while not buf\find "\n"
rec = unix.recv @unix_socket, 4096
if rec
buf ..= rec
else
collectgarbage!
buf ..= assert unix.recv @unix_socket, 4096
if #@buf < size
events = assert unix.poll @unix_socket: unix.POLLIN
return nil, "timeout" unless events[@unix_socket]
return nil, "close" if events[@unix_socket] & CANREAD == 0
@buf = @buf .. assert unix.recv @unix_socket, size-#@buf
res = @buf\sub 1, size
@buf = @buf\sub size+1
return res

while not @buf\find "\n"
@buf = @buf .. assert unix.recv @unix_socket, 4096

pos = buf\find "\n"
res = buf\sub(1, pos-1)\gsub "\r", ""
pos = @buf\find "\n"
res = @buf\sub(1, pos-1)\gsub "\r", ""
@buf = @buf\sub pos+1
res

close: =>
Expand Down

0 comments on commit ff83ce7

Please sign in to comment.