Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
shrapnel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
shrapnel
Commits
4e117a35
Commit
4e117a35
authored
Jul 17, 2014
by
Sam Rushing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use signalfd(2) to support kqueue-style signal events.
parent
170aa6df
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
2 deletions
+56
-2
coro/linux_poller.pyx
coro/linux_poller.pyx
+52
-0
coro/signal_handler.py
coro/signal_handler.py
+4
-2
No files found.
coro/linux_poller.pyx
View file @
4e117a35
...
...
@@ -72,6 +72,25 @@ cdef extern from "sys/epoll.h":
int
EPOLLHUP
,
EPOLLPRI
,
EPOLLERR
,
EPOLLET
,
EPOLLONESHOT
,
EPOLLRDHUP
int
EPOLLIN
,
EPOLLOUT
cdef
extern
from
"signal.h"
:
ctypedef
struct
sigset_t
:
unsigned
long
val
[
1
]
int
sigfillset
(
sigset_t
*
set
)
int
sigemptyset
(
sigset_t
*
set
)
int
sigaddset
(
sigset_t
*
,
int
)
int
sigprocmask
(
int
,
sigset_t
*
,
sigset_t
*
)
int
SIG_BLOCK
cdef
extern
from
"sys/signalfd.h"
:
cdef
struct
signalfd_siginfo
:
uint32_t
ssi_signo
int
signalfd
(
int
fd
,
const
sigset_t
*
mask
,
int
flags
)
int
SFD_NONBLOCK
cdef
extern
from
"unistd.h"
:
size_t
read
(
int
fd
,
char
*
buf
,
size_t
nbytes
)
cdef
struct
shrapnel_epoll_event
:
uint32_t
events
epoll_data_t
data
...
...
@@ -175,6 +194,39 @@ cdef class event_key:
else
:
return
(
self
.
events
==
other
.
events
)
and
(
self
.
fd
==
other
.
fd
)
cdef
public
class
signalfd_handler
[
object
signalfd_handler_object
,
type
signalfd_handler_type
]:
cdef
public
int
sig_fd
cdef
public
int
siginfo_size
cdef
readonly
callback
def
__init__
(
self
,
int
sig
,
object
callback
):
cdef
sigset_t
ss
self
.
callback
=
callback
sigemptyset
(
&
ss
)
sigaddset
(
&
ss
,
sig
)
if
sigprocmask
(
SIG_BLOCK
,
&
ss
,
NULL
)
<
0
:
raise_oserror
()
else
:
self
.
sig_fd
=
signalfd
(
-
1
,
&
ss
,
SFD_NONBLOCK
)
if
self
.
sig_fd
<
0
:
raise_oserror
()
else
:
_spawn
(
self
.
signal_thread
,
(),
{})
def
read_signal_event
(
self
):
cdef
signalfd_siginfo
si
cdef
int
r
r
=
read
(
self
.
sig_fd
,
<
char
*>&
si
,
sizeof
(
si
))
if
r
<
0
:
raise_oserror
()
else
:
return
si
.
ssi_signo
def
signal_thread
(
self
):
while
1
:
the_poller
.
_wait_for_read
(
self
.
sig_fd
)
self
.
callback
(
self
.
read_signal_event
())
cdef
public
class
queue_poller
[
object
queue_poller_object
,
type
queue_poller_type
]:
cdef
int
ep_fd
...
...
coro/signal_handler.py
View file @
4e117a35
...
...
@@ -36,7 +36,7 @@ def register (signum, handler, once_only=False):
- `handler`: A callable object that takes one parameter which is the
signal number that was triggered.
- `once_only`: If True, will only trigger once, and then disable the
signal handler. Defaults to False.
signal handler.
[kqueue only].
Defaults to False.
:Exceptions:
- `coro.SimultaneousError`: Another handler is already registered for
...
...
@@ -52,8 +52,10 @@ def register (signum, handler, once_only=False):
flags
|=
coro
.
EV
.
ONESHOT
k_handler
=
lambda
x
:
handler
(
x
.
ident
)
coro
.
set_handler
((
signum
,
coro
.
EVFILT
.
SIGNAL
),
k_handler
,
flags
)
elif
UNAME
==
'Linux'
:
coro
.
signalfd_handler
(
signum
,
handler
)
else
:
signal
.
signal
(
signum
,
handler
)
signal
.
signal
(
signum
,
handler
)
# alias for backward compatibility
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment