Murga-Projects Forums
socket.http bug or aminotdoinitrite? - Printable Version

+- Murga-Projects Forums (http://www.murga-projects.com/forum)
+-- Forum: Project Forums (/forumdisplay.php?fid=1)
+--- Forum: MurgaLua - General (/forumdisplay.php?fid=2)
+--- Thread: socket.http bug or aminotdoinitrite? (/showthread.php?tid=402)


socket.http bug or aminotdoinitrite? - mikshaw - 12-28-2010 01:14 PM

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]: ?




RE: socket.http bug or aminotdoinitrite? - mikshaw - 12-28-2010 02:07 PM

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




RE: socket.http bug or aminotdoinitrite? - jpjacobs - 12-28-2010 10:18 PM

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


RE: socket.http bug or aminotdoinitrite? - JohnMurga - 01-14-2011 01:00 AM

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