Changeset 1899afd for fedkit


Ignore:
Timestamp:
Feb 15, 2010 5:32:05 AM (14 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
3132419
Parents:
6d985c0
Message:

Add port waiting. Should be asynchronous now.

Location:
fedkit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • fedkit/active_config.pl

    r6d985c0 r1899afd  
    4444my $f = new IO::File($iface_file) || die "Can't open $iface_file: $!\n";
    4545my $ifnum = 0;
     46
     47print "Waiting for ssh on $peer\n";
     48gateway_lib::wait_for_port($peer, 22, 60*60) ||
     49    die "ssh never came up on $peer\n";
    4650
    4751while (<$f>) {
  • fedkit/gateway_lib.pm

    r6d985c0 r1899afd  
    1616use IO::File;
    1717use IO::Pipe;
     18use IO::Socket;
    1819
    1920use File::Temp;
     
    244245}
    245246
    246 # untested
    247247sub read_config {
    248248    my($file, $map) = @_;
     
    317317}
    318318
     319sub wait_for_port {
     320    my($addr, $port, $timeout, $sleep) = @_;
     321    my $start = time();
     322    $sleep = 5 unless $sleep;
     323    die "Need both address and port\n" unless $addr && $port;
     324
     325    my $s;
     326
     327    while (!$s) {
     328        if (!($s = new IO::Socket(Domain => &AF_INET, PeerAddr => $addr,
     329            PeerPort => $port))) {
     330            if ($timeout and time() - $start > $timeout) {
     331                return undef;
     332            }
     333            else { sleep($sleep); }
     334        }
     335    }
     336    $s->close();
     337    return 1;
     338
     339}
     340
     341
    3193421;
Note: See TracChangeset for help on using the changeset viewer.