From: <buc...@us...> - 2011-01-25 13:54:42
|
Revision: 214 http://devmon.svn.sourceforge.net/devmon/?rev=214&view=rev Author: buchanmilne Date: 2011-01-25 13:54:36 +0000 (Tue, 25 Jan 2011) Log Message: ----------- Wrap all socket comms to Hobbit/BB when sending status messages in eval/alarm blocks Add more debug logging when sending messages Modified Paths: -------------- trunk/modules/dm_msg.pm Modified: trunk/modules/dm_msg.pm =================================================================== --- trunk/modules/dm_msg.pm 2011-01-25 12:05:18 UTC (rev 213) +++ trunk/modules/dm_msg.pm 2011-01-25 13:54:36 UTC (rev 214) @@ -53,6 +53,7 @@ return; } + do_log("DEBUG: Looping through messages for this socket",3) if $g{'debug'}; # Run until we are out of messages to send SOCKLOOP: while(@{$g{'test_results'}}) { @@ -60,20 +61,44 @@ select undef, undef, undef, $g{'msgsleep'} / 1000; # Open our socket to the host - socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp')) - or do_log("Failed to create socket ($!)",0) and - $g{'msgxfrtime'} = time - $g{'msgxfrtime'} and return; - if (!connect(SOCK, $p_addr)) { - do_log("Can't connect to display server $host ($!)",0); - $g{'msgxfrtime'} = time - $g{'msgxfrtime'}; - close SOCK; - return; + do_log("DEBUG: Opening socket to $host:$g{'dispport'}",3) if $g{'debug'}; + eval { + local $SIG{ALRM} = sub { die "Socket timed out" }; + alarm 10; + socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp')) + or do_log("Failed to create socket ($!)",0) and + $g{'msgxfrtime'} = time - $g{'msgxfrtime'} and return; + alarm 0; + local $SIG{ALRM} = sub { die "Connect timed out" }; + alarm 10; + if (!connect(SOCK, $p_addr)) { + do_log("Can't connect to display server $host ($!)",0); + $g{'msgxfrtime'} = time - $g{'msgxfrtime'}; + close SOCK; + return; + } + alarm 0; + }; + if ($@) { + do_log("Timed out connecting to display server: $!",0); + return; } # Tell the display server that we are sending a combo msg - print SOCK "combo\n"; + eval { + local $SIG{ALRM} = sub { die "Print timed out" }; + alarm 10; + print SOCK "combo\n"; + alarm 0; + }; + if ($@) { + do_log("Timed out printing to display server: $!",0); + close SOCK; + return; + } # Now print to this socket until we hit the max msg size + do_log("DEBUG: Looping through messages to build a combo",3) if $g{'debug'}; my $msg_size = 0; MSGLOOP: while($msg_size < $g{'msgsize'} and @{$g{'test_results'}}) { @@ -90,9 +115,20 @@ # Nuts, this is a huge message, bigger than our msg size. Well want # to send it by itself to minimize how much it gets truncated if($msg_size == 0) { + do_log("DEBUG: Printing single combo message",3) if $g{'debug'}; # Okay, we are clear, send the message - print SOCK "$msg\n"; - } + eval { + local $SIG{ALRM} = sub { die "Printing message timed out" }; + alarm 10; + print SOCK "$msg\n"; + alarm 0; + }; + if ($@) { + do_log("Timed out printing to display server: $!",0); + close SOCK; + return; + } + } # Not an empty combo msg, wait till our new socket is open else { @@ -116,7 +152,18 @@ # Looks good, print the msg else { - print SOCK "$msg\n"; + do_log("DEBUG: Printing combo message with multiple messages",3) if $g{'debug'}; + eval { + local $SIG{ALRM} = sub { die "Printing message timed out" }; + alarm 10; + print SOCK "$msg\n"; + alarm 0; + }; + if ($@) { + do_log("Timed out printing to display server: $!",0); + close SOCK; + return; + } $msg_size += length $msg; } @@ -130,14 +177,25 @@ # Now send our dm status message! if(!$g{'print_msg'}) { + do_log("DEBUG: Connecting and sending dm message",3) if $g{'debug'}; my $dm_msg = dm_stat_msg(); - socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp')) - or do_log("Failed to create socket ($!)",0) and return; - connect(SOCK, $p_addr) - or do_log("Can't connect to display server ($!)",0) and return; + eval { + local $SIG{ALRM} = sub { die "Connecting and sending dm message timed out" }; + alarm 10; + socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp')) + or do_log("Failed to create socket ($!)",0) and return; + connect(SOCK, $p_addr) + or do_log("Can't connect to display server ($!)",0) and return; - print SOCK "$dm_msg\n"; - close SOCK; + print SOCK "$dm_msg\n"; + close SOCK; + alarm 0; + }; + if ($@) { + do_log("Timed out connecting and sending dm: $!",0); + close SOCK; + return; + } } do_log("Done sending messages",2); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |