1 |
root |
1.115 |
#include "libeio/xthread.h" |
2 |
root |
1.63 |
|
3 |
root |
1.19 |
#include <errno.h> |
4 |
|
|
|
5 |
root |
1.15 |
#include "EXTERN.h" |
6 |
root |
1.1 |
#include "perl.h" |
7 |
|
|
#include "XSUB.h" |
8 |
|
|
|
9 |
root |
1.37 |
#include <stddef.h> |
10 |
root |
1.94 |
#include <stdlib.h> |
11 |
root |
1.41 |
#include <errno.h> |
12 |
root |
1.1 |
#include <sys/types.h> |
13 |
|
|
#include <sys/stat.h> |
14 |
root |
1.37 |
#include <limits.h> |
15 |
root |
1.1 |
#include <fcntl.h> |
16 |
|
|
#include <sched.h> |
17 |
root |
1.103 |
|
18 |
|
|
#ifdef _WIN32 |
19 |
|
|
|
20 |
root |
1.115 |
# define EIO_STRUCT_DIRENT Direntry_t |
21 |
|
|
# undef malloc |
22 |
|
|
# undef free |
23 |
root |
1.103 |
|
24 |
|
|
// perl overrides all those nice win32 functions |
25 |
|
|
# undef open |
26 |
|
|
# undef read |
27 |
|
|
# undef write |
28 |
root |
1.104 |
# undef send |
29 |
|
|
# undef recv |
30 |
root |
1.103 |
# undef stat |
31 |
|
|
# undef fstat |
32 |
|
|
# define lstat stat |
33 |
|
|
# undef truncate |
34 |
|
|
# undef ftruncate |
35 |
|
|
# undef open |
36 |
|
|
# undef close |
37 |
|
|
# undef unlink |
38 |
|
|
# undef rmdir |
39 |
|
|
# undef rename |
40 |
|
|
# undef lseek |
41 |
|
|
|
42 |
|
|
# define chown(a,b,c) (errno = ENOSYS, -1) |
43 |
|
|
# define fchown(a,b,c) (errno = ENOSYS, -1) |
44 |
|
|
# define fchmod(a,b) (errno = ENOSYS, -1) |
45 |
|
|
# define symlink(a,b) (errno = ENOSYS, -1) |
46 |
|
|
# define readlink(a,b,c) (errno = ENOSYS, -1) |
47 |
|
|
# define mknod(a,b,c) (errno = ENOSYS, -1) |
48 |
|
|
# define truncate(a,b) (errno = ENOSYS, -1) |
49 |
|
|
# define ftruncate(fd,o) chsize ((fd), (o)) |
50 |
|
|
# define fsync(fd) _commit (fd) |
51 |
|
|
# define opendir(fd) (errno = ENOSYS, 0) |
52 |
|
|
# define readdir(fd) (errno = ENOSYS, -1) |
53 |
|
|
# define closedir(fd) (errno = ENOSYS, -1) |
54 |
|
|
# define mkdir(a,b) mkdir (a) |
55 |
|
|
|
56 |
|
|
#else |
57 |
|
|
|
58 |
|
|
# include <sys/time.h> |
59 |
|
|
# include <sys/select.h> |
60 |
|
|
# include <unistd.h> |
61 |
|
|
# include <utime.h> |
62 |
|
|
# include <signal.h> |
63 |
root |
1.115 |
# define EIO_STRUCT_DIRENT struct dirent |
64 |
root |
1.103 |
|
65 |
|
|
#endif |
66 |
root |
1.1 |
|
67 |
root |
1.115 |
#define EIO_STRUCT_STAT Stat_t |
68 |
root |
1.65 |
|
69 |
root |
1.101 |
/* use NV for 32 bit perls as it allows larger offsets */ |
70 |
|
|
#if IVSIZE >= 8 |
71 |
|
|
# define SvVAL64 SvIV |
72 |
|
|
#else |
73 |
|
|
# define SvVAL64 SvNV |
74 |
|
|
#endif |
75 |
|
|
|
76 |
root |
1.107 |
static HV *stash; |
77 |
root |
1.90 |
typedef SV SV8; /* byte-sv, used for argument-checking */ |
78 |
|
|
|
79 |
root |
1.44 |
#define AIO_REQ_KLASS "IO::AIO::REQ" |
80 |
|
|
#define AIO_GRP_KLASS "IO::AIO::GRP" |
81 |
root |
1.43 |
|
82 |
root |
1.115 |
#define EIO_COMMON \ |
83 |
|
|
SV *callback; \ |
84 |
|
|
SV *sv1, *sv2; \ |
85 |
|
|
STRLEN stroffset; \ |
86 |
|
|
SV *self |
87 |
|
|
|
88 |
|
|
#include "libeio/eio.h" |
89 |
|
|
|
90 |
|
|
static int req_invoke (eio_req *req); |
91 |
|
|
#define EIO_FINISH(req) req_invoke (req) |
92 |
|
|
static void aio_grp_feed (eio_req *grp); |
93 |
|
|
#define EIO_FEED(req) aio_grp_feed (req) |
94 |
|
|
static void req_destroy (eio_req *grp); |
95 |
|
|
#define EIO_DESTROY(req) req_destroy (req) |
96 |
root |
1.1 |
|
97 |
root |
1.58 |
enum { |
98 |
root |
1.115 |
FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
99 |
root |
1.58 |
}; |
100 |
|
|
|
101 |
root |
1.115 |
#include "libeio/eio.c" |
102 |
root |
1.1 |
|
103 |
root |
1.115 |
typedef eio_req *aio_req; |
104 |
|
|
typedef eio_req *aio_req_ornot; |
105 |
root |
1.60 |
|
106 |
root |
1.116 |
static int max_outstanding = 0; |
107 |
root |
1.85 |
|
108 |
root |
1.115 |
static int next_pri = EIO_DEFAULT_PRI + EIO_PRI_BIAS; |
109 |
root |
1.94 |
|
110 |
root |
1.106 |
static int respipe_osf [2], respipe [2] = { -1, -1 }; |
111 |
root |
1.80 |
|
112 |
root |
1.115 |
static void req_destroy (aio_req req); |
113 |
|
|
static void req_cancel (aio_req req); |
114 |
root |
1.80 |
|
115 |
root |
1.115 |
static void want_poll (void) |
116 |
root |
1.80 |
{ |
117 |
root |
1.115 |
/* write a dummy byte to the pipe so fh becomes ready */ |
118 |
|
|
respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); |
119 |
root |
1.67 |
} |
120 |
|
|
|
121 |
root |
1.115 |
static void done_poll (void) |
122 |
root |
1.67 |
{ |
123 |
root |
1.115 |
/* read any signals sent by the worker threads */ |
124 |
|
|
char buf [4]; |
125 |
|
|
while (respipe_read (respipe [0], buf, 4) == 4) |
126 |
|
|
; |
127 |
root |
1.67 |
} |
128 |
root |
1.1 |
|
129 |
root |
1.43 |
/* must be called at most once */ |
130 |
root |
1.44 |
static SV *req_sv (aio_req req, const char *klass) |
131 |
root |
1.43 |
{ |
132 |
root |
1.49 |
if (!req->self) |
133 |
|
|
{ |
134 |
|
|
req->self = (SV *)newHV (); |
135 |
|
|
sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
136 |
|
|
} |
137 |
root |
1.43 |
|
138 |
root |
1.45 |
return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1))); |
139 |
root |
1.43 |
} |
140 |
|
|
|
141 |
root |
1.45 |
static aio_req SvAIO_REQ (SV *sv) |
142 |
root |
1.26 |
{ |
143 |
root |
1.53 |
MAGIC *mg; |
144 |
|
|
|
145 |
root |
1.45 |
if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv)) |
146 |
|
|
croak ("object of class " AIO_REQ_KLASS " expected"); |
147 |
root |
1.43 |
|
148 |
root |
1.53 |
mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
149 |
root |
1.43 |
|
150 |
|
|
return mg ? (aio_req)mg->mg_ptr : 0; |
151 |
|
|
} |
152 |
|
|
|
153 |
root |
1.49 |
static void aio_grp_feed (aio_req grp) |
154 |
|
|
{ |
155 |
root |
1.115 |
if (grp->sv2 && SvOK (grp->sv2)) |
156 |
root |
1.49 |
{ |
157 |
root |
1.115 |
dSP; |
158 |
root |
1.49 |
|
159 |
root |
1.115 |
ENTER; |
160 |
|
|
SAVETMPS; |
161 |
|
|
PUSHMARK (SP); |
162 |
|
|
XPUSHs (req_sv (grp, AIO_GRP_KLASS)); |
163 |
|
|
PUTBACK; |
164 |
|
|
call_sv (grp->sv2, G_VOID | G_EVAL | G_KEEPERR); |
165 |
|
|
SPAGAIN; |
166 |
|
|
FREETMPS; |
167 |
|
|
LEAVE; |
168 |
root |
1.50 |
} |
169 |
|
|
} |
170 |
|
|
|
171 |
root |
1.115 |
static int req_invoke (eio_req *req) |
172 |
root |
1.45 |
{ |
173 |
|
|
dSP; |
174 |
|
|
|
175 |
root |
1.100 |
if (req->flags & FLAG_SV2_RO_OFF) |
176 |
|
|
SvREADONLY_off (req->sv2); |
177 |
root |
1.86 |
|
178 |
root |
1.115 |
if (!EIO_CANCELLED (req) && SvOK (req->callback)) |
179 |
root |
1.67 |
{ |
180 |
|
|
ENTER; |
181 |
|
|
SAVETMPS; |
182 |
|
|
PUSHMARK (SP); |
183 |
|
|
EXTEND (SP, 1); |
184 |
root |
1.45 |
|
185 |
root |
1.67 |
switch (req->type) |
186 |
root |
1.45 |
{ |
187 |
root |
1.115 |
case EIO_READDIR: |
188 |
root |
1.45 |
{ |
189 |
root |
1.67 |
SV *rv = &PL_sv_undef; |
190 |
root |
1.45 |
|
191 |
root |
1.67 |
if (req->result >= 0) |
192 |
root |
1.45 |
{ |
193 |
root |
1.71 |
int i; |
194 |
root |
1.86 |
char *buf = req->ptr2; |
195 |
root |
1.67 |
AV *av = newAV (); |
196 |
|
|
|
197 |
root |
1.71 |
av_extend (av, req->result - 1); |
198 |
|
|
|
199 |
|
|
for (i = 0; i < req->result; ++i) |
200 |
root |
1.67 |
{ |
201 |
|
|
SV *sv = newSVpv (buf, 0); |
202 |
|
|
|
203 |
root |
1.71 |
av_store (av, i, sv); |
204 |
root |
1.67 |
buf += SvCUR (sv) + 1; |
205 |
|
|
} |
206 |
root |
1.45 |
|
207 |
root |
1.67 |
rv = sv_2mortal (newRV_noinc ((SV *)av)); |
208 |
root |
1.45 |
} |
209 |
|
|
|
210 |
root |
1.67 |
PUSHs (rv); |
211 |
root |
1.45 |
} |
212 |
root |
1.67 |
break; |
213 |
root |
1.45 |
|
214 |
root |
1.115 |
case EIO_OPEN: |
215 |
root |
1.67 |
{ |
216 |
|
|
/* convert fd to fh */ |
217 |
root |
1.107 |
SV *fh = &PL_sv_undef; |
218 |
|
|
|
219 |
|
|
if (req->result >= 0) |
220 |
|
|
{ |
221 |
|
|
GV *gv = (GV *)sv_newmortal (); |
222 |
|
|
int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR); |
223 |
|
|
char sym [64]; |
224 |
|
|
int symlen; |
225 |
|
|
|
226 |
|
|
symlen = snprintf (sym, sizeof (sym), "fd#%d", req->result); |
227 |
|
|
gv_init (gv, stash, sym, symlen, 0); |
228 |
|
|
|
229 |
|
|
symlen = snprintf ( |
230 |
|
|
sym, |
231 |
|
|
sizeof (sym), |
232 |
|
|
"%s&=%d", |
233 |
|
|
flags == O_RDONLY ? "<" : flags == O_WRONLY ? ">" : "+<", |
234 |
|
|
req->result |
235 |
|
|
); |
236 |
root |
1.45 |
|
237 |
root |
1.107 |
if (do_open (gv, sym, symlen, 0, 0, 0, 0)) |
238 |
root |
1.108 |
fh = (SV *)gv; |
239 |
root |
1.107 |
} |
240 |
root |
1.45 |
|
241 |
root |
1.109 |
PUSHs (fh); |
242 |
root |
1.67 |
} |
243 |
|
|
break; |
244 |
root |
1.45 |
|
245 |
root |
1.115 |
case EIO_GROUP: |
246 |
root |
1.86 |
req->int1 = 2; /* mark group as finished */ |
247 |
root |
1.45 |
|
248 |
root |
1.86 |
if (req->sv1) |
249 |
root |
1.67 |
{ |
250 |
|
|
int i; |
251 |
root |
1.86 |
AV *av = (AV *)req->sv1; |
252 |
root |
1.49 |
|
253 |
root |
1.67 |
EXTEND (SP, AvFILL (av) + 1); |
254 |
|
|
for (i = 0; i <= AvFILL (av); ++i) |
255 |
|
|
PUSHs (*av_fetch (av, i, 0)); |
256 |
|
|
} |
257 |
|
|
break; |
258 |
root |
1.48 |
|
259 |
root |
1.115 |
case EIO_NOP: |
260 |
|
|
case EIO_BUSY: |
261 |
root |
1.67 |
break; |
262 |
root |
1.48 |
|
263 |
root |
1.115 |
case EIO_READLINK: |
264 |
root |
1.86 |
if (req->result > 0) |
265 |
|
|
{ |
266 |
root |
1.99 |
SvCUR_set (req->sv2, req->result); |
267 |
|
|
*SvEND (req->sv2) = 0; |
268 |
|
|
PUSHs (req->sv2); |
269 |
root |
1.86 |
} |
270 |
|
|
break; |
271 |
|
|
|
272 |
root |
1.115 |
case EIO_STAT: |
273 |
|
|
case EIO_LSTAT: |
274 |
|
|
case EIO_FSTAT: |
275 |
|
|
PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
276 |
root |
1.87 |
PL_laststatval = req->result; |
277 |
root |
1.115 |
PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
278 |
root |
1.87 |
PUSHs (sv_2mortal (newSViv (req->result))); |
279 |
|
|
break; |
280 |
|
|
|
281 |
root |
1.115 |
case EIO_READ: |
282 |
root |
1.99 |
SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
283 |
|
|
*SvEND (req->sv2) = 0; |
284 |
root |
1.87 |
PUSHs (sv_2mortal (newSViv (req->result))); |
285 |
|
|
break; |
286 |
|
|
|
287 |
root |
1.115 |
case EIO_DUP2: |
288 |
|
|
if (req->result > 0) |
289 |
|
|
req->result = 0; |
290 |
|
|
/* FALLTHROUGH */ |
291 |
|
|
|
292 |
root |
1.67 |
default: |
293 |
|
|
PUSHs (sv_2mortal (newSViv (req->result))); |
294 |
|
|
break; |
295 |
|
|
} |
296 |
root |
1.45 |
|
297 |
root |
1.79 |
errno = req->errorno; |
298 |
root |
1.51 |
|
299 |
root |
1.67 |
PUTBACK; |
300 |
root |
1.109 |
call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
301 |
root |
1.67 |
SPAGAIN; |
302 |
root |
1.51 |
|
303 |
root |
1.67 |
FREETMPS; |
304 |
|
|
LEAVE; |
305 |
root |
1.109 |
|
306 |
|
|
PUTBACK; |
307 |
root |
1.45 |
} |
308 |
|
|
|
309 |
root |
1.115 |
return !!SvTRUE (ERRSV); |
310 |
root |
1.67 |
} |
311 |
|
|
|
312 |
root |
1.101 |
static void req_destroy (aio_req req) |
313 |
root |
1.67 |
{ |
314 |
root |
1.43 |
if (req->self) |
315 |
|
|
{ |
316 |
|
|
sv_unmagic (req->self, PERL_MAGIC_ext); |
317 |
|
|
SvREFCNT_dec (req->self); |
318 |
|
|
} |
319 |
|
|
|
320 |
root |
1.86 |
SvREFCNT_dec (req->sv1); |
321 |
|
|
SvREFCNT_dec (req->sv2); |
322 |
root |
1.49 |
SvREFCNT_dec (req->callback); |
323 |
root |
1.26 |
|
324 |
|
|
Safefree (req); |
325 |
|
|
} |
326 |
|
|
|
327 |
root |
1.72 |
static void req_cancel_subs (aio_req grp) |
328 |
|
|
{ |
329 |
|
|
aio_req sub; |
330 |
|
|
|
331 |
root |
1.115 |
if (grp->type != EIO_GROUP) |
332 |
root |
1.72 |
return; |
333 |
|
|
|
334 |
root |
1.86 |
SvREFCNT_dec (grp->sv2); |
335 |
|
|
grp->sv2 = 0; |
336 |
root |
1.72 |
|
337 |
root |
1.115 |
eio_grp_cancel (grp); |
338 |
root |
1.1 |
} |
339 |
|
|
|
340 |
root |
1.104 |
#ifdef USE_SOCKETS_AS_HANDLES |
341 |
|
|
# define TO_SOCKET(x) (win32_get_osfhandle (x)) |
342 |
|
|
#else |
343 |
|
|
# define TO_SOCKET(x) (x) |
344 |
|
|
#endif |
345 |
|
|
|
346 |
|
|
static void |
347 |
root |
1.111 |
create_respipe (void) |
348 |
root |
1.104 |
{ |
349 |
root |
1.106 |
int old_readfd = respipe [0]; |
350 |
|
|
|
351 |
|
|
if (respipe [1] >= 0) |
352 |
|
|
respipe_close (TO_SOCKET (respipe [1])); |
353 |
|
|
|
354 |
|
|
#ifdef _WIN32 |
355 |
|
|
if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe)) |
356 |
|
|
#else |
357 |
|
|
if (pipe (respipe)) |
358 |
|
|
#endif |
359 |
|
|
croak ("unable to initialize result pipe"); |
360 |
|
|
|
361 |
|
|
if (old_readfd >= 0) |
362 |
|
|
{ |
363 |
|
|
if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) |
364 |
|
|
croak ("unable to initialize result pipe(2)"); |
365 |
|
|
|
366 |
|
|
respipe_close (respipe [0]); |
367 |
|
|
respipe [0] = old_readfd; |
368 |
|
|
} |
369 |
|
|
|
370 |
root |
1.104 |
#ifdef _WIN32 |
371 |
|
|
int arg = 1; |
372 |
root |
1.106 |
if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) |
373 |
|
|
|| ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) |
374 |
root |
1.104 |
#else |
375 |
root |
1.106 |
if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) |
376 |
|
|
|| fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
377 |
root |
1.104 |
#endif |
378 |
root |
1.106 |
croak ("unable to initialize result pipe(3)"); |
379 |
root |
1.104 |
|
380 |
|
|
respipe_osf [0] = TO_SOCKET (respipe [0]); |
381 |
|
|
respipe_osf [1] = TO_SOCKET (respipe [1]); |
382 |
|
|
} |
383 |
|
|
|
384 |
root |
1.111 |
static void poll_wait (void) |
385 |
root |
1.80 |
{ |
386 |
|
|
fd_set rfd; |
387 |
|
|
|
388 |
root |
1.115 |
while (eio_nreqs ()) |
389 |
root |
1.30 |
{ |
390 |
root |
1.80 |
int size; |
391 |
root |
1.115 |
|
392 |
|
|
X_LOCK (reslock); |
393 |
root |
1.80 |
size = res_queue.size; |
394 |
root |
1.115 |
X_UNLOCK (reslock); |
395 |
root |
1.80 |
|
396 |
|
|
if (size) |
397 |
|
|
return; |
398 |
|
|
|
399 |
|
|
maybe_start_thread (); |
400 |
|
|
|
401 |
root |
1.104 |
FD_ZERO (&rfd); |
402 |
|
|
FD_SET (respipe [0], &rfd); |
403 |
root |
1.80 |
|
404 |
root |
1.104 |
PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
405 |
root |
1.22 |
} |
406 |
root |
1.80 |
} |
407 |
|
|
|
408 |
root |
1.111 |
static int poll_cb (void) |
409 |
root |
1.80 |
{ |
410 |
root |
1.116 |
int res; |
411 |
root |
1.17 |
|
412 |
root |
1.116 |
do |
413 |
|
|
{ |
414 |
|
|
res = eio_poll (); |
415 |
|
|
|
416 |
|
|
if (res > 0) |
417 |
|
|
croak (0); |
418 |
|
|
} |
419 |
|
|
while (max_outstanding && max_outstanding <= eio_nreqs ()); |
420 |
root |
1.17 |
|
421 |
|
|
return res; |
422 |
|
|
} |
423 |
root |
1.37 |
|
424 |
root |
1.116 |
static void atfork_child (void) |
425 |
|
|
{ |
426 |
|
|
create_respipe (); |
427 |
|
|
} |
428 |
|
|
|
429 |
root |
1.22 |
#define dREQ \ |
430 |
|
|
aio_req req; \ |
431 |
root |
1.60 |
int req_pri = next_pri; \ |
432 |
root |
1.115 |
next_pri = EIO_DEFAULT_PRI + EIO_PRI_BIAS; \ |
433 |
root |
1.22 |
\ |
434 |
|
|
if (SvOK (callback) && !SvROK (callback)) \ |
435 |
root |
1.43 |
croak ("callback must be undef or of reference type"); \ |
436 |
root |
1.22 |
\ |
437 |
root |
1.115 |
Newz (0, req, 1, eio_req); \ |
438 |
root |
1.22 |
if (!req) \ |
439 |
root |
1.115 |
croak ("out of memory during eio_req allocation"); \ |
440 |
root |
1.22 |
\ |
441 |
root |
1.60 |
req->callback = newSVsv (callback); \ |
442 |
|
|
req->pri = req_pri |
443 |
root |
1.43 |
|
444 |
|
|
#define REQ_SEND \ |
445 |
root |
1.115 |
eio_submit (req); \ |
446 |
root |
1.43 |
\ |
447 |
|
|
if (GIMME_V != G_VOID) \ |
448 |
root |
1.44 |
XPUSHs (req_sv (req, AIO_REQ_KLASS)); |
449 |
root |
1.22 |
|
450 |
root |
1.1 |
MODULE = IO::AIO PACKAGE = IO::AIO |
451 |
|
|
|
452 |
root |
1.8 |
PROTOTYPES: ENABLE |
453 |
|
|
|
454 |
root |
1.1 |
BOOT: |
455 |
|
|
{ |
456 |
root |
1.107 |
stash = gv_stashpv ("IO::AIO", 1); |
457 |
root |
1.82 |
|
458 |
root |
1.41 |
newCONSTSUB (stash, "EXDEV", newSViv (EXDEV)); |
459 |
|
|
newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY)); |
460 |
|
|
newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY)); |
461 |
root |
1.81 |
newCONSTSUB (stash, "O_CREAT", newSViv (O_CREAT)); |
462 |
|
|
newCONSTSUB (stash, "O_TRUNC", newSViv (O_TRUNC)); |
463 |
root |
1.103 |
#ifdef _WIN32 |
464 |
|
|
X_MUTEX_CHECK (wrklock); |
465 |
|
|
X_MUTEX_CHECK (reslock); |
466 |
|
|
X_MUTEX_CHECK (reqlock); |
467 |
|
|
X_MUTEX_CHECK (reqwait); |
468 |
|
|
X_MUTEX_CHECK (preadwritelock); |
469 |
|
|
X_MUTEX_CHECK (readdirlock); |
470 |
root |
1.104 |
|
471 |
|
|
X_COND_CHECK (reqwait); |
472 |
root |
1.103 |
#else |
473 |
root |
1.82 |
newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO)); |
474 |
root |
1.103 |
#endif |
475 |
|
|
|
476 |
root |
1.106 |
create_respipe (); |
477 |
root |
1.41 |
|
478 |
root |
1.115 |
if (eio_init (want_poll, done_poll) < 0) |
479 |
|
|
croak ("IO::AIO: unable to initialise eio library"); |
480 |
root |
1.116 |
|
481 |
|
|
/* atfork child called in fifo order, so before eio's handler */ |
482 |
|
|
X_THREAD_ATFORK (0, 0, atfork_child); |
483 |
root |
1.1 |
} |
484 |
|
|
|
485 |
|
|
void |
486 |
root |
1.85 |
max_poll_reqs (int nreqs) |
487 |
|
|
PROTOTYPE: $ |
488 |
|
|
CODE: |
489 |
root |
1.115 |
eio_set_max_poll_reqs (nreqs); |
490 |
root |
1.85 |
|
491 |
|
|
void |
492 |
|
|
max_poll_time (double nseconds) |
493 |
|
|
PROTOTYPE: $ |
494 |
|
|
CODE: |
495 |
root |
1.115 |
eio_set_max_poll_time (nseconds); |
496 |
root |
1.85 |
|
497 |
|
|
void |
498 |
root |
1.78 |
min_parallel (int nthreads) |
499 |
root |
1.1 |
PROTOTYPE: $ |
500 |
root |
1.115 |
CODE: |
501 |
|
|
eio_set_min_parallel (nthreads); |
502 |
root |
1.1 |
|
503 |
|
|
void |
504 |
root |
1.78 |
max_parallel (int nthreads) |
505 |
|
|
PROTOTYPE: $ |
506 |
root |
1.115 |
CODE: |
507 |
|
|
eio_set_max_parallel (nthreads); |
508 |
root |
1.78 |
|
509 |
root |
1.85 |
void |
510 |
|
|
max_idle (int nthreads) |
511 |
|
|
PROTOTYPE: $ |
512 |
|
|
CODE: |
513 |
root |
1.115 |
eio_set_max_idle (nthreads); |
514 |
root |
1.85 |
|
515 |
root |
1.115 |
void |
516 |
root |
1.78 |
max_outstanding (int maxreqs) |
517 |
root |
1.1 |
PROTOTYPE: $ |
518 |
root |
1.78 |
CODE: |
519 |
|
|
max_outstanding = maxreqs; |
520 |
root |
1.1 |
|
521 |
|
|
void |
522 |
root |
1.99 |
aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
523 |
root |
1.8 |
PROTOTYPE: $$$;$ |
524 |
root |
1.43 |
PPCODE: |
525 |
root |
1.1 |
{ |
526 |
root |
1.22 |
dREQ; |
527 |
root |
1.1 |
|
528 |
root |
1.115 |
req->type = EIO_OPEN; |
529 |
root |
1.86 |
req->sv1 = newSVsv (pathname); |
530 |
root |
1.89 |
req->ptr1 = SvPVbyte_nolen (req->sv1); |
531 |
root |
1.86 |
req->int1 = flags; |
532 |
root |
1.115 |
req->int2 = mode; |
533 |
root |
1.1 |
|
534 |
root |
1.43 |
REQ_SEND; |
535 |
root |
1.1 |
} |
536 |
|
|
|
537 |
|
|
void |
538 |
root |
1.107 |
aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
539 |
root |
1.8 |
PROTOTYPE: $;$ |
540 |
root |
1.1 |
ALIAS: |
541 |
root |
1.115 |
aio_fsync = EIO_FSYNC |
542 |
|
|
aio_fdatasync = EIO_FDATASYNC |
543 |
root |
1.43 |
PPCODE: |
544 |
root |
1.1 |
{ |
545 |
root |
1.22 |
dREQ; |
546 |
root |
1.1 |
|
547 |
|
|
req->type = ix; |
548 |
root |
1.99 |
req->sv1 = newSVsv (fh); |
549 |
root |
1.86 |
req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
550 |
root |
1.1 |
|
551 |
root |
1.43 |
REQ_SEND (req); |
552 |
root |
1.1 |
} |
553 |
|
|
|
554 |
|
|
void |
555 |
root |
1.113 |
aio_close (SV *fh, SV *callback=&PL_sv_undef) |
556 |
root |
1.107 |
PROTOTYPE: $;$ |
557 |
|
|
PPCODE: |
558 |
|
|
{ |
559 |
root |
1.115 |
static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
560 |
root |
1.109 |
dREQ; |
561 |
root |
1.107 |
|
562 |
root |
1.115 |
if (close_pipe < 0) |
563 |
|
|
{ |
564 |
|
|
int pipefd [2]; |
565 |
|
|
|
566 |
|
|
if (pipe (pipefd) < 0 |
567 |
|
|
|| close (pipefd [1]) < 0 |
568 |
|
|
|| fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) |
569 |
|
|
abort (); /*D*/ |
570 |
|
|
|
571 |
|
|
close_pipe = pipefd [0]; |
572 |
|
|
} |
573 |
|
|
|
574 |
|
|
req->type = EIO_DUP2; |
575 |
|
|
req->int1 = close_pipe; |
576 |
|
|
req->sv2 = newSVsv (fh); |
577 |
|
|
req->int2 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
578 |
root |
1.107 |
|
579 |
root |
1.109 |
REQ_SEND (req); |
580 |
root |
1.107 |
} |
581 |
|
|
|
582 |
|
|
void |
583 |
root |
1.102 |
aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
584 |
root |
1.13 |
ALIAS: |
585 |
root |
1.115 |
aio_read = EIO_READ |
586 |
|
|
aio_write = EIO_WRITE |
587 |
root |
1.8 |
PROTOTYPE: $$$$$;$ |
588 |
root |
1.43 |
PPCODE: |
589 |
root |
1.13 |
{ |
590 |
|
|
STRLEN svlen; |
591 |
root |
1.21 |
char *svptr = SvPVbyte (data, svlen); |
592 |
root |
1.102 |
UV len = SvUV (length); |
593 |
root |
1.13 |
|
594 |
|
|
SvUPGRADE (data, SVt_PV); |
595 |
|
|
SvPOK_on (data); |
596 |
root |
1.1 |
|
597 |
root |
1.13 |
if (dataoffset < 0) |
598 |
|
|
dataoffset += svlen; |
599 |
|
|
|
600 |
|
|
if (dataoffset < 0 || dataoffset > svlen) |
601 |
root |
1.102 |
croak ("dataoffset outside of data scalar"); |
602 |
root |
1.13 |
|
603 |
root |
1.115 |
if (ix == EIO_WRITE) |
604 |
root |
1.13 |
{ |
605 |
|
|
/* write: check length and adjust. */ |
606 |
root |
1.102 |
if (!SvOK (length) || len + dataoffset > svlen) |
607 |
|
|
len = svlen - dataoffset; |
608 |
root |
1.13 |
} |
609 |
|
|
else |
610 |
|
|
{ |
611 |
|
|
/* read: grow scalar as necessary */ |
612 |
root |
1.102 |
svptr = SvGROW (data, len + dataoffset + 1); |
613 |
root |
1.13 |
} |
614 |
|
|
|
615 |
root |
1.102 |
if (len < 0) |
616 |
root |
1.13 |
croak ("length must not be negative"); |
617 |
|
|
|
618 |
root |
1.22 |
{ |
619 |
|
|
dREQ; |
620 |
root |
1.13 |
|
621 |
root |
1.22 |
req->type = ix; |
622 |
root |
1.99 |
req->sv1 = newSVsv (fh); |
623 |
root |
1.115 |
req->int1 = PerlIO_fileno (ix == EIO_READ ? IoIFP (sv_2io (fh)) |
624 |
root |
1.86 |
: IoOFP (sv_2io (fh))); |
625 |
root |
1.101 |
req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
626 |
root |
1.102 |
req->size = len; |
627 |
root |
1.99 |
req->sv2 = SvREFCNT_inc (data); |
628 |
root |
1.115 |
req->ptr2 = (char *)svptr + dataoffset; |
629 |
root |
1.86 |
req->stroffset = dataoffset; |
630 |
root |
1.13 |
|
631 |
root |
1.28 |
if (!SvREADONLY (data)) |
632 |
|
|
{ |
633 |
|
|
SvREADONLY_on (data); |
634 |
root |
1.100 |
req->flags |= FLAG_SV2_RO_OFF; |
635 |
root |
1.28 |
} |
636 |
|
|
|
637 |
root |
1.43 |
REQ_SEND; |
638 |
root |
1.22 |
} |
639 |
root |
1.13 |
} |
640 |
root |
1.1 |
|
641 |
|
|
void |
642 |
root |
1.99 |
aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
643 |
root |
1.86 |
PROTOTYPE: $$;$ |
644 |
|
|
PPCODE: |
645 |
|
|
{ |
646 |
|
|
SV *data; |
647 |
|
|
dREQ; |
648 |
|
|
|
649 |
|
|
data = newSV (NAME_MAX); |
650 |
|
|
SvPOK_on (data); |
651 |
|
|
|
652 |
root |
1.115 |
req->type = EIO_READLINK; |
653 |
root |
1.99 |
req->sv1 = newSVsv (path); |
654 |
root |
1.115 |
req->ptr1 = SvPVbyte_nolen (req->sv1); |
655 |
root |
1.99 |
req->sv2 = data; |
656 |
root |
1.115 |
req->ptr2 = SvPVbyte_nolen (data); |
657 |
root |
1.86 |
|
658 |
|
|
REQ_SEND; |
659 |
|
|
} |
660 |
|
|
|
661 |
|
|
void |
662 |
root |
1.101 |
aio_sendfile (SV *out_fh, SV *in_fh, SV *in_offset, UV length, SV *callback=&PL_sv_undef) |
663 |
root |
1.32 |
PROTOTYPE: $$$$;$ |
664 |
root |
1.43 |
PPCODE: |
665 |
root |
1.32 |
{ |
666 |
|
|
dREQ; |
667 |
|
|
|
668 |
root |
1.115 |
req->type = EIO_SENDFILE; |
669 |
root |
1.99 |
req->sv1 = newSVsv (out_fh); |
670 |
root |
1.86 |
req->int1 = PerlIO_fileno (IoIFP (sv_2io (out_fh))); |
671 |
|
|
req->sv2 = newSVsv (in_fh); |
672 |
|
|
req->int2 = PerlIO_fileno (IoIFP (sv_2io (in_fh))); |
673 |
root |
1.101 |
req->offs = SvVAL64 (in_offset); |
674 |
root |
1.86 |
req->size = length; |
675 |
root |
1.32 |
|
676 |
root |
1.43 |
REQ_SEND; |
677 |
root |
1.32 |
} |
678 |
|
|
|
679 |
|
|
void |
680 |
root |
1.101 |
aio_readahead (SV *fh, SV *offset, IV length, SV *callback=&PL_sv_undef) |
681 |
root |
1.8 |
PROTOTYPE: $$$;$ |
682 |
root |
1.43 |
PPCODE: |
683 |
root |
1.1 |
{ |
684 |
root |
1.22 |
dREQ; |
685 |
root |
1.1 |
|
686 |
root |
1.115 |
req->type = EIO_READAHEAD; |
687 |
root |
1.99 |
req->sv1 = newSVsv (fh); |
688 |
root |
1.86 |
req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
689 |
root |
1.101 |
req->offs = SvVAL64 (offset); |
690 |
root |
1.86 |
req->size = length; |
691 |
root |
1.1 |
|
692 |
root |
1.43 |
REQ_SEND; |
693 |
root |
1.1 |
} |
694 |
|
|
|
695 |
|
|
void |
696 |
root |
1.99 |
aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) |
697 |
root |
1.1 |
ALIAS: |
698 |
root |
1.115 |
aio_stat = EIO_STAT |
699 |
|
|
aio_lstat = EIO_LSTAT |
700 |
root |
1.43 |
PPCODE: |
701 |
root |
1.1 |
{ |
702 |
root |
1.22 |
dREQ; |
703 |
root |
1.1 |
|
704 |
root |
1.115 |
req->ptr2 = malloc (sizeof (EIO_STRUCT_STAT)); |
705 |
root |
1.87 |
if (!req->ptr2) |
706 |
root |
1.27 |
{ |
707 |
root |
1.101 |
req_destroy (req); |
708 |
root |
1.88 |
croak ("out of memory during aio_stat statdata allocation"); |
709 |
root |
1.27 |
} |
710 |
root |
1.1 |
|
711 |
root |
1.115 |
req->flags |= EIO_FLAG_PTR2_FREE; |
712 |
root |
1.99 |
req->sv1 = newSVsv (fh_or_path); |
713 |
root |
1.87 |
|
714 |
root |
1.1 |
if (SvPOK (fh_or_path)) |
715 |
|
|
{ |
716 |
root |
1.8 |
req->type = ix; |
717 |
root |
1.89 |
req->ptr1 = SvPVbyte_nolen (req->sv1); |
718 |
root |
1.1 |
} |
719 |
|
|
else |
720 |
|
|
{ |
721 |
root |
1.115 |
req->type = EIO_FSTAT; |
722 |
root |
1.86 |
req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
723 |
root |
1.1 |
} |
724 |
|
|
|
725 |
root |
1.43 |
REQ_SEND; |
726 |
root |
1.1 |
} |
727 |
|
|
|
728 |
|
|
void |
729 |
root |
1.99 |
aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
730 |
|
|
PPCODE: |
731 |
|
|
{ |
732 |
|
|
dREQ; |
733 |
|
|
|
734 |
|
|
req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; |
735 |
|
|
req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; |
736 |
|
|
req->sv1 = newSVsv (fh_or_path); |
737 |
|
|
|
738 |
|
|
if (SvPOK (fh_or_path)) |
739 |
|
|
{ |
740 |
root |
1.115 |
req->type = EIO_UTIME; |
741 |
root |
1.99 |
req->ptr1 = SvPVbyte_nolen (req->sv1); |
742 |
|
|
} |
743 |
|
|
else |
744 |
|
|
{ |
745 |
root |
1.115 |
req->type = EIO_FUTIME; |
746 |
root |
1.99 |
req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
747 |
|
|
} |
748 |
|
|
|
749 |
|
|
REQ_SEND; |
750 |
|
|
} |
751 |
|
|
|
752 |
|
|
void |
753 |
root |
1.103 |
aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) |
754 |
|
|
PPCODE: |
755 |
|
|
{ |
756 |
|
|
dREQ; |
757 |
|
|
|
758 |
|
|
req->sv1 = newSVsv (fh_or_path); |
759 |
|
|
req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
760 |
|
|
|
761 |
|
|
if (SvPOK (fh_or_path)) |
762 |
|
|
{ |
763 |
root |
1.115 |
req->type = EIO_TRUNCATE; |
764 |
root |
1.103 |
req->ptr1 = SvPVbyte_nolen (req->sv1); |
765 |
|
|
} |
766 |
|
|
else |
767 |
|
|
{ |
768 |
root |
1.115 |
req->type = EIO_FTRUNCATE; |
769 |
root |
1.103 |
req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
770 |
|
|
} |
771 |
|
|
|
772 |
|
|
REQ_SEND; |
773 |
|
|
} |
774 |
|
|
|
775 |
|
|
void |
776 |
root |
1.99 |
aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) |
777 |
root |
1.115 |
ALIAS: |
778 |
|
|
aio_chmod = EIO_CHMOD |
779 |
|
|
aio_fchmod = EIO_FCHMOD |
780 |
|
|
aio_mkdir = EIO_MKDIR |
781 |
root |
1.99 |
PPCODE: |
782 |
|
|
{ |
783 |
|
|
dREQ; |
784 |
|
|
|
785 |
root |
1.115 |
req->type = ix; |
786 |
|
|
req->int2 = mode; |
787 |
root |
1.99 |
req->sv1 = newSVsv (fh_or_path); |
788 |
|
|
|
789 |
root |
1.115 |
if (ix == EIO_FCHMOD) |
790 |
|
|
req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
791 |
root |
1.99 |
else |
792 |
root |
1.115 |
req->ptr1 = SvPVbyte_nolen (req->sv1); |
793 |
root |
1.99 |
|
794 |
|
|
REQ_SEND; |
795 |
|
|
} |
796 |
|
|
|
797 |
|
|
void |
798 |
|
|
aio_chown (SV8 *fh_or_path, SV *uid, SV *gid, SV *callback=&PL_sv_undef) |
799 |
|
|
PPCODE: |
800 |
|
|
{ |
801 |
|
|
dREQ; |
802 |
|
|
|
803 |
|
|
req->int2 = SvOK (uid) ? SvIV (uid) : -1; |
804 |
|
|
req->int3 = SvOK (gid) ? SvIV (gid) : -1; |
805 |
|
|
req->sv1 = newSVsv (fh_or_path); |
806 |
|
|
|
807 |
|
|
if (SvPOK (fh_or_path)) |
808 |
|
|
{ |
809 |
root |
1.115 |
req->type = EIO_CHOWN; |
810 |
root |
1.99 |
req->ptr1 = SvPVbyte_nolen (req->sv1); |
811 |
|
|
} |
812 |
|
|
else |
813 |
|
|
{ |
814 |
root |
1.115 |
req->type = EIO_FCHOWN; |
815 |
root |
1.99 |
req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
816 |
|
|
} |
817 |
|
|
|
818 |
|
|
REQ_SEND; |
819 |
|
|
} |
820 |
|
|
|
821 |
|
|
void |
822 |
|
|
aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
823 |
root |
1.22 |
ALIAS: |
824 |
root |
1.115 |
aio_unlink = EIO_UNLINK |
825 |
|
|
aio_rmdir = EIO_RMDIR |
826 |
|
|
aio_readdir = EIO_READDIR |
827 |
root |
1.43 |
PPCODE: |
828 |
root |
1.1 |
{ |
829 |
root |
1.22 |
dREQ; |
830 |
root |
1.1 |
|
831 |
root |
1.22 |
req->type = ix; |
832 |
root |
1.86 |
req->sv1 = newSVsv (pathname); |
833 |
root |
1.89 |
req->ptr1 = SvPVbyte_nolen (req->sv1); |
834 |
root |
1.87 |
|
835 |
root |
1.43 |
REQ_SEND; |
836 |
root |
1.22 |
} |
837 |
|
|
|
838 |
|
|
void |
839 |
root |
1.99 |
aio_link (SV8 *oldpath, SV8 *newpath, SV *callback=&PL_sv_undef) |
840 |
root |
1.40 |
ALIAS: |
841 |
root |
1.115 |
aio_link = EIO_LINK |
842 |
|
|
aio_symlink = EIO_SYMLINK |
843 |
|
|
aio_rename = EIO_RENAME |
844 |
root |
1.43 |
PPCODE: |
845 |
root |
1.22 |
{ |
846 |
|
|
dREQ; |
847 |
root |
1.1 |
|
848 |
root |
1.40 |
req->type = ix; |
849 |
root |
1.115 |
req->sv1 = newSVsv (oldpath); |
850 |
|
|
req->ptr1 = SvPVbyte_nolen (req->sv1); |
851 |
|
|
req->sv2 = newSVsv (newpath); |
852 |
root |
1.99 |
req->ptr2 = SvPVbyte_nolen (req->sv2); |
853 |
root |
1.1 |
|
854 |
root |
1.43 |
REQ_SEND; |
855 |
root |
1.1 |
} |
856 |
|
|
|
857 |
root |
1.42 |
void |
858 |
root |
1.99 |
aio_mknod (SV8 *pathname, int mode, UV dev, SV *callback=&PL_sv_undef) |
859 |
root |
1.81 |
PPCODE: |
860 |
|
|
{ |
861 |
|
|
dREQ; |
862 |
|
|
|
863 |
root |
1.115 |
req->type = EIO_MKNOD; |
864 |
root |
1.86 |
req->sv1 = newSVsv (pathname); |
865 |
root |
1.89 |
req->ptr1 = SvPVbyte_nolen (req->sv1); |
866 |
root |
1.115 |
req->int2 = (mode_t)mode; |
867 |
root |
1.86 |
req->offs = dev; |
868 |
root |
1.81 |
|
869 |
|
|
REQ_SEND; |
870 |
|
|
} |
871 |
|
|
|
872 |
|
|
void |
873 |
root |
1.99 |
aio_busy (double delay, SV *callback=&PL_sv_undef) |
874 |
root |
1.45 |
PPCODE: |
875 |
|
|
{ |
876 |
|
|
dREQ; |
877 |
|
|
|
878 |
root |
1.115 |
req->type = EIO_BUSY; |
879 |
root |
1.99 |
req->nv1 = delay < 0. ? 0. : delay; |
880 |
root |
1.45 |
|
881 |
|
|
REQ_SEND; |
882 |
|
|
} |
883 |
|
|
|
884 |
|
|
void |
885 |
root |
1.99 |
aio_group (SV *callback=&PL_sv_undef) |
886 |
root |
1.46 |
PROTOTYPE: ;$ |
887 |
root |
1.44 |
PPCODE: |
888 |
root |
1.42 |
{ |
889 |
root |
1.44 |
dREQ; |
890 |
root |
1.60 |
|
891 |
root |
1.115 |
req->type = EIO_GROUP; |
892 |
root |
1.86 |
|
893 |
root |
1.115 |
eio_submit (req); |
894 |
root |
1.44 |
XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
895 |
root |
1.42 |
} |
896 |
|
|
|
897 |
root |
1.6 |
void |
898 |
root |
1.99 |
aio_nop (SV *callback=&PL_sv_undef) |
899 |
root |
1.110 |
ALIAS: |
900 |
root |
1.115 |
aio_nop = EIO_NOP |
901 |
|
|
aio_sync = EIO_SYNC |
902 |
root |
1.54 |
PPCODE: |
903 |
|
|
{ |
904 |
|
|
dREQ; |
905 |
|
|
|
906 |
root |
1.110 |
req->type = ix; |
907 |
root |
1.54 |
|
908 |
|
|
REQ_SEND; |
909 |
|
|
} |
910 |
|
|
|
911 |
root |
1.79 |
int |
912 |
|
|
aioreq_pri (int pri = 0) |
913 |
|
|
PROTOTYPE: ;$ |
914 |
|
|
CODE: |
915 |
root |
1.115 |
RETVAL = next_pri - EIO_PRI_BIAS; |
916 |
root |
1.79 |
if (items > 0) |
917 |
|
|
{ |
918 |
root |
1.115 |
if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
919 |
|
|
if (pri > EIO_PRI_MAX) pri = EIO_PRI_MAX; |
920 |
|
|
next_pri = pri + EIO_PRI_BIAS; |
921 |
root |
1.79 |
} |
922 |
|
|
OUTPUT: |
923 |
|
|
RETVAL |
924 |
root |
1.68 |
|
925 |
|
|
void |
926 |
|
|
aioreq_nice (int nice = 0) |
927 |
root |
1.79 |
CODE: |
928 |
|
|
nice = next_pri - nice; |
929 |
root |
1.115 |
if (nice < EIO_PRI_MIN) nice = EIO_PRI_MIN; |
930 |
|
|
if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
931 |
|
|
next_pri = nice + EIO_PRI_BIAS; |
932 |
root |
1.60 |
|
933 |
root |
1.54 |
void |
934 |
root |
1.40 |
flush () |
935 |
root |
1.6 |
PROTOTYPE: |
936 |
|
|
CODE: |
937 |
root |
1.116 |
while (eio_nreqs ()) |
938 |
root |
1.6 |
{ |
939 |
|
|
poll_wait (); |
940 |
root |
1.91 |
poll_cb (); |
941 |
root |
1.6 |
} |
942 |
|
|
|
943 |
root |
1.91 |
int |
944 |
root |
1.7 |
poll() |
945 |
|
|
PROTOTYPE: |
946 |
|
|
CODE: |
947 |
root |
1.92 |
poll_wait (); |
948 |
|
|
RETVAL = poll_cb (); |
949 |
root |
1.91 |
OUTPUT: |
950 |
|
|
RETVAL |
951 |
root |
1.7 |
|
952 |
root |
1.1 |
int |
953 |
|
|
poll_fileno() |
954 |
|
|
PROTOTYPE: |
955 |
|
|
CODE: |
956 |
root |
1.3 |
RETVAL = respipe [0]; |
957 |
root |
1.1 |
OUTPUT: |
958 |
|
|
RETVAL |
959 |
|
|
|
960 |
|
|
int |
961 |
|
|
poll_cb(...) |
962 |
|
|
PROTOTYPE: |
963 |
|
|
CODE: |
964 |
root |
1.85 |
RETVAL = poll_cb (); |
965 |
root |
1.1 |
OUTPUT: |
966 |
|
|
RETVAL |
967 |
|
|
|
968 |
|
|
void |
969 |
|
|
poll_wait() |
970 |
|
|
PROTOTYPE: |
971 |
|
|
CODE: |
972 |
root |
1.92 |
poll_wait (); |
973 |
root |
1.1 |
|
974 |
|
|
int |
975 |
|
|
nreqs() |
976 |
|
|
PROTOTYPE: |
977 |
|
|
CODE: |
978 |
root |
1.115 |
RETVAL = eio_nreqs (); |
979 |
root |
1.1 |
OUTPUT: |
980 |
|
|
RETVAL |
981 |
|
|
|
982 |
root |
1.79 |
int |
983 |
|
|
nready() |
984 |
|
|
PROTOTYPE: |
985 |
|
|
CODE: |
986 |
root |
1.115 |
RETVAL = eio_nready (); |
987 |
root |
1.79 |
OUTPUT: |
988 |
|
|
RETVAL |
989 |
|
|
|
990 |
|
|
int |
991 |
|
|
npending() |
992 |
|
|
PROTOTYPE: |
993 |
|
|
CODE: |
994 |
root |
1.115 |
RETVAL = eio_npending (); |
995 |
root |
1.79 |
OUTPUT: |
996 |
|
|
RETVAL |
997 |
|
|
|
998 |
root |
1.85 |
int |
999 |
|
|
nthreads() |
1000 |
|
|
PROTOTYPE: |
1001 |
|
|
CODE: |
1002 |
root |
1.103 |
if (WORDACCESS_UNSAFE) X_LOCK (wrklock); |
1003 |
root |
1.85 |
RETVAL = started; |
1004 |
root |
1.103 |
if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock); |
1005 |
root |
1.85 |
OUTPUT: |
1006 |
|
|
RETVAL |
1007 |
|
|
|
1008 |
root |
1.48 |
PROTOTYPES: DISABLE |
1009 |
|
|
|
1010 |
root |
1.44 |
MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1011 |
root |
1.43 |
|
1012 |
|
|
void |
1013 |
|
|
cancel (aio_req_ornot req) |
1014 |
|
|
CODE: |
1015 |
root |
1.115 |
eio_cancel (req); |
1016 |
root |
1.45 |
|
1017 |
root |
1.56 |
void |
1018 |
root |
1.59 |
cb (aio_req_ornot req, SV *callback=&PL_sv_undef) |
1019 |
root |
1.56 |
CODE: |
1020 |
|
|
SvREFCNT_dec (req->callback); |
1021 |
|
|
req->callback = newSVsv (callback); |
1022 |
|
|
|
1023 |
root |
1.45 |
MODULE = IO::AIO PACKAGE = IO::AIO::GRP |
1024 |
|
|
|
1025 |
|
|
void |
1026 |
|
|
add (aio_req grp, ...) |
1027 |
|
|
PPCODE: |
1028 |
|
|
{ |
1029 |
|
|
int i; |
1030 |
root |
1.94 |
|
1031 |
root |
1.86 |
if (grp->int1 == 2) |
1032 |
root |
1.49 |
croak ("cannot add requests to IO::AIO::GRP after the group finished"); |
1033 |
|
|
|
1034 |
root |
1.45 |
for (i = 1; i < items; ++i ) |
1035 |
|
|
{ |
1036 |
root |
1.115 |
aio_req req; |
1037 |
|
|
|
1038 |
root |
1.46 |
if (GIMME_V != G_VOID) |
1039 |
|
|
XPUSHs (sv_2mortal (newSVsv (ST (i)))); |
1040 |
|
|
|
1041 |
root |
1.53 |
req = SvAIO_REQ (ST (i)); |
1042 |
root |
1.45 |
|
1043 |
root |
1.46 |
if (req) |
1044 |
root |
1.115 |
eio_grp_add (grp, req); |
1045 |
root |
1.45 |
} |
1046 |
|
|
} |
1047 |
root |
1.43 |
|
1048 |
root |
1.48 |
void |
1049 |
root |
1.72 |
cancel_subs (aio_req_ornot req) |
1050 |
|
|
CODE: |
1051 |
|
|
req_cancel_subs (req); |
1052 |
|
|
|
1053 |
|
|
void |
1054 |
root |
1.51 |
result (aio_req grp, ...) |
1055 |
|
|
CODE: |
1056 |
|
|
{ |
1057 |
|
|
int i; |
1058 |
root |
1.79 |
AV *av; |
1059 |
|
|
|
1060 |
|
|
grp->errorno = errno; |
1061 |
|
|
|
1062 |
|
|
av = newAV (); |
1063 |
root |
1.51 |
|
1064 |
|
|
for (i = 1; i < items; ++i ) |
1065 |
|
|
av_push (av, newSVsv (ST (i))); |
1066 |
|
|
|
1067 |
root |
1.86 |
SvREFCNT_dec (grp->sv1); |
1068 |
|
|
grp->sv1 = (SV *)av; |
1069 |
root |
1.51 |
} |
1070 |
|
|
|
1071 |
|
|
void |
1072 |
root |
1.79 |
errno (aio_req grp, int errorno = errno) |
1073 |
|
|
CODE: |
1074 |
|
|
grp->errorno = errorno; |
1075 |
|
|
|
1076 |
|
|
void |
1077 |
root |
1.67 |
limit (aio_req grp, int limit) |
1078 |
root |
1.49 |
CODE: |
1079 |
root |
1.115 |
eio_grp_limit (grp, limit); |
1080 |
root |
1.49 |
|
1081 |
|
|
void |
1082 |
root |
1.56 |
feed (aio_req grp, SV *callback=&PL_sv_undef) |
1083 |
root |
1.49 |
CODE: |
1084 |
|
|
{ |
1085 |
root |
1.86 |
SvREFCNT_dec (grp->sv2); |
1086 |
|
|
grp->sv2 = newSVsv (callback); |
1087 |
root |
1.49 |
|
1088 |
root |
1.86 |
if (grp->int2 <= 0) |
1089 |
|
|
grp->int2 = 2; |
1090 |
root |
1.49 |
|
1091 |
root |
1.115 |
eio_grp_limit (grp, grp->int2); |
1092 |
root |
1.49 |
} |
1093 |
|
|
|