libktorrent
2.2.0
src
util
signalcatcher.h
1
/***************************************************************************
2
* Copyright (C) 2010 by Joris Guisson *
3
* joris.guisson@gmail.com *
4
* *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
9
* *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
14
* *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19
***************************************************************************/
20
21
#ifndef BT_SIGNALCATCHER_H
22
#define BT_SIGNALCATCHER_H
23
24
#ifndef Q_WS_WIN
25
26
#include <ktorrent_export.h>
27
#include <signal.h>
28
#include <setjmp.h>
29
#include <QObject>
30
#include <QSocketNotifier>
31
#include <util/error.h>
32
33
namespace
bt
34
{
38
extern
KTORRENT_EXPORT sigjmp_buf sigbus_env;
39
43
class
KTORRENT_EXPORT
BusErrorGuard
44
{
45
public
:
46
BusErrorGuard
();
47
virtual
~
BusErrorGuard
();
48
};
49
53
class
KTORRENT_EXPORT
BusError
:
public
bt::Error
54
{
55
public
:
56
BusError
(
bool
write_operation);
57
~
BusError
()
override
;
58
60
bool
write_operation
;
61
};
62
66
class
KTORRENT_EXPORT
SignalCatcher
:
public
QObject
67
{
68
Q_OBJECT
69
public
:
70
SignalCatcher
(QObject* parent = 0);
71
~
SignalCatcher
()
override
;
72
78
bool
catchSignal
(
int
sig);
79
80
private
Q_SLOTS:
81
void
handleInput(
int
fd);
82
83
private
:
84
static
void
signalHandler(
int
sig, siginfo_t *siginfo,
void
*ptr);
85
86
Q_SIGNALS:
88
void
triggered
();
89
90
private
:
91
QSocketNotifier* notifier;
92
static
int
signal_received_pipe[2];
93
};
94
}
95
97
#define BUS_ERROR_WPROTECT() BusErrorGuard bus_error_guard; if (sigsetjmp(bt::sigbus_env, 1)) throw bt::BusError(true)
98
100
#define BUS_ERROR_RPROTECT() BusErrorGuard bus_error_guard; if (sigsetjmp(bt::sigbus_env, 1)) throw bt::BusError(false)
101
102
#endif
103
104
#endif // BT_SIGNALCATCHER_H
bt::BusError::write_operation
bool write_operation
Whether or not the SIGBUS was triggered by a write operation.
Definition:
signalcatcher.h:60
bt::SignalCatcher::triggered
void triggered()
Emitted when a.
bt::Error
Definition:
error.h:33
bt::SignalCatcher::catchSignal
bool catchSignal(int sig)
bt::BusError
Definition:
signalcatcher.h:54
bt::BusErrorGuard
Definition:
signalcatcher.h:44
bt::SignalCatcher
Definition:
signalcatcher.h:67
Generated by
1.8.20