From c943edb088e27e1e96f9446dc7e554ae09a8cc62 Mon Sep 17 00:00:00 2001 From: rudolfkoenig Date: Tue, 5 Feb 2013 08:25:20 +0000 Subject: [PATCH] Using threads->exit() for Windows git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@2648 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/Blocking.pm | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/FHEM/Blocking.pm b/FHEM/Blocking.pm index 112aff238..981935498 100644 --- a/FHEM/Blocking.pm +++ b/FHEM/Blocking.pm @@ -15,6 +15,8 @@ use warnings; use IO::Socket::INET; sub BlockingCall($$@); +sub BlockingExit($); +sub BlockingKill($); sub BlockingCall($$@) @@ -38,7 +40,7 @@ BlockingCall($$@) my $ret = &{$blockingFn}($arg); use strict "refs"; - exit(0) if(!$finishFn); + BlockingExit(undef) if(!$finishFn); # Look for the telnetport my $tp; @@ -53,7 +55,7 @@ BlockingCall($$@) if(!$tp) { Log 1, "CallBlockingFn: No telnet port found for sending the data back."; - exit(0); + BlockingExit(undef); } # Write the data back, calling the function @@ -62,7 +64,7 @@ BlockingCall($$@) Log 1, "CallBlockingFn: Can't connect to $addr\n" if(!$client); $ret =~ s/'/\\'/g; syswrite($client, "{$finishFn('$ret')}\n"); - exit(0); + BlockingExit($client); } sub @@ -72,5 +74,20 @@ BlockingKill($) Log 1, "Terminated $pid" if($pid && kill(9, $pid)); } +sub +BlockingExit($) +{ + my $client = shift; + + if($^O =~ m/Win/) { + close($client) if($client); + threads->exit(); + + } else { + exit(0); + + } +} + 1;