Timeout for get-url?

Q&A's, tips, howto's
Locked
methodic
Posts: 58
Joined: Tue May 10, 2005 5:04 am

Timeout for get-url?

Post by methodic »

What is the default timeout for get-url if it doesn't recieve any data, and is there a way to specify a timeout?

Thanks.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

It depends on the socket stack of your OS. Perhaps some kernel setting?

Lutz

methodic
Posts: 58
Joined: Tue May 10, 2005 5:04 am

Post by methodic »

Is there a way to set a time-out, as you would on a regular socket? Or would I have to actually roll my own URL grabbing code?

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

In any case you would have to change kernel settings to control this timeout. The system waits in a socket library connect() call. I am not aware of a method to control a timeout of that function call from 'C'. This is different from already connected sockets where you can specify a timeout using select(). So rolling your 'own' get-url won't help you.


Lutz

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

On BSD/LINUX you could do a:

Code: Select all

sysctl -a
to find out if a timeout settings is available, and then try to change the setting.

Lutz

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

This is an annoying problem indeed, I suffer from this with my RSS reader as well. Hmm... maybe we can work around it as mentioned previously in another discussion:

Code: Select all

(set 'result (exec "ping -c 1 www.newlisp.org "))
(if (> (length result) 0)
  (get-url "www.newlisp.org")
  (println "website not available"))

The '-c 1' option pings only once.

-Peter

methodic
Posts: 58
Joined: Tue May 10, 2005 5:04 am

Post by methodic »

That's definitely one way to get around it, although what if the box is panic'd and it still replies to pings, but the kernel itself is hung? I've seen that happen before.

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

Well, that cannot be solved within newLisp. So you need external tools for this.

Suppose a 'ping' delivers a result, then you must know if port 80 is alive (assuming the webserver is running on this port). The only way I see is using 'nmap' for that:

Code: Select all

nmap -p 80 <remote-host>
For example:
peter@Solarstriker:~/programming/newlisp$ nmap -p 80 www.newlisp.org

Starting nmap 3.50 ( http://www.insecure.org/nmap/ ) at 2005-08-13 01:19 CEST
Interesting ports on ds209-72.ipowerweb.com (66.235.209.72):
PORT STATE SERVICE
80/tcp open http

Nmap run completed -- 1 IP address (1 host up) scanned in 0.957 seconds
The result can be parsed in newLisp, same as with the 'ping', so you can find out if the port is really alive.

Even then the remote webserver may be malfunctioning, but there is nothing more you can do - at least, I don't know any other tricks here. :-(


-Peter

methodic
Posts: 58
Joined: Tue May 10, 2005 5:04 am

Post by methodic »

nmap was a tool that came to mind, unfortunately i am running this code off an appliance of sorts, where we dont have the room to put nmap on it.

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

Our network guru Norman has created a portscanner with newLisp:

http://www.nodep.nl/downloads/newlisp/portscan.lsp

I am not sure how well it works, but you can give it a try.

-Peter

Locked