473,383 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Imposing a timeout on the <> operator - is this possible?

Hi all

I have code that polls a number of machines on our network and
retrieves stats from each one.

This is done via HTTP

This morning the program hung. When I started investigating I found
that one of the remote machines was in some kind of strange state. You
could ping it. You coud connect to it (HTTP, Telnet, FTP) but you got
no response.

So my program opens up a socket, fires off the HTTP request and then
waits for a response from apache, and waits, and waits, and waits...

The relevant portion of the code looks like this...

# open a socket...
$socket = IO::Socket::INET->new(PeerAddr => $netaddr,
PeerPort => 80,
Proto => "tcp",
Timeout => 10)
or die "Couldn\'t open the socket!!!!";

# form the HTTP request
$request = "GET $url HTTP\/1.0\n\n";

# request the file...
print $socket $request;

# process the output and strip out the response headers
$printit = 0;
# ...now read the socket and process the output
while($line = <$socket>){

# do some stuff with $line
}

The program hangs at the <> operator.

OK... a wierd situation and not a common one, but I want to improve
the code. Specificially when I invoke <> I'd like to be able to impose
a time out so that if I get nothing back after n seconds I can raise
an error condition and start interrogating the next site.

TIA

Bob Dubery
Jul 19 '05 #1
1 2208
JSM
me******@hotmail.com (Bob Dubery) wrote in message news:<e8**************************@posting.google. com>...
OK... a wierd situation and not a common one, but I want to improve
the code. Specificially when I invoke <> I'd like to be able to impose
a time out so that if I get nothing back after n seconds I can raise
an error condition and start interrogating the next site.


You can use alarm to do this. There is an example in the Perl Cookbook (16.21).
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: kyo | last post by:
class A { public: int a; }; struct testfun1 : public unary_function<const A&, bool> { bool operator()(const A &) const {
2
by: Eshrath | last post by:
Hi, What I am trying to do: ======================= I need to form a table in html using the xsl but the table that is formed is quite long and cannot be viewed in our application. So we are...
2
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script...
14
by: Dave | last post by:
Hello all, After perusing the Standard, I believe it is true to say that once you insert an element into a std::list<>, its location in memory never changes. This makes a std::list<> ideal for...
1
by: ±èÀçȲ | last post by:
//this code generates the error. uint a=1,b=2; Console.WriteLine(a << b); Console.WriteLine(a >> b); What problem does "uint type" have.?
2
by: brzozo2 | last post by:
Hello, this program might look abit long, but it's pretty simple and easy to follow. What it does is read from a file, outputs the contents to screen, and then writes them to a different file. It...
3
by: ajay2552 | last post by:
Hi, I have a query. All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it? One method is to use &lt,...
3
by: Peterwkc | last post by:
Hello all expert C++ programmer, i fairly new to C++ programming. I have a class cellphone which contain dynamic pointer. I have create (example)ten cellphone. I want to ask user for the...
14
by: urikaluzhny | last post by:
It seems that I rather frequently need a list or iterator of the form And there is no one like this. May be there is another short way to write it (not as a loop). Is there? Thanks
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.