Murga-Projects Forums

Full Version: socket.http bug or aminotdoinitrite?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In the LuaSocket docs:

Code:
-- tries to connect to server "wrong.host" to retrieve "/"
-- and fails because the host does not exist.
r, e = http.request("http://wrong.host/")
-- r is nil, and e returns with value "host not found"

When I try this it does more than fail...it takes murgaLua down with it. Wondering if this is expected behaviour, because it seems like this is a pretty harsh way to handle it.

Code:
/home/deb/bin/murgaLua: No route to host
stack traceback:
        [C]: in function 'request'
        /home/deb/bin/media.lua:28: in main chunk
        [C]: ?

I think I found a solution of some kind, by testing the server first, and then the files on it

Code:
host="somehostname"
-- check is server is available
testy=socket.protect(function()
  local c = socket.connect(host, 80)
  if not c then fltk.fl_alert("server not found!"); os.exit()
  else c:close() end
end)
testy()

host="http://"..host.."/media"
-- check if the media dir is available
local b,c=socket.http.request(host)
if c~=200 then fltk.fl_alert("media not available"); os.exit() end

That's weird. Executing the same code as you gives me this:

Code:
> r, e = socket.http.request("http://wrong.host/")
host not found
stack traceback:
    [C]: in function 'request'
    stdin:1: in main chunk
    [C]: ?
>


And it doesn't take down murgaLua, just the error. But indeed, normally r should be nil and e should be the error message, and no error should be thrown automagically.

Edit:
I looked at this a bit further, and found out that it does work as expected in a plain Lua with the LuaRocks version of LuaSocket.
Apparently the only difference in the luasocket code between murgaLua and what I got from LuaRocks is this:

Code:
diff .//usocket.c /home/jpjacobs/software/murgaLua/3rd-party/luasocket-2.0.2-MOD/src//usocket.c
349c349
<         default: return hstrerror(err);
---
>         default: return strerror(err);

But this shouldn't matter because usocket isn't even being included in murgaLua, is it? So I think the problem must lie somewhere in the binding / build process...

Greetings,
JP

jpjacobs Wrote:
That's weird. Executing the same code as you gives me this:

Code:
> r, e = socket.http.request("http://wrong.host/")
host not found
stack traceback:
    [C]: in function 'request'
    stdin:1: in main chunk
    [C]: ?
>


And it doesn't take down murgaLua, just the error. But indeed, normally r should be nil and e should be the error message, and no error should be thrown automagically.

Edit:
I looked at this a bit further, and found out that it does work as expected in a plain Lua with the LuaRocks version of LuaSocket.
Apparently the only difference in the luasocket code between murgaLua and what I got from LuaRocks is this:

Code:
diff .//usocket.c /home/jpjacobs/software/murgaLua/3rd-party/luasocket-2.0.2-MOD/src//usocket.c
349c349
<         default: return hstrerror(err);
---
>         default: return strerror(err);

But this shouldn't matter because usocket isn't even being included in murgaLua, is it? So I think the problem must lie somewhere in the binding / build process...

Greetings,
JP


I will look into this

Reference URL's