mirror of
https://github.com/imapsync/imapsync.git
synced 2025-07-25 03:28:16 +02:00
1.350
This commit is contained in:
parent
34c3add845
commit
804a713af1
17 changed files with 462 additions and 235 deletions
48
learn/io_socket_get
Normal file
48
learn/io_socket_get
Normal file
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
use IO::Socket;
|
||||
|
||||
sub last_release {
|
||||
my $sock = new IO::Socket::INET (
|
||||
PeerAddr => 'linux-france.org',
|
||||
PeerPort => '80',
|
||||
Proto => 'tcp');
|
||||
return('unknown') if not $sock;
|
||||
print $sock
|
||||
"GET /prj/imapsync/VERSION HTTP/1.0\n",
|
||||
"Host: www.linux-france.org\n\n";
|
||||
my @line = <$sock>;
|
||||
close($sock);
|
||||
my $last_release = $line[-1];
|
||||
chomp($last_release);
|
||||
return($last_release);
|
||||
}
|
||||
|
||||
sub not_long {
|
||||
|
||||
my ($func) = @_;
|
||||
my $val;
|
||||
eval {
|
||||
local $SIG{ALRM} = sub { die "alarm\n" };
|
||||
alarm 3;
|
||||
#print $func, "\n";
|
||||
{
|
||||
no strict "refs";
|
||||
$val = &$func();
|
||||
}
|
||||
alarm 0;
|
||||
};
|
||||
if ($@) {
|
||||
# timed out
|
||||
return('unknown') unless $@ eq "alarm\n"; # propagate unexpected errors
|
||||
|
||||
}else {
|
||||
# didn't
|
||||
return($val);
|
||||
}
|
||||
}
|
||||
|
||||
print last_release(), "\n";
|
||||
print not_long('last_release'), "\n";
|
Loading…
Add table
Add a link
Reference in a new issue