I missed the destructor, meaning an fd leak (not a problem, as my handlers live the length of the program), but if I implemented one, it would be shorter - just the two
closecalls (QPointeris automatically reset tonullptrwhen the object is deleted, so thehandlerarray looks after itself).I always avoid
qFatal()andQ_ASSERT(in my applications, it's better to manage without the handler than to exit). I'm playing fast and loose withqWarning()inside the signal handler (but at that point, we're in trouble anyway, if we've lost the reader). I did find it helpful to show the error indication in the warning messages whenerrnohas been set.You've found a value
_NSIGfor the range of signals you support. I couldn't find it documented; is that just an artefact of your particular<signal.h>?I also wrote a QTest unit test:
void raiseSignal_USR1() { UnixSignalHandler handler(SIGUSR1); QSignalSpy spy(&handler, SIGNAL(raised())); QVERIFY(spy.isValid()); QVERIFY(spy.isEmpty()); ::raise(SIGUSR1); QVERIFY(spy.wait()); }
Further observations; also, the QPointer obviates the cleanup of handler array
Toby Speight
- 89.6k
- 14
- 105
- 329