News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
socket.http bug or aminotdoinitrite?
Author Message
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #1
socket.http bug or aminotdoinitrite?

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

12-28-2010 01:14 PM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #2
RE: socket.http bug or aminotdoinitrite?

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

This post was last modified: 12-28-2010 02:09 PM by mikshaw.

12-28-2010 02:07 PM
Find all posts by this user Quote this message in a reply
jpjacobs
Member
***


Posts: 113
Group: Registered
Joined: Jul 2007
Status: Offline
Reputation: 0
Post: #3
RE: socket.http bug or aminotdoinitrite?

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

This post was last modified: 12-28-2010 10:34 PM by jpjacobs.

12-28-2010 10:18 PM
Find all posts by this user Quote this message in a reply
JohnMurga
Administrator
*******


Posts: 381
Group: Administrators
Joined: Apr 2007
Status: Offline
Reputation: 2
Post: #4
RE: socket.http bug or aminotdoinitrite?

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

01-14-2011 01:00 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: