Skip to content

Commit

Permalink
Updated luasocket components that use default receive() method to w…
Browse files Browse the repository at this point in the history
…ork with Lua 5.4.3.

Lua 5.4.3 throws `bad argument #1 to 'receive' (string expected, got light userdata)`
error when `receive()` method from luasocket is used without parameters.
The patch provides the default value, which eliminates the issue.
  • Loading branch information
pkulchenko committed Jun 17, 2021
1 parent 0a695ee commit 68dcfc8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lualibs/socket/http.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ local function receiveheaders(sock, headers)
local line, name, value, err
headers = headers or {}
-- get first line
line, err = sock:receive()
line, err = sock:receive("*l")
if err then return nil, err end
-- headers go until a blank line is found
while line ~= "" do
Expand All @@ -44,12 +44,12 @@ local function receiveheaders(sock, headers)
if not (name and value) then return nil, "malformed reponse headers" end
name = string.lower(name)
-- get next line (value might be folded)
line, err = sock:receive()
line, err = sock:receive("*l")
if err then return nil, err end
-- unfold any folded values
while string.find(line, "^%s") do
value = value .. line
line = sock:receive()
line = sock:receive("*l")
if err then return nil, err end
end
-- save pair in table
Expand All @@ -69,15 +69,15 @@ socket.sourcet["http-chunked"] = function(sock, headers)
}, {
__call = function()
-- get chunk size, skip extention
local line, err = sock:receive()
local line, err = sock:receive("*l")
if err then return nil, err end
local size = base.tonumber(string.gsub(line, ";.*", ""), 16)
if not size then return nil, "invalid chunk size" end
-- was it the last chunk?
if size > 0 then
-- if not, get chunk and skip terminating CRLF
local chunk, err, part = sock:receive(size)
if chunk then sock:receive() end
if chunk then sock:receive("*l") end
return chunk, err
else
-- if it was, read trailers into headers table
Expand Down
4 changes: 2 additions & 2 deletions lualibs/socket/tp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ _M.TIMEOUT = 60
-- gets server reply (works for SMTP and FTP)
local function get_reply(c)
local code, current, sep
local line, err = c:receive()
local line, err = c:receive("*l")
local reply = line
if err then return nil, err end
code, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)"))
if not code then return nil, "invalid server reply" end
if sep == "-" then -- reply is multiline
repeat
line, err = c:receive()
line, err = c:receive("*l")
if err then return nil, err end
current, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)"))
reply = reply .. "\n" .. line
Expand Down

0 comments on commit 68dcfc8

Please sign in to comment.