login

<     >

2023-08-27 14:29:59 (UTC-03:00)

Marcel Rodrigues <marcelgmr@gmail.com>

tcp: datain must be indexed by file descriptors

the sockets can appear in different positions in the epoll set

diff --git a/lib/ludweb/tcp.lua b/lib/ludweb/tcp.lua
index 2634fb9..c3aa37a 100644
--- a/lib/ludweb/tcp.lua
+++ b/lib/ludweb/tcp.lua
@@ -142,9 +142,10 @@ function TCP:run()
                         can_close = true
                         break
                     else
-                        datain[n] = (datain[n] or "") .. ffi.string(buffer, size)
-                        if self:request_ready(datain[n]) then
-                            local dataout, keep_alive = self:process(datain[n])
+                        datain[readyfd] = (datain[readyfd] or "") .. ffi.string(buffer, size)
+                        if self:request_ready(datain[readyfd]) then
+                            local dataout, keep_alive = self:process(datain[readyfd])
+                            datain[readyfd] = ""
                             if dataout == nil then
                                 running = false
                             else
@@ -153,7 +154,6 @@ function TCP:run()
                             if not keep_alive then
                                 can_close = true
                             end
-                            datain[n] = ""
                         end
                     end
                 end