From 6e07ed1935ea837c1e5343ce9ffc30951bd2af01 Mon Sep 17 00:00:00 2001 From: HereAdvertise <162376972+HereAdvertise@users.noreply.github.com> Date: Tue, 9 Jul 2024 01:56:12 -0300 Subject: [PATCH] add collectgarbage --- pgmoon/redbean.moon | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/pgmoon/redbean.moon b/pgmoon/redbean.moon index 0ab4df9..41780ff 100644 --- a/pgmoon/redbean.moon +++ b/pgmoon/redbean.moon @@ -49,16 +49,26 @@ class RedbeanSocket 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 + rec = unix.recv @unix_socket, size-#@buf + if rec + @buf ..= rec + else + collectgarbage! + @buf ..= assert unix.recv @unix_socket, 4096 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 + rec = unix.recv @unix_socket, 4096 + if rec + @buf ..= rec + else + collectgarbage! + @buf ..= assert unix.recv @unix_socket, 4096 pos = @buf\find "\n" - res = @buf\sub(1, pos-1)\gsub("\r", "") + res = @buf\sub(1, pos-1)\gsub "\r", "" @buf = @buf\sub pos+1 res @@ -83,5 +93,3 @@ class RedbeanSocket error "You attempted to call setkeepalive on a Redbean socket. This method is only available for the ngx cosocket API for releasing a socket back into the connection pool" { :RedbeanSocket } - -