Time out SSL request?

M

Michael Capone

Hi folks,

I'm using perl (actually, mod_perl environment on RH 8.0) to connect
to an external SSL server. I feed it an XML request and get a
response back. The problem is, the server is flaky, and I'd like to
be able to timeout / break if I haven't gotten a response in X
seconds. (Note that the server may connect, but simply not send a
response, i.e., it's too busy.)

I don't really understand filehandles and setting timeouts in unix /
perl as much as I should. The code below was lifted from the
Net::SSLeay readme and worked, and I never questioned it further.

Could someone show me how to modify the code below to add my timeout?
Note that I'm also completely open to other methods of connecting to
an SSL server; the Net::SSLeay method seemed to be the quickest to
implement, and I have no idea if there's a better way out there.

Thanks!

Michael

#!/usr/local/bin/perl -w

use strict;
use Net::SSLeay::Handle qw/shutdown/;

my ($request, $response) ;

local *F;
my $FH = *F;

$request = <<ENDXML;
<?xml version="1.0"?>
<Request>
<UserId>user1</UserId>
<Password>pass1</Password>
</Request>
ENDXML

my ($host, $port) = ("www.some.server", 443);
tie(*SSL, "Net::SSLeay::Handle", $host, $port);

print SSL "POST /xmlapps/blah HTTP/1.0\n";
print SSL "Content-type: application/x-www-form-urlencoded\n";
print SSL "Content-length: " . length($request) . "\n\n";
print SSL $request;

shutdown(\*SSL, 1);

$response .= $_ while (<SSL>);
close SSL;
print $response;
 
K

ko

Hi folks,

I'm using perl (actually, mod_perl environment on RH 8.0) to connect
to an external SSL server. I feed it an XML request and get a
response back. The problem is, the server is flaky, and I'd like to
be able to timeout / break if I haven't gotten a response in X
seconds. (Note that the server may connect, but simply not send a
response, i.e., it's too busy.)

I don't really understand filehandles and setting timeouts in unix /
perl as much as I should. The code below was lifted from the
Net::SSLeay readme and worked, and I never questioned it further.

Could someone show me how to modify the code below to add my timeout?
Note that I'm also completely open to other methods of connecting to
an SSL server; the Net::SSLeay method seemed to be the quickest to
implement, and I have no idea if there's a better way out there.

Thanks!

Michael

[snip code]

perldoc -f alarm
perldoc -f eval

You can pretty much cut/paste from the alarm() example.

HTH - keith


Th
 
M

Michael Capone

(e-mail address removed) (ko) wrote in message
perldoc -f alarm
perldoc -f eval

You can pretty much cut/paste from the alarm() example.

HTH - keith


Th

You're absolutely right. The code in 'perldoc -f alarm' worked out
perfectly for me. Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top