]> git.proxmox.com Git - pve-common.git/commitdiff
avoid unnecessarry delay by using usleep
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 9 Dec 2013 12:15:07 +0000 (13:15 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 9 Dec 2013 12:16:05 +0000 (13:16 +0100)
data/PVE/Tools.pm

index 922c0e6685d6773ff9210428bde34b4931069b83..f399d77dbb4541116bb4ea68adf112cc6e46c79d 100644 (file)
@@ -17,6 +17,7 @@ use Encode;
 use Digest::SHA;
 use Text::ParseWords;
 use String::ShellQuote;
 use Digest::SHA;
 use Text::ParseWords;
 use String::ShellQuote;
+use Time::HiRes qw(usleep gettimeofday tv_interval);
 
 our @EXPORT_OK = qw(
 $IPV6RE
 
 our @EXPORT_OK = qw(
 $IPV6RE
@@ -627,13 +628,16 @@ sub extract_param {
     return $res;
 }
 
     return $res;
 }
 
-# Note: we use this to wait until vncterm is ready
+# Note: we use this to wait until vncterm/spiceterm is ready
 sub wait_for_vnc_port {
     my ($port, $timeout) = @_;
 
     $timeout = 5 if !$timeout;
 sub wait_for_vnc_port {
     my ($port, $timeout) = @_;
 
     $timeout = 5 if !$timeout;
+    my $sleeptime = 0;
+    my $starttime = [gettimeofday];
+    my $elapsed;
 
 
-    for (my $i = 0; $i < $timeout; $i++) {
+    while (($elapsed = tv_interval($starttime)) < $timeout) {
        if (my $fh = IO::File->new ("/proc/net/tcp", "r")) {
            while (defined (my $line = <$fh>)) {
                if ($line =~ m/^\s*\d+:\s+([0-9A-Fa-f]{8}):([0-9A-Fa-f]{4})\s/) {
        if (my $fh = IO::File->new ("/proc/net/tcp", "r")) {
            while (defined (my $line = <$fh>)) {
                if ($line =~ m/^\s*\d+:\s+([0-9A-Fa-f]{8}):([0-9A-Fa-f]{4})\s/) {
@@ -645,7 +649,8 @@ sub wait_for_vnc_port {
            }
            close($fh);
        }
            }
            close($fh);
        }
-       sleep(1);
+       $sleeptime += 100000 if  $sleeptime < 1000000;
+       usleep($sleeptime);
     }
 
     return undef;
     }
 
     return undef;