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