You have to remember that Win32 does not have signals as a native concept. Perl's support for them is simulated and limited, and is actually implemented via the process message queue. This is the code that implements the signal emulations from win32.c:
void
sig_terminate(pTHX_ int sig)
{
Perl_warn(aTHX_ "Terminating on signal SIG%s(%d)\n",PL_sig_name[si
+g], sig);
/* exit() seems to be safe, my_exit() or die() is a problem in ^C
+thread */
exit(sig);
}
DllExport int
win32_async_check(pTHX)
{
MSG msg;
int ours = 1;
/* Passing PeekMessage -1 as HWND (2nd arg) only get PostThreadMes
+sage() messages
* and ignores window messages - should co-exist better with windo
+ws apps e.g. Tk
*/
while (PeekMessage(&msg, (HWND)-1, 0, 0, PM_REMOVE|PM_NOYIELD)) {
int sig;
switch(msg.message) {
#if 0
/* Perhaps some other messages could map to signals ? ... */
case WM_CLOSE:
case WM_QUIT:
/* Treat WM_QUIT like SIGHUP? */
sig = SIGHUP;
goto Raise;
break;
#endif
/* We use WM_USER to fake kill() with other signals */
case WM_USER: {
sig = msg.wParam;
Raise:
if (do_raise(aTHX_ sig)) {
sig_terminate(aTHX_ sig);
}
break;
}
case WM_TIMER: {
/* alarm() is a one-shot but SetTimer() repeats so kill it
+ */
if (w32_timerid && w32_timerid==msg.wParam) {
KillTimer(NULL,w32_timerid);
w32_timerid=0;
}
else
goto FallThrough;
/* Now fake a call to signal handler */
if (do_raise(aTHX_ 14)) {
sig_terminate(aTHX_ 14);
}
break;
}
/* Otherwise do normal Win32 thing - in case it is useful */
default:
FallThrough:
TranslateMessage(&msg);
DispatchMessage(&msg);
ours = 0;
break;
}
}
w32_poll_count = 0;
/* Above or other stuff may have set a signal flag */
if (PL_sig_pending) {
despatch_signals();
}
return ours;
}
Setting the environment variable PERL_SIGNALS=unsafe allows ^C to interupt sleep. Without it, the signal handler doesn't get invoked until the sleep is over.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|