1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Class Poco::SignalHandler</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="author" content="Applied Informatics Software Engineering GmbH and Contributors"/>
<meta name="publisher" content="Applied Informatics Software Engineering GmbH and Contributors"/>
<meta name="copyright" content="Copyright (c) 2009, Applied Informatics Software Engineering GmbH and Contributors"/>
<meta name="language" content="en"/>
<meta name="date" content="2009-11-24"/>
<meta name="generator" content="PocoDoc"/>
<link rel="stylesheet" href="css/styles.css" type="text/css"/>
</head>
<body bgcolor="#ffffff" leftmargin="0" topmargin="0">
<div class="header">
<h1 class="namespace"><a href="Poco.html" class="namespace">Poco</a></h1>
<h1 class="symbol">class SignalHandler</h1>
</div>
<div class="body">
<p>
<b>Library:</b> Foundation<br />
<b>Package:</b> Threading<br />
<b>Header:</b> Poco/SignalHandler.h</p>
<h2>Description</h2>
<div class="description">
<p>This helper class simplifies the handling of POSIX signals. </p>
<p>The class provides a signal handler (installed with installHandlers()) that translates certain POSIX signals (SIGILL, SIGBUS, SIGSEGV, SIGSYS) into C++ exceptions. </p>
<p>Internally, a stack of sigjmp_buf structs is maintained for each thread. The constructor pushes a new sigjmp_buf onto the current thread's stack. The destructor pops the sigjmp_buf from the stack. </p>
<p>The poco_throw_on_signal macro creates an instance of <a href="Poco.SignalHandler.html" title="class Poco::SignalHandler">SignalHandler</a> on the stack, which results in a new sigjmp_buf being created. The sigjmp_buf is then set-up with sigsetjmp(). </p>
<p>The <a href="Poco.SignalHandler.html#10058" title="Poco::SignalHandler::handleSignal()">handleSignal</a>() method, which is invoked when a signal arrives, checks if a sigjmp_buf is available for the current thread. If so, siglongjmp() is used to jump out of the signal handler. </p>
<p>Typical usage is as follows: </p>
<p></p>
<pre>try
{
poco_throw_on_signal;
...
}
catch (Poco::SignalException&)
{
...
}
</pre>
<p>The best way to deal with a <a href="Poco.SignalException.html" title="class Poco::SignalException">SignalException</a> is to log as much context information as possible, to aid in debugging, and then to exit. </p>
<p>The <a href="Poco.SignalHandler.html" title="class Poco::SignalHandler">SignalHandler</a> can be disabled globally by compiling POCO and client code with the POCO_NO_SIGNAL_HANDLER macro defined. </p>
</div>
<h2>Member Summary</h2>
<p><b>Member Functions: </b><a href="Poco.SignalHandler.html#10058" title="Poco::SignalHandler::handleSignal()">handleSignal</a>, <a href="Poco.SignalHandler.html#10057" title="Poco::SignalHandler::install()">install</a>, <a href="Poco.SignalHandler.html#10054" title="Poco::SignalHandler::jumpBuffer()">jumpBuffer</a>, <a href="Poco.SignalHandler.html#10063" title="Poco::SignalHandler::jumpBufferVec()">jumpBufferVec</a>, <a href="Poco.SignalHandler.html#10055" title="Poco::SignalHandler::throwSignalException()">throwSignalException</a></p>
<h2>Nested Classes</h2>
<h3><a href="Poco.SignalHandler.JumpBuffer.html" class="class">struct JumpBuffer</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" /> </h3>
<p> sigjmp_buf cannot be used to instantiate a std::vector,
so we provide a wrapper struct. <a href="Poco.SignalHandler.JumpBuffer.html"><img src="images/arrow.gif" alt="more..." style="vertical-align:baseline;" border="0" /> </a></p>
<h2>Types</h2>
<h3><a name="10062">JumpBufferVec</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">typedef std::vector < <a href="Poco.SignalHandler.JumpBuffer.html" title="struct Poco::SignalHandler::JumpBuffer">JumpBuffer</a> > <a href="Poco.SignalHandler.html#10062" title="Poco::SignalHandler::JumpBufferVec">JumpBufferVec</a>;</p>
<div class="description">
<p></p>
</div>
<h2>Constructors</h2>
<h3><a name="10052">SignalHandler</a></h3>
<p class="decl"><a href="Poco.SignalHandler.html" title="class Poco::SignalHandler">SignalHandler</a>();</p>
<div class="description">
<p>Creates the <a href="Poco.SignalHandler.html" title="class Poco::SignalHandler">SignalHandler</a>. </p>
</div>
<h2>Destructor</h2>
<h3><a name="10053">~SignalHandler</a></h3>
<p class="decl">~<a href="Poco.SignalHandler.html" title="class Poco::SignalHandler">SignalHandler</a>();</p>
<div class="description">
<p>Destroys the <a href="Poco.SignalHandler.html" title="class Poco::SignalHandler">SignalHandler</a>. </p>
</div>
<h2>Member Functions</h2>
<h3><a name="10057">install</a> <img src="images/static.gif" alt="static" title="static" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">static void install();</p>
<div class="description">
<p>Installs signal handlers for SIGILL, SIGBUS, SIGSEGV and SIGSYS. </p>
</div>
<h3><a name="10054">jumpBuffer</a></h3>
<p class="decl">sigjmp_buf & jumpBuffer();</p>
<div class="description">
<p>Returns the top-most sigjmp_buf for the current thread. </p>
</div>
<h3><a name="10055">throwSignalException</a> <img src="images/static.gif" alt="static" title="static" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">static void throwSignalException(<br /> int sig<br />);</p>
<div class="description">
<p>Throws a <a href="Poco.SignalException.html" title="class Poco::SignalException">SignalException</a> with a textual description of the given signal as argument. </p>
</div>
<h3><a name="10058">handleSignal</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" /> <img src="images/static.gif" alt="static" title="static" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">static void handleSignal(<br /> int sig<br />);</p>
<div class="description">
<p>The actual signal handler. </p>
</div>
<h3><a name="10063">jumpBufferVec</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" /> <img src="images/static.gif" alt="static" title="static" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">static <a href="Poco.SignalHandler.html#10062" title="Poco::SignalHandler::JumpBufferVec">JumpBufferVec</a> & jumpBufferVec();</p>
<div class="description">
<p>Returns the <a href="Poco.SignalHandler.html#10062" title="Poco::SignalHandler::JumpBufferVec">JumpBufferVec</a> for the current thread. </p>
</div>
<p class="footer">POCO C++ Libraries 1.3.6-all<br />
Copyright © 2009, <a href="http://pocoproject.org/" target="_blank">Applied Informatics Software Engineering GmbH and Contributors</a></p>
</div>
</body>
</html>
|