| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#ifndef _GNU_SOURCE |
|
2
|
|
|
|
|
|
|
# define _GNU_SOURCE |
|
3
|
|
|
|
|
|
|
#endif |
|
4
|
|
|
|
|
|
|
#define GNU_STRERROR_R |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#include |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#include |
|
9
|
|
|
|
|
|
|
#include |
|
10
|
|
|
|
|
|
|
#include |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#define PERL_NO_GET_CONTEXT |
|
13
|
|
|
|
|
|
|
#define PERL_REENTR_API 1 |
|
14
|
|
|
|
|
|
|
#include "EXTERN.h" |
|
15
|
|
|
|
|
|
|
#include "perl.h" |
|
16
|
|
|
|
|
|
|
#include "XSUB.h" |
|
17
|
|
|
|
|
|
|
#include "ppport.h" |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#define get_fd(self) PerlIO_fileno(IoOFP(sv_2io(SvRV(self)))); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#define die_sys(format) Perl_croak(aTHX_ format, strerror(errno)) |
|
22
|
|
|
|
|
|
|
|
|
23
|
2
|
|
|
|
|
|
static sigset_t* S_sv_to_sigset(pTHX_ SV* sigmask, const char* name) { |
|
24
|
|
|
|
|
|
|
IV tmp; |
|
25
|
1
|
50
|
|
|
|
|
if (!SvOK(sigmask)) |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
return NULL; |
|
27
|
1
|
50
|
|
|
|
|
if (!SvROK(sigmask) || !sv_derived_from(sigmask, "POSIX::SigSet")) |
|
|
|
50
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
Perl_croak(aTHX_ "%s is not of type POSIX::SigSet"); |
|
29
|
|
|
|
|
|
|
#if PERL_VERSION > 15 || PERL_VERSION == 15 && PERL_SUBVERSION > 2 |
|
30
|
1
|
50
|
|
|
|
|
return (sigset_t *) SvPV_nolen(SvRV(sigmask)); |
|
31
|
|
|
|
|
|
|
#else |
|
32
|
|
|
|
|
|
|
tmp = SvIV((SV*)SvRV(sigmask)); |
|
33
|
|
|
|
|
|
|
return INT2PTR(sigset_t*, tmp); |
|
34
|
|
|
|
|
|
|
#endif |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
#define sv_to_sigset(sigmask, name) S_sv_to_sigset(aTHX_ sigmask, name) |
|
37
|
|
|
|
|
|
|
|
|
38
|
6
|
|
|
|
|
|
static sigset_t* S_get_sigset(pTHX_ SV* signal, const char* name) { |
|
39
|
3
|
100
|
|
|
|
|
if (SvROK(signal)) |
|
40
|
1
|
|
|
|
|
|
return sv_to_sigset(signal, name); |
|
41
|
|
|
|
|
|
|
else { |
|
42
|
2
|
100
|
|
|
|
|
int signo = (SvIOK(signal) || looks_like_number(signal)) && SvIV(signal) ? SvIV(signal) : whichsig(SvPV_nolen(signal)); |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
43
|
2
|
|
|
|
|
|
SV* buffer = sv_2mortal(newSVpvn("", 0)); |
|
44
|
2
|
50
|
|
|
|
|
SvGROW(buffer, sizeof(sigset_t)); |
|
|
|
50
|
|
|
|
|
|
|
45
|
2
|
50
|
|
|
|
|
sigset_t* ret = (sigset_t*)SvPV_nolen(buffer); |
|
46
|
2
|
|
|
|
|
|
sigemptyset(ret); |
|
47
|
2
|
|
|
|
|
|
sigaddset(ret, signo); |
|
48
|
|
|
|
|
|
|
return ret; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
#define get_sigset(sigmask, name) S_get_sigset(aTHX_ sigmask, name) |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#define NANO_SECONDS 1000000000 |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
static NV timespec_to_nv(struct timespec* time) { |
|
56
|
4
|
|
|
|
|
|
return time->tv_sec + time->tv_nsec / (double)NANO_SECONDS; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
static void nv_to_timespec(NV input, struct timespec* output) { |
|
60
|
4
|
|
|
|
|
|
output->tv_sec = (time_t) floor(input); |
|
61
|
4
|
|
|
|
|
|
output->tv_nsec = (long) ((input - output->tv_sec) * NANO_SECONDS); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
typedef struct { const char* key; clockid_t value; } map[]; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
static map clocks = { |
|
67
|
|
|
|
|
|
|
{ "monotonic" , CLOCK_MONOTONIC }, |
|
68
|
|
|
|
|
|
|
{ "realtime" , CLOCK_REALTIME }, |
|
69
|
|
|
|
|
|
|
{ "boottime" , CLOCK_BOOTTIME }, |
|
70
|
|
|
|
|
|
|
{ "realtime_alarm", CLOCK_REALTIME_ALARM }, |
|
71
|
|
|
|
|
|
|
{ "boottime_alarm", CLOCK_BOOTTIME_ALARM }, |
|
72
|
|
|
|
|
|
|
}; |
|
73
|
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
|
static clockid_t S_get_clockid(pTHX_ const char* clock_name) { |
|
75
|
|
|
|
|
|
|
int i; |
|
76
|
2
|
50
|
|
|
|
|
for (i = 0; i < sizeof clocks / sizeof *clocks; ++i) { |
|
77
|
2
|
100
|
|
|
|
|
if (strEQ(clock_name, clocks[i].key)) |
|
78
|
1
|
|
|
|
|
|
return clocks[i].value; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
0
|
|
|
|
|
|
Perl_croak(aTHX_ "No such timer '%s' known", clock_name); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
#define get_clockid(name) S_get_clockid(aTHX_ name) |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
static clockid_t S_get_clock(pTHX_ SV* ref, const char* funcname) { |
|
85
|
|
|
|
|
|
|
SV* value; |
|
86
|
0
|
0
|
|
|
|
|
if (!SvROK(ref) || !(value = SvRV(ref))) |
|
|
|
0
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
Perl_croak(aTHX_ "Could not %s: this variable is not a clock", funcname); |
|
88
|
0
|
0
|
|
|
|
|
return SvIV(value); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
#define get_clock(ref, func) S_get_clock(aTHX_ ref, func) |
|
91
|
|
|
|
|
|
|
|
|
92
|
6
|
|
|
|
|
|
static SV* S_io_fdopen(pTHX_ int fd, const char* classname, char type) { |
|
93
|
6
|
|
|
|
|
|
PerlIO* pio = PerlIO_fdopen(fd, "r"); |
|
94
|
6
|
|
|
|
|
|
GV* gv = newGVgen(classname); |
|
95
|
6
|
|
|
|
|
|
SV* ret = newRV_noinc((SV*)gv); |
|
96
|
6
|
50
|
|
|
|
|
IO* io = GvIOn(gv); |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
97
|
6
|
|
|
|
|
|
HV* stash = gv_stashpv(classname, FALSE); |
|
98
|
6
|
|
|
|
|
|
IoTYPE(io) = type; |
|
99
|
6
|
|
|
|
|
|
IoIFP(io) = pio; |
|
100
|
6
|
|
|
|
|
|
IoOFP(io) = pio; |
|
101
|
6
|
|
|
|
|
|
sv_bless(ret, stash); |
|
102
|
6
|
|
|
|
|
|
return ret; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
#define io_fdopen(fd, classname, type) S_io_fdopen(aTHX_ fd, classname, type) |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
#define SET_HASH_IMPL(key,value) hv_store(hash, key, sizeof key - 1, value, 0) |
|
107
|
|
|
|
|
|
|
#define SET_HASH_U(key) SET_HASH_IMPL(#key, newSVuv(buffer.ssi_##key)) |
|
108
|
|
|
|
|
|
|
#define SET_HASH_I(key) SET_HASH_IMPL(#key, newSViv(buffer.ssi_##key)) |
|
109
|
|
|
|
|
|
|
|
|
110
|
5
|
|
|
|
|
|
static UV S_get_flag(pTHX_ map flags, size_t map_size, SV* flag_name) { |
|
111
|
|
|
|
|
|
|
int i; |
|
112
|
6
|
50
|
|
|
|
|
for (i = 0; i < map_size / sizeof *flags; ++i) |
|
113
|
6
|
50
|
|
|
|
|
if (strEQ(SvPV_nolen(flag_name), flags[i].key)) |
|
|
|
100
|
|
|
|
|
|
|
114
|
5
|
|
|
|
|
|
return flags[i].value; |
|
115
|
0
|
|
|
|
|
|
Perl_croak(aTHX_ "No such flag '%s' known", flag_name); |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
#define get_flag(map, name) S_get_flag(aTHX_ map, sizeof(map), name) |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
static map event_flags = { |
|
120
|
|
|
|
|
|
|
{ "non-blocking" , EFD_NONBLOCK }, |
|
121
|
|
|
|
|
|
|
{ "semaphore" , EFD_SEMAPHORE }, |
|
122
|
|
|
|
|
|
|
}; |
|
123
|
|
|
|
|
|
|
#define get_event_flag(name) get_flag(event_flags, name) |
|
124
|
|
|
|
|
|
|
|
|
125
|
2
|
|
|
|
|
|
static SV* S_new_eventfd(pTHX_ const char* classname, UV initial, int flags) { |
|
126
|
2
|
|
|
|
|
|
int fd = eventfd(initial, flags); |
|
127
|
2
|
50
|
|
|
|
|
if (fd < 0) |
|
128
|
0
|
|
|
|
|
|
die_sys("Can't open eventfd descriptor: %s"); |
|
129
|
2
|
|
|
|
|
|
return io_fdopen(fd, classname, '|'); |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
#define new_eventfd(classname, initial, flags) S_new_eventfd(aTHX_ classname, initial, flags) |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
static map signal_flags = { |
|
134
|
|
|
|
|
|
|
{ "non-blocking" , SFD_NONBLOCK }, |
|
135
|
|
|
|
|
|
|
}; |
|
136
|
|
|
|
|
|
|
#define get_signal_flag(name) get_flag(signal_flags, name) |
|
137
|
|
|
|
|
|
|
|
|
138
|
3
|
|
|
|
|
|
static SV* S_new_signalfd(pTHX_ const char* classname, SV* sigmask, int flags) { |
|
139
|
3
|
|
|
|
|
|
int fd = signalfd(-1, get_sigset(sigmask, "signalfd"), flags); |
|
140
|
3
|
50
|
|
|
|
|
if (fd < 0) |
|
141
|
0
|
|
|
|
|
|
die_sys("Can't open signalfd descriptor: %s"); |
|
142
|
3
|
|
|
|
|
|
return io_fdopen(fd, classname, '<'); |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
#define new_signalfd(classname, sigset, flags) S_new_signalfd(aTHX_ classname, sigset, flags) |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
static map timer_flags = { |
|
147
|
|
|
|
|
|
|
{ "non-blocking" , TFD_NONBLOCK }, |
|
148
|
|
|
|
|
|
|
}; |
|
149
|
|
|
|
|
|
|
#define get_timer_flag(name) get_flag(timer_flags, name) |
|
150
|
|
|
|
|
|
|
|
|
151
|
1
|
|
|
|
|
|
static SV* S_new_timerfd(pTHX_ const char* classname, SV* clock, int flags, const char* funcname) { |
|
152
|
1
|
50
|
|
|
|
|
clockid_t clock_id = SvROK(clock) ? get_clock(clock, funcname) : get_clockid(SvPV_nolen(clock)); |
|
|
|
50
|
|
|
|
|
|
|
153
|
1
|
|
|
|
|
|
int fd = timerfd_create(clock_id, flags); |
|
154
|
1
|
50
|
|
|
|
|
if (fd < 0) |
|
155
|
0
|
|
|
|
|
|
die_sys("Can't open timerfd descriptor: %s"); |
|
156
|
1
|
|
|
|
|
|
return io_fdopen(fd, classname, '<'); |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
#define new_timerfd(classname, clock, flags, func) S_new_timerfd(aTHX_ classname, clock, flags, func) |
|
159
|
|
|
|
|
|
|
|
|
160
|
13
|
|
|
|
|
|
static int S_interrupted(pTHX_ int value) { |
|
161
|
13
|
100
|
|
|
|
|
if (value == -1 && errno == EINTR) { |
|
|
|
50
|
|
|
|
|
|
|
162
|
0
|
0
|
|
|
|
|
PERL_ASYNC_CHECK(); |
|
163
|
|
|
|
|
|
|
return 1; |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
return 0; |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
#define interrupted(value) S_interrupted(aTHX_ value) |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
MODULE = Linux::FD PACKAGE = Linux::FD |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
BOOT: |
|
172
|
3
|
|
|
|
|
|
load_module(PERL_LOADMOD_NOIMPORT, newSVpvs("IO::Handle"), NULL); |
|
173
|
3
|
|
|
|
|
|
av_push(get_av("Linux::FD::Event::ISA" , GV_ADD), newSVpvs("IO::Handle")); |
|
174
|
3
|
|
|
|
|
|
av_push(get_av("Linux::FD::Signal::ISA", GV_ADD), newSVpvs("IO::Handle")); |
|
175
|
3
|
|
|
|
|
|
av_push(get_av("Linux::FD::Timer::ISA" , GV_ADD), newSVpvs("IO::Handle")); |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
SV* |
|
178
|
|
|
|
|
|
|
eventfd(initial = 0, ...) |
|
179
|
|
|
|
|
|
|
UV initial; |
|
180
|
|
|
|
|
|
|
PREINIT: |
|
181
|
|
|
|
|
|
|
int i, flags = EFD_CLOEXEC; |
|
182
|
|
|
|
|
|
|
CODE: |
|
183
|
5
|
100
|
|
|
|
|
for (i = 1; i < items; i++) |
|
184
|
3
|
|
|
|
|
|
flags |= get_event_flag(ST(i)); |
|
185
|
2
|
|
|
|
|
|
RETVAL = new_eventfd("Linux::FD::Event", initial, flags); |
|
186
|
|
|
|
|
|
|
OUTPUT: |
|
187
|
|
|
|
|
|
|
RETVAL |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
SV* |
|
190
|
|
|
|
|
|
|
signalfd(sigmask, ...) |
|
191
|
|
|
|
|
|
|
SV* sigmask; |
|
192
|
|
|
|
|
|
|
PREINIT: |
|
193
|
|
|
|
|
|
|
int i, flags = SFD_CLOEXEC; |
|
194
|
|
|
|
|
|
|
CODE: |
|
195
|
4
|
100
|
|
|
|
|
for (i = 1; i < items; i++) |
|
196
|
1
|
|
|
|
|
|
flags |= get_signal_flag(ST(i)); |
|
197
|
3
|
|
|
|
|
|
RETVAL = new_signalfd("Linux::FD::Signal", sigmask, flags); |
|
198
|
|
|
|
|
|
|
OUTPUT: |
|
199
|
|
|
|
|
|
|
RETVAL |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
SV* |
|
202
|
|
|
|
|
|
|
timerfd(clock, ...) |
|
203
|
|
|
|
|
|
|
SV* clock; |
|
204
|
|
|
|
|
|
|
PREINIT: |
|
205
|
|
|
|
|
|
|
int i, flags = TFD_CLOEXEC; |
|
206
|
|
|
|
|
|
|
CODE: |
|
207
|
2
|
100
|
|
|
|
|
for (i = 1; i < items; i++) |
|
208
|
1
|
|
|
|
|
|
flags |= get_timer_flag(ST(i)); |
|
209
|
1
|
|
|
|
|
|
RETVAL = new_timerfd("Linux::FD::Timer", clock, flags, "timerfd"); |
|
210
|
|
|
|
|
|
|
OUTPUT: |
|
211
|
|
|
|
|
|
|
RETVAL |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
MODULE = Linux::FD PACKAGE = Linux::FD::Event |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
SV* |
|
216
|
|
|
|
|
|
|
new(classname, initial = 0, ...) |
|
217
|
|
|
|
|
|
|
const char* classname; |
|
218
|
|
|
|
|
|
|
UV initial; |
|
219
|
|
|
|
|
|
|
PREINIT: |
|
220
|
|
|
|
|
|
|
int i, flags = EFD_CLOEXEC; |
|
221
|
|
|
|
|
|
|
CODE: |
|
222
|
0
|
0
|
|
|
|
|
for (i = 2; i < items; i++) |
|
223
|
0
|
|
|
|
|
|
flags |= get_event_flag(ST(i)); |
|
224
|
0
|
|
|
|
|
|
RETVAL = new_eventfd(classname, initial, flags); |
|
225
|
|
|
|
|
|
|
OUTPUT: |
|
226
|
|
|
|
|
|
|
RETVAL |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
UV |
|
229
|
|
|
|
|
|
|
get(self) |
|
230
|
|
|
|
|
|
|
SV* self; |
|
231
|
|
|
|
|
|
|
PREINIT: |
|
232
|
|
|
|
|
|
|
uint64_t buffer; |
|
233
|
|
|
|
|
|
|
int ret, events; |
|
234
|
|
|
|
|
|
|
CODE: |
|
235
|
6
|
|
|
|
|
|
events = get_fd(self); |
|
236
|
|
|
|
|
|
|
do { |
|
237
|
6
|
|
|
|
|
|
ret = read(events, &buffer, sizeof buffer); |
|
238
|
6
|
50
|
|
|
|
|
} while (interrupted(ret)); |
|
239
|
6
|
100
|
|
|
|
|
if (ret == -1) { |
|
240
|
3
|
50
|
|
|
|
|
if (errno == EAGAIN) |
|
241
|
3
|
|
|
|
|
|
XSRETURN_EMPTY; |
|
242
|
|
|
|
|
|
|
else |
|
243
|
0
|
|
|
|
|
|
die_sys("Couldn't read from eventfd: %s"); |
|
244
|
|
|
|
|
|
|
} |
|
245
|
3
|
|
|
|
|
|
RETVAL = buffer; |
|
246
|
|
|
|
|
|
|
OUTPUT: |
|
247
|
|
|
|
|
|
|
RETVAL |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
UV |
|
250
|
|
|
|
|
|
|
add(self, value) |
|
251
|
|
|
|
|
|
|
SV* self; |
|
252
|
|
|
|
|
|
|
UV value; |
|
253
|
|
|
|
|
|
|
PREINIT: |
|
254
|
|
|
|
|
|
|
uint64_t buffer; |
|
255
|
|
|
|
|
|
|
int ret, events; |
|
256
|
|
|
|
|
|
|
CODE: |
|
257
|
2
|
|
|
|
|
|
events = get_fd(self); |
|
258
|
2
|
|
|
|
|
|
buffer = value; |
|
259
|
|
|
|
|
|
|
do { |
|
260
|
2
|
|
|
|
|
|
ret = write(events, &buffer, sizeof buffer); |
|
261
|
2
|
50
|
|
|
|
|
} while (interrupted(ret)); |
|
262
|
2
|
50
|
|
|
|
|
if (ret == -1) { |
|
263
|
0
|
0
|
|
|
|
|
if (errno == EAGAIN) |
|
264
|
0
|
|
|
|
|
|
XSRETURN_EMPTY; |
|
265
|
|
|
|
|
|
|
else |
|
266
|
0
|
|
|
|
|
|
die_sys("Couldn't write to eventfd: %s"); |
|
267
|
|
|
|
|
|
|
} |
|
268
|
|
|
|
|
|
|
RETVAL = value; |
|
269
|
|
|
|
|
|
|
OUTPUT: |
|
270
|
|
|
|
|
|
|
RETVAL |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
MODULE = Linux::FD PACKAGE = Linux::FD::Signal |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
SV* |
|
276
|
|
|
|
|
|
|
new(classname, sigmask, ...) |
|
277
|
|
|
|
|
|
|
const char* classname; |
|
278
|
|
|
|
|
|
|
SV* sigmask; |
|
279
|
|
|
|
|
|
|
PREINIT: |
|
280
|
|
|
|
|
|
|
int i, flags = SFD_CLOEXEC; |
|
281
|
|
|
|
|
|
|
CODE: |
|
282
|
0
|
0
|
|
|
|
|
for (i = 2; i < items; i++) |
|
283
|
0
|
|
|
|
|
|
flags |= get_signal_flag(ST(i)); |
|
284
|
0
|
|
|
|
|
|
RETVAL = new_signalfd(classname, sigmask, flags); |
|
285
|
|
|
|
|
|
|
OUTPUT: |
|
286
|
|
|
|
|
|
|
RETVAL |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
void set_mask(self, sigmask) |
|
289
|
|
|
|
|
|
|
SV* self; |
|
290
|
|
|
|
|
|
|
SV* sigmask; |
|
291
|
|
|
|
|
|
|
PREINIT: |
|
292
|
|
|
|
|
|
|
int fd; |
|
293
|
|
|
|
|
|
|
CODE: |
|
294
|
0
|
|
|
|
|
|
fd = get_fd(self); |
|
295
|
0
|
0
|
|
|
|
|
if(signalfd(fd, sv_to_sigset(sigmask, "signalfd"), 0) == -1) |
|
296
|
0
|
|
|
|
|
|
die_sys("Couldn't set_mask: %s"); |
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
SV* |
|
299
|
|
|
|
|
|
|
receive(self) |
|
300
|
|
|
|
|
|
|
SV* self; |
|
301
|
|
|
|
|
|
|
PREINIT: |
|
302
|
|
|
|
|
|
|
struct signalfd_siginfo buffer; |
|
303
|
|
|
|
|
|
|
int tmp, timer; |
|
304
|
|
|
|
|
|
|
HV* hash; |
|
305
|
|
|
|
|
|
|
CODE: |
|
306
|
2
|
|
|
|
|
|
timer = get_fd(self); |
|
307
|
|
|
|
|
|
|
do { |
|
308
|
2
|
|
|
|
|
|
tmp = read(timer, &buffer, sizeof buffer); |
|
309
|
2
|
50
|
|
|
|
|
} while (interrupted(tmp)); |
|
310
|
2
|
100
|
|
|
|
|
if (tmp == -1) { |
|
311
|
1
|
50
|
|
|
|
|
if (errno == EAGAIN) |
|
312
|
1
|
|
|
|
|
|
XSRETURN_EMPTY; |
|
313
|
|
|
|
|
|
|
else |
|
314
|
0
|
|
|
|
|
|
die_sys("Couldn't read from signalfd: %s"); |
|
315
|
|
|
|
|
|
|
} |
|
316
|
1
|
|
|
|
|
|
hash = newHV(); |
|
317
|
1
|
|
|
|
|
|
SET_HASH_U(signo); |
|
318
|
1
|
|
|
|
|
|
SET_HASH_I(errno); |
|
319
|
1
|
|
|
|
|
|
SET_HASH_I(code); |
|
320
|
1
|
|
|
|
|
|
SET_HASH_U(pid); |
|
321
|
1
|
|
|
|
|
|
SET_HASH_U(uid); |
|
322
|
1
|
|
|
|
|
|
SET_HASH_I(fd); |
|
323
|
1
|
|
|
|
|
|
SET_HASH_U(tid); |
|
324
|
1
|
|
|
|
|
|
SET_HASH_U(band); |
|
325
|
1
|
|
|
|
|
|
SET_HASH_U(overrun); |
|
326
|
1
|
|
|
|
|
|
SET_HASH_U(trapno); |
|
327
|
1
|
|
|
|
|
|
SET_HASH_I(status); |
|
328
|
1
|
|
|
|
|
|
SET_HASH_I(int); |
|
329
|
1
|
|
|
|
|
|
SET_HASH_U(ptr); |
|
330
|
1
|
|
|
|
|
|
SET_HASH_U(utime); |
|
331
|
1
|
|
|
|
|
|
SET_HASH_U(stime); |
|
332
|
1
|
|
|
|
|
|
SET_HASH_U(addr); |
|
333
|
1
|
|
|
|
|
|
RETVAL = newRV_noinc((SV*)hash); |
|
334
|
|
|
|
|
|
|
OUTPUT: |
|
335
|
|
|
|
|
|
|
RETVAL |
|
336
|
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
MODULE = Linux::FD PACKAGE = Linux::FD::Timer |
|
339
|
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
SV* |
|
341
|
|
|
|
|
|
|
new(classname, clock) |
|
342
|
|
|
|
|
|
|
const char* classname; |
|
343
|
|
|
|
|
|
|
SV* clock; |
|
344
|
|
|
|
|
|
|
PREINIT: |
|
345
|
|
|
|
|
|
|
int i, flags = TFD_CLOEXEC; |
|
346
|
|
|
|
|
|
|
CODE: |
|
347
|
0
|
0
|
|
|
|
|
for (i = 2; i < items; i++) |
|
348
|
0
|
|
|
|
|
|
flags |= get_timer_flag(ST(i)); |
|
349
|
0
|
|
|
|
|
|
RETVAL = new_timerfd(classname, clock, flags, "Linux::FD::Timer->new"); |
|
350
|
|
|
|
|
|
|
OUTPUT: |
|
351
|
|
|
|
|
|
|
RETVAL |
|
352
|
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
void |
|
354
|
|
|
|
|
|
|
get_timeout(self) |
|
355
|
|
|
|
|
|
|
SV* self; |
|
356
|
|
|
|
|
|
|
PREINIT: |
|
357
|
|
|
|
|
|
|
int timer; |
|
358
|
|
|
|
|
|
|
struct itimerspec value; |
|
359
|
|
|
|
|
|
|
PPCODE: |
|
360
|
1
|
|
|
|
|
|
timer = get_fd(self); |
|
361
|
1
|
50
|
|
|
|
|
if (timerfd_gettime(timer, &value) == -1) |
|
362
|
0
|
|
|
|
|
|
die_sys("Couldn't get_timeout: %s"); |
|
363
|
1
|
50
|
|
|
|
|
mXPUSHn(timespec_to_nv(&value.it_value)); |
|
364
|
1
|
50
|
|
|
|
|
if (GIMME_V == G_ARRAY) |
|
|
|
50
|
|
|
|
|
|
|
365
|
1
|
50
|
|
|
|
|
mXPUSHn(timespec_to_nv(&value.it_interval)); |
|
366
|
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
SV* |
|
368
|
|
|
|
|
|
|
set_timeout(self, new_value, new_interval = 0, abstime = 0) |
|
369
|
|
|
|
|
|
|
SV* self; |
|
370
|
|
|
|
|
|
|
NV new_value; |
|
371
|
|
|
|
|
|
|
NV new_interval; |
|
372
|
|
|
|
|
|
|
IV abstime; |
|
373
|
|
|
|
|
|
|
PREINIT: |
|
374
|
|
|
|
|
|
|
int timer; |
|
375
|
|
|
|
|
|
|
struct itimerspec new_itimer, old_itimer; |
|
376
|
|
|
|
|
|
|
PPCODE: |
|
377
|
2
|
|
|
|
|
|
timer = get_fd(self); |
|
378
|
|
|
|
|
|
|
nv_to_timespec(new_value, &new_itimer.it_value); |
|
379
|
|
|
|
|
|
|
nv_to_timespec(new_interval, &new_itimer.it_interval); |
|
380
|
2
|
50
|
|
|
|
|
if (timerfd_settime(timer, (abstime ? TIMER_ABSTIME : 0), &new_itimer, &old_itimer) == -1) |
|
381
|
0
|
|
|
|
|
|
die_sys("Couldn't set_timeout: %s"); |
|
382
|
2
|
50
|
|
|
|
|
mXPUSHn(timespec_to_nv(&old_itimer.it_value)); |
|
383
|
2
|
50
|
|
|
|
|
if (GIMME_V == G_ARRAY) |
|
|
|
50
|
|
|
|
|
|
|
384
|
0
|
0
|
|
|
|
|
mXPUSHn(timespec_to_nv(&old_itimer.it_interval)); |
|
385
|
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
IV |
|
387
|
|
|
|
|
|
|
receive(self) |
|
388
|
|
|
|
|
|
|
SV* self; |
|
389
|
|
|
|
|
|
|
PREINIT: |
|
390
|
|
|
|
|
|
|
uint64_t buffer; |
|
391
|
|
|
|
|
|
|
int ret, timer; |
|
392
|
|
|
|
|
|
|
CODE: |
|
393
|
3
|
|
|
|
|
|
timer = get_fd(self); |
|
394
|
|
|
|
|
|
|
do { |
|
395
|
3
|
|
|
|
|
|
ret = read(timer, &buffer, sizeof buffer); |
|
396
|
3
|
50
|
|
|
|
|
} while (interrupted(ret)); |
|
397
|
3
|
100
|
|
|
|
|
if (ret == -1) { |
|
398
|
1
|
50
|
|
|
|
|
if (errno == EAGAIN) |
|
399
|
1
|
|
|
|
|
|
XSRETURN_EMPTY; |
|
400
|
|
|
|
|
|
|
else |
|
401
|
0
|
|
|
|
|
|
die_sys("Couldn't read from timerfd: %s"); |
|
402
|
|
|
|
|
|
|
} |
|
403
|
2
|
|
|
|
|
|
RETVAL = buffer; |
|
404
|
|
|
|
|
|
|
OUTPUT: |
|
405
|
|
|
|
|
|
|
RETVAL |
|
406
|
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
void |
|
408
|
|
|
|
|
|
|
clocks(classname) |
|
409
|
|
|
|
|
|
|
SV* classname; |
|
410
|
|
|
|
|
|
|
INIT: |
|
411
|
|
|
|
|
|
|
int i; |
|
412
|
|
|
|
|
|
|
PPCODE: |
|
413
|
6
|
100
|
|
|
|
|
for (i = 0; i < sizeof clocks / sizeof *clocks; ++i) |
|
414
|
5
|
50
|
|
|
|
|
mXPUSHp(clocks[i].key, strlen(clocks[i].key)); |