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