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.115 |
static unsigned int max_outstanding = 0x7fffffff; |
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.115 |
int res = eio_poll (); |
411 |
root |
1.17 |
|
412 |
root |
1.115 |
if (res > 0) |
413 |
|
|
croak (0); |
414 |
root |
1.17 |
|
415 |
|
|
return res; |
416 |
|
|
} |
417 |
root |
1.37 |
|
418 |
root |
1.22 |
#define dREQ \ |
419 |
|
|
aio_req req; \ |
420 |
root |
1.60 |
int req_pri = next_pri; \ |
421 |
root |
1.115 |
next_pri = EIO_DEFAULT_PRI + EIO_PRI_BIAS; \ |
422 |
root |
1.22 |
\ |
423 |
|
|
if (SvOK (callback) && !SvROK (callback)) \ |
424 |
root |
1.43 |
croak ("callback must be undef or of reference type"); \ |
425 |
root |
1.22 |
\ |
426 |
root |
1.115 |
Newz (0, req, 1, eio_req); \ |
427 |
root |
1.22 |
if (!req) \ |
428 |
root |
1.115 |
croak ("out of memory during eio_req allocation"); \ |
429 |
root |
1.22 |
\ |
430 |
root |
1.60 |
req->callback = newSVsv (callback); \ |
431 |
|
|
req->pri = req_pri |
432 |
root |
1.43 |
|
433 |
|
|
#define REQ_SEND \ |
434 |
root |
1.115 |
eio_submit (req); \ |
435 |
root |
1.43 |
\ |
436 |
|
|
if (GIMME_V != G_VOID) \ |
437 |
root |
1.44 |
XPUSHs (req_sv (req, AIO_REQ_KLASS)); |
438 |
root |
1.22 |
|
439 |
root |
1.1 |
MODULE = IO::AIO PACKAGE = IO::AIO |
440 |
|
|
|
441 |
root |
1.8 |
PROTOTYPES: ENABLE |
442 |
|
|
|
443 |
root |
1.1 |
BOOT: |
444 |
|
|
{ |
445 |
root |
1.107 |
stash = gv_stashpv ("IO::AIO", 1); |
446 |
root |
1.82 |
|
447 |
root |
1.41 |
newCONSTSUB (stash, "EXDEV", newSViv (EXDEV)); |
448 |
|
|
newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY)); |
449 |
|
|
newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY)); |
450 |
root |
1.81 |
newCONSTSUB (stash, "O_CREAT", newSViv (O_CREAT)); |
451 |
|
|
newCONSTSUB (stash, "O_TRUNC", newSViv (O_TRUNC)); |
452 |
root |
1.103 |
#ifdef _WIN32 |
453 |
|
|
X_MUTEX_CHECK (wrklock); |
454 |
|
|
X_MUTEX_CHECK (reslock); |
455 |
|
|
X_MUTEX_CHECK (reqlock); |
456 |
|
|
X_MUTEX_CHECK (reqwait); |
457 |
|
|
X_MUTEX_CHECK (preadwritelock); |
458 |
|
|
X_MUTEX_CHECK (readdirlock); |
459 |
root |
1.104 |
|
460 |
|
|
X_COND_CHECK (reqwait); |
461 |
root |
1.103 |
#else |
462 |
root |
1.82 |
newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO)); |
463 |
root |
1.103 |
#endif |
464 |
|
|
|
465 |
root |
1.106 |
create_respipe (); |
466 |
root |
1.41 |
|
467 |
root |
1.115 |
if (eio_init (want_poll, done_poll) < 0) |
468 |
|
|
croak ("IO::AIO: unable to initialise eio library"); |
469 |
root |
1.1 |
} |
470 |
|
|
|
471 |
|
|
void |
472 |
root |
1.85 |
max_poll_reqs (int nreqs) |
473 |
|
|
PROTOTYPE: $ |
474 |
|
|
CODE: |
475 |
root |
1.115 |
eio_set_max_poll_reqs (nreqs); |
476 |
root |
1.85 |
|
477 |
|
|
void |
478 |
|
|
max_poll_time (double nseconds) |
479 |
|
|
PROTOTYPE: $ |
480 |
|
|
CODE: |
481 |
root |
1.115 |
eio_set_max_poll_time (nseconds); |
482 |
root |
1.85 |
|
483 |
|
|
void |
484 |
root |
1.78 |
min_parallel (int nthreads) |
485 |
root |
1.1 |
PROTOTYPE: $ |
486 |
root |
1.115 |
CODE: |
487 |
|
|
eio_set_min_parallel (nthreads); |
488 |
root |
1.1 |
|
489 |
|
|
void |
490 |
root |
1.78 |
max_parallel (int nthreads) |
491 |
|
|
PROTOTYPE: $ |
492 |
root |
1.115 |
CODE: |
493 |
|
|
eio_set_max_parallel (nthreads); |
494 |
root |
1.78 |
|
495 |
root |
1.85 |
void |
496 |
|
|
max_idle (int nthreads) |
497 |
|
|
PROTOTYPE: $ |
498 |
|
|
CODE: |
499 |
root |
1.115 |
eio_set_max_idle (nthreads); |
500 |
root |
1.85 |
|
501 |
root |
1.115 |
void |
502 |
root |
1.78 |
max_outstanding (int maxreqs) |
503 |
root |
1.1 |
PROTOTYPE: $ |
504 |
root |
1.78 |
CODE: |
505 |
|
|
max_outstanding = maxreqs; |
506 |
root |
1.1 |
|
507 |
|
|
void |
508 |
root |
1.99 |
aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
509 |
root |
1.8 |
PROTOTYPE: $$$;$ |
510 |
root |
1.43 |
PPCODE: |
511 |
root |
1.1 |
{ |
512 |
root |
1.22 |
dREQ; |
513 |
root |
1.1 |
|
514 |
root |
1.115 |
req->type = EIO_OPEN; |
515 |
root |
1.86 |
req->sv1 = newSVsv (pathname); |
516 |
root |
1.89 |
req->ptr1 = SvPVbyte_nolen (req->sv1); |
517 |
root |
1.86 |
req->int1 = flags; |
518 |
root |
1.115 |
req->int2 = mode; |
519 |
root |
1.1 |
|
520 |
root |
1.43 |
REQ_SEND; |
521 |
root |
1.1 |
} |
522 |
|
|
|
523 |
|
|
void |
524 |
root |
1.107 |
aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
525 |
root |
1.8 |
PROTOTYPE: $;$ |
526 |
root |
1.1 |
ALIAS: |
527 |
root |
1.115 |
aio_fsync = EIO_FSYNC |
528 |
|
|
aio_fdatasync = EIO_FDATASYNC |
529 |
root |
1.43 |
PPCODE: |
530 |
root |
1.1 |
{ |
531 |
root |
1.22 |
dREQ; |
532 |
root |
1.1 |
|
533 |
|
|
req->type = ix; |
534 |
root |
1.99 |
req->sv1 = newSVsv (fh); |
535 |
root |
1.86 |
req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
536 |
root |
1.1 |
|
537 |
root |
1.43 |
REQ_SEND (req); |
538 |
root |
1.1 |
} |
539 |
|
|
|
540 |
|
|
void |
541 |
root |
1.113 |
aio_close (SV *fh, SV *callback=&PL_sv_undef) |
542 |
root |
1.107 |
PROTOTYPE: $;$ |
543 |
|
|
PPCODE: |
544 |
|
|
{ |
545 |
root |
1.115 |
static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
546 |
root |
1.109 |
dREQ; |
547 |
root |
1.107 |
|
548 |
root |
1.115 |
if (close_pipe < 0) |
549 |
|
|
{ |
550 |
|
|
int pipefd [2]; |
551 |
|
|
|
552 |
|
|
if (pipe (pipefd) < 0 |
553 |
|
|
|| close (pipefd [1]) < 0 |
554 |
|
|
|| fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) |
555 |
|
|
abort (); /*D*/ |
556 |
|
|
|
557 |
|
|
close_pipe = pipefd [0]; |
558 |
|
|
} |
559 |
|
|
|
560 |
|
|
req->type = EIO_DUP2; |
561 |
|
|
req->int1 = close_pipe; |
562 |
|
|
req->sv2 = newSVsv (fh); |
563 |
|
|
req->int2 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
564 |
root |
1.107 |
|
565 |
root |
1.109 |
REQ_SEND (req); |
566 |
root |
1.107 |
} |
567 |
|
|
|
568 |
|
|
void |
569 |
root |
1.102 |
aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
570 |
root |
1.13 |
ALIAS: |
571 |
root |
1.115 |
aio_read = EIO_READ |
572 |
|
|
aio_write = EIO_WRITE |
573 |
root |
1.8 |
PROTOTYPE: $$$$$;$ |
574 |
root |
1.43 |
PPCODE: |
575 |
root |
1.13 |
{ |
576 |
|
|
STRLEN svlen; |
577 |
root |
1.21 |
char *svptr = SvPVbyte (data, svlen); |
578 |
root |
1.102 |
UV len = SvUV (length); |
579 |
root |
1.13 |
|
580 |
|
|
SvUPGRADE (data, SVt_PV); |
581 |
|
|
SvPOK_on (data); |
582 |
root |
1.1 |
|
583 |
root |
1.13 |
if (dataoffset < 0) |
584 |
|
|
dataoffset += svlen; |
585 |
|
|
|
586 |
|
|
if (dataoffset < 0 || dataoffset > svlen) |
587 |
root |
1.102 |
croak ("dataoffset outside of data scalar"); |
588 |
root |
1.13 |
|
589 |
root |
1.115 |
if (ix == EIO_WRITE) |
590 |
root |
1.13 |
{ |
591 |
|
|
/* write: check length and adjust. */ |
592 |
root |
1.102 |
if (!SvOK (length) || len + dataoffset > svlen) |
593 |
|
|
len = svlen - dataoffset; |
594 |
root |
1.13 |
} |
595 |
|
|
else |
596 |
|
|
{ |
597 |
|
|
/* read: grow scalar as necessary */ |
598 |
root |
1.102 |
svptr = SvGROW (data, len + dataoffset + 1); |
599 |
root |
1.13 |
} |
600 |
|
|
|
601 |
root |
1.102 |
if (len < 0) |
602 |
root |
1.13 |
croak ("length must not be negative"); |
603 |
|
|
|
604 |
root |
1.22 |
{ |
605 |
|
|
dREQ; |
606 |
root |
1.13 |
|
607 |
root |
1.22 |
req->type = ix; |
608 |
root |
1.99 |
req->sv1 = newSVsv (fh); |
609 |
root |
1.115 |
req->int1 = PerlIO_fileno (ix == EIO_READ ? IoIFP (sv_2io (fh)) |
610 |
root |
1.86 |
: IoOFP (sv_2io (fh))); |
611 |
root |
1.101 |
req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
612 |
root |
1.102 |
req->size = len; |
613 |
root |
1.99 |
req->sv2 = SvREFCNT_inc (data); |
614 |
root |
1.115 |
req->ptr2 = (char *)svptr + dataoffset; |
615 |
root |
1.86 |
req->stroffset = dataoffset; |
616 |
root |
1.13 |
|
617 |
root |
1.28 |
if (!SvREADONLY (data)) |
618 |
|
|
{ |
619 |
|
|
SvREADONLY_on (data); |
620 |
root |
1.100 |
req->flags |= FLAG_SV2_RO_OFF; |
621 |
root |
1.28 |
} |
622 |
|
|
|
623 |
root |
1.43 |
REQ_SEND; |
624 |
root |
1.22 |
} |
625 |
root |
1.13 |
} |
626 |
root |
1.1 |
|
627 |
|
|
void |
628 |
root |
1.99 |
aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
629 |
root |
1.86 |
PROTOTYPE: $$;$ |
630 |
|
|
PPCODE: |
631 |
|
|
{ |
632 |
|
|
SV *data; |
633 |
|
|
dREQ; |
634 |
|
|
|
635 |
|
|
data = newSV (NAME_MAX); |
636 |
|
|
SvPOK_on (data); |
637 |
|
|
|
638 |
root |
1.115 |
req->type = EIO_READLINK; |
639 |
root |
1.99 |
req->sv1 = newSVsv (path); |
640 |
root |
1.115 |
req->ptr1 = SvPVbyte_nolen (req->sv1); |
641 |
root |
1.99 |
req->sv2 = data; |
642 |
root |
1.115 |
req->ptr2 = SvPVbyte_nolen (data); |
643 |
root |
1.86 |
|
644 |
|
|
REQ_SEND; |
645 |
|
|
} |
646 |
|
|
|
647 |
|
|
void |
648 |
root |
1.101 |
aio_sendfile (SV *out_fh, SV *in_fh, SV *in_offset, UV length, SV *callback=&PL_sv_undef) |
649 |
root |
1.32 |
PROTOTYPE: $$$$;$ |
650 |
root |
1.43 |
PPCODE: |
651 |
root |
1.32 |
{ |
652 |
|
|
dREQ; |
653 |
|
|
|
654 |
root |
1.115 |
req->type = EIO_SENDFILE; |
655 |
root |
1.99 |
req->sv1 = newSVsv (out_fh); |
656 |
root |
1.86 |
req->int1 = PerlIO_fileno (IoIFP (sv_2io (out_fh))); |
657 |
|
|
req->sv2 = newSVsv (in_fh); |
658 |
|
|
req->int2 = PerlIO_fileno (IoIFP (sv_2io (in_fh))); |
659 |
root |
1.101 |
req->offs = SvVAL64 (in_offset); |
660 |
root |
1.86 |
req->size = length; |
661 |
root |
1.32 |
|
662 |
root |
1.43 |
REQ_SEND; |
663 |
root |
1.32 |
} |
664 |
|
|
|
665 |
|
|
void |
666 |
root |
1.101 |
aio_readahead (SV *fh, SV *offset, IV length, SV *callback=&PL_sv_undef) |
667 |
root |
1.8 |
PROTOTYPE: $$$;$ |
668 |
root |
1.43 |
PPCODE: |
669 |
root |
1.1 |
{ |
670 |
root |
1.22 |
dREQ; |
671 |
root |
1.1 |
|
672 |
root |
1.115 |
req->type = EIO_READAHEAD; |
673 |
root |
1.99 |
req->sv1 = newSVsv (fh); |
674 |
root |
1.86 |
req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
675 |
root |
1.101 |
req->offs = SvVAL64 (offset); |
676 |
root |
1.86 |
req->size = length; |
677 |
root |
1.1 |
|
678 |
root |
1.43 |
REQ_SEND; |
679 |
root |
1.1 |
} |
680 |
|
|
|
681 |
|
|
void |
682 |
root |
1.99 |
aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) |
683 |
root |
1.1 |
ALIAS: |
684 |
root |
1.115 |
aio_stat = EIO_STAT |
685 |
|
|
aio_lstat = EIO_LSTAT |
686 |
root |
1.43 |
PPCODE: |
687 |
root |
1.1 |
{ |
688 |
root |
1.22 |
dREQ; |
689 |
root |
1.1 |
|
690 |
root |
1.115 |
req->ptr2 = malloc (sizeof (EIO_STRUCT_STAT)); |
691 |
root |
1.87 |
if (!req->ptr2) |
692 |
root |
1.27 |
{ |
693 |
root |
1.101 |
req_destroy (req); |
694 |
root |
1.88 |
croak ("out of memory during aio_stat statdata allocation"); |
695 |
root |
1.27 |
} |
696 |
root |
1.1 |
|
697 |
root |
1.115 |
req->flags |= EIO_FLAG_PTR2_FREE; |
698 |
root |
1.99 |
req->sv1 = newSVsv (fh_or_path); |
699 |
root |
1.87 |
|
700 |
root |
1.1 |
if (SvPOK (fh_or_path)) |
701 |
|
|
{ |
702 |
root |
1.8 |
req->type = ix; |
703 |
root |
1.89 |
req->ptr1 = SvPVbyte_nolen (req->sv1); |
704 |
root |
1.1 |
} |
705 |
|
|
else |
706 |
|
|
{ |
707 |
root |
1.115 |
req->type = EIO_FSTAT; |
708 |
root |
1.86 |
req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
709 |
root |
1.1 |
} |
710 |
|
|
|
711 |
root |
1.43 |
REQ_SEND; |
712 |
root |
1.1 |
} |
713 |
|
|
|
714 |
|
|
void |
715 |
root |
1.99 |
aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
716 |
|
|
PPCODE: |
717 |
|
|
{ |
718 |
|
|
dREQ; |
719 |
|
|
|
720 |
|
|
req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; |
721 |
|
|
req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; |
722 |
|
|
req->sv1 = newSVsv (fh_or_path); |
723 |
|
|
|
724 |
|
|
if (SvPOK (fh_or_path)) |
725 |
|
|
{ |
726 |
root |
1.115 |
req->type = EIO_UTIME; |
727 |
root |
1.99 |
req->ptr1 = SvPVbyte_nolen (req->sv1); |
728 |
|
|
} |
729 |
|
|
else |
730 |
|
|
{ |
731 |
root |
1.115 |
req->type = EIO_FUTIME; |
732 |
root |
1.99 |
req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
733 |
|
|
} |
734 |
|
|
|
735 |
|
|
REQ_SEND; |
736 |
|
|
} |
737 |
|
|
|
738 |
|
|
void |
739 |
root |
1.103 |
aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) |
740 |
|
|
PPCODE: |
741 |
|
|
{ |
742 |
|
|
dREQ; |
743 |
|
|
|
744 |
|
|
req->sv1 = newSVsv (fh_or_path); |
745 |
|
|
req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
746 |
|
|
|
747 |
|
|
if (SvPOK (fh_or_path)) |
748 |
|
|
{ |
749 |
root |
1.115 |
req->type = EIO_TRUNCATE; |
750 |
root |
1.103 |
req->ptr1 = SvPVbyte_nolen (req->sv1); |
751 |
|
|
} |
752 |
|
|
else |
753 |
|
|
{ |
754 |
root |
1.115 |
req->type = EIO_FTRUNCATE; |
755 |
root |
1.103 |
req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
756 |
|
|
} |
757 |
|
|
|
758 |
|
|
REQ_SEND; |
759 |
|
|
} |
760 |
|
|
|
761 |
|
|
void |
762 |
root |
1.99 |
aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) |
763 |
root |
1.115 |
ALIAS: |
764 |
|
|
aio_chmod = EIO_CHMOD |
765 |
|
|
aio_fchmod = EIO_FCHMOD |
766 |
|
|
aio_mkdir = EIO_MKDIR |
767 |
root |
1.99 |
PPCODE: |
768 |
|
|
{ |
769 |
|
|
dREQ; |
770 |
|
|
|
771 |
root |
1.115 |
req->type = ix; |
772 |
|
|
req->int2 = mode; |
773 |
root |
1.99 |
req->sv1 = newSVsv (fh_or_path); |
774 |
|
|
|
775 |
root |
1.115 |
if (ix == EIO_FCHMOD) |
776 |
|
|
req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
777 |
root |
1.99 |
else |
778 |
root |
1.115 |
req->ptr1 = SvPVbyte_nolen (req->sv1); |
779 |
root |
1.99 |
|
780 |
|
|
REQ_SEND; |
781 |
|
|
} |
782 |
|
|
|
783 |
|
|
void |
784 |
|
|
aio_chown (SV8 *fh_or_path, SV *uid, SV *gid, SV *callback=&PL_sv_undef) |
785 |
|
|
PPCODE: |
786 |
|
|
{ |
787 |
|
|
dREQ; |
788 |
|
|
|
789 |
|
|
req->int2 = SvOK (uid) ? SvIV (uid) : -1; |
790 |
|
|
req->int3 = SvOK (gid) ? SvIV (gid) : -1; |
791 |
|
|
req->sv1 = newSVsv (fh_or_path); |
792 |
|
|
|
793 |
|
|
if (SvPOK (fh_or_path)) |
794 |
|
|
{ |
795 |
root |
1.115 |
req->type = EIO_CHOWN; |
796 |
root |
1.99 |
req->ptr1 = SvPVbyte_nolen (req->sv1); |
797 |
|
|
} |
798 |
|
|
else |
799 |
|
|
{ |
800 |
root |
1.115 |
req->type = EIO_FCHOWN; |
801 |
root |
1.99 |
req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
802 |
|
|
} |
803 |
|
|
|
804 |
|
|
REQ_SEND; |
805 |
|
|
} |
806 |
|
|
|
807 |
|
|
void |
808 |
|
|
aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
809 |
root |
1.22 |
ALIAS: |
810 |
root |
1.115 |
aio_unlink = EIO_UNLINK |
811 |
|
|
aio_rmdir = EIO_RMDIR |
812 |
|
|
aio_readdir = EIO_READDIR |
813 |
root |
1.43 |
PPCODE: |
814 |
root |
1.1 |
{ |
815 |
root |
1.22 |
dREQ; |
816 |
root |
1.1 |
|
817 |
root |
1.22 |
req->type = ix; |
818 |
root |
1.86 |
req->sv1 = newSVsv (pathname); |
819 |
root |
1.89 |
req->ptr1 = SvPVbyte_nolen (req->sv1); |
820 |
root |
1.87 |
|
821 |
root |
1.43 |
REQ_SEND; |
822 |
root |
1.22 |
} |
823 |
|
|
|
824 |
|
|
void |
825 |
root |
1.99 |
aio_link (SV8 *oldpath, SV8 *newpath, SV *callback=&PL_sv_undef) |
826 |
root |
1.40 |
ALIAS: |
827 |
root |
1.115 |
aio_link = EIO_LINK |
828 |
|
|
aio_symlink = EIO_SYMLINK |
829 |
|
|
aio_rename = EIO_RENAME |
830 |
root |
1.43 |
PPCODE: |
831 |
root |
1.22 |
{ |
832 |
|
|
dREQ; |
833 |
root |
1.1 |
|
834 |
root |
1.40 |
req->type = ix; |
835 |
root |
1.115 |
req->sv1 = newSVsv (oldpath); |
836 |
|
|
req->ptr1 = SvPVbyte_nolen (req->sv1); |
837 |
|
|
req->sv2 = newSVsv (newpath); |
838 |
root |
1.99 |
req->ptr2 = SvPVbyte_nolen (req->sv2); |
839 |
root |
1.1 |
|
840 |
root |
1.43 |
REQ_SEND; |
841 |
root |
1.1 |
} |
842 |
|
|
|
843 |
root |
1.42 |
void |
844 |
root |
1.99 |
aio_mknod (SV8 *pathname, int mode, UV dev, SV *callback=&PL_sv_undef) |
845 |
root |
1.81 |
PPCODE: |
846 |
|
|
{ |
847 |
|
|
dREQ; |
848 |
|
|
|
849 |
root |
1.115 |
req->type = EIO_MKNOD; |
850 |
root |
1.86 |
req->sv1 = newSVsv (pathname); |
851 |
root |
1.89 |
req->ptr1 = SvPVbyte_nolen (req->sv1); |
852 |
root |
1.115 |
req->int2 = (mode_t)mode; |
853 |
root |
1.86 |
req->offs = dev; |
854 |
root |
1.81 |
|
855 |
|
|
REQ_SEND; |
856 |
|
|
} |
857 |
|
|
|
858 |
|
|
void |
859 |
root |
1.99 |
aio_busy (double delay, SV *callback=&PL_sv_undef) |
860 |
root |
1.45 |
PPCODE: |
861 |
|
|
{ |
862 |
|
|
dREQ; |
863 |
|
|
|
864 |
root |
1.115 |
req->type = EIO_BUSY; |
865 |
root |
1.99 |
req->nv1 = delay < 0. ? 0. : delay; |
866 |
root |
1.45 |
|
867 |
|
|
REQ_SEND; |
868 |
|
|
} |
869 |
|
|
|
870 |
|
|
void |
871 |
root |
1.99 |
aio_group (SV *callback=&PL_sv_undef) |
872 |
root |
1.46 |
PROTOTYPE: ;$ |
873 |
root |
1.44 |
PPCODE: |
874 |
root |
1.42 |
{ |
875 |
root |
1.44 |
dREQ; |
876 |
root |
1.60 |
|
877 |
root |
1.115 |
req->type = EIO_GROUP; |
878 |
root |
1.86 |
|
879 |
root |
1.115 |
eio_submit (req); |
880 |
root |
1.44 |
XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
881 |
root |
1.42 |
} |
882 |
|
|
|
883 |
root |
1.6 |
void |
884 |
root |
1.99 |
aio_nop (SV *callback=&PL_sv_undef) |
885 |
root |
1.110 |
ALIAS: |
886 |
root |
1.115 |
aio_nop = EIO_NOP |
887 |
|
|
aio_sync = EIO_SYNC |
888 |
root |
1.54 |
PPCODE: |
889 |
|
|
{ |
890 |
|
|
dREQ; |
891 |
|
|
|
892 |
root |
1.110 |
req->type = ix; |
893 |
root |
1.54 |
|
894 |
|
|
REQ_SEND; |
895 |
|
|
} |
896 |
|
|
|
897 |
root |
1.79 |
int |
898 |
|
|
aioreq_pri (int pri = 0) |
899 |
|
|
PROTOTYPE: ;$ |
900 |
|
|
CODE: |
901 |
root |
1.115 |
RETVAL = next_pri - EIO_PRI_BIAS; |
902 |
root |
1.79 |
if (items > 0) |
903 |
|
|
{ |
904 |
root |
1.115 |
if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
905 |
|
|
if (pri > EIO_PRI_MAX) pri = EIO_PRI_MAX; |
906 |
|
|
next_pri = pri + EIO_PRI_BIAS; |
907 |
root |
1.79 |
} |
908 |
|
|
OUTPUT: |
909 |
|
|
RETVAL |
910 |
root |
1.68 |
|
911 |
|
|
void |
912 |
|
|
aioreq_nice (int nice = 0) |
913 |
root |
1.79 |
CODE: |
914 |
|
|
nice = next_pri - nice; |
915 |
root |
1.115 |
if (nice < EIO_PRI_MIN) nice = EIO_PRI_MIN; |
916 |
|
|
if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
917 |
|
|
next_pri = nice + EIO_PRI_BIAS; |
918 |
root |
1.60 |
|
919 |
root |
1.54 |
void |
920 |
root |
1.40 |
flush () |
921 |
root |
1.6 |
PROTOTYPE: |
922 |
|
|
CODE: |
923 |
|
|
while (nreqs) |
924 |
|
|
{ |
925 |
|
|
poll_wait (); |
926 |
root |
1.91 |
poll_cb (); |
927 |
root |
1.6 |
} |
928 |
|
|
|
929 |
root |
1.91 |
int |
930 |
root |
1.7 |
poll() |
931 |
|
|
PROTOTYPE: |
932 |
|
|
CODE: |
933 |
root |
1.92 |
poll_wait (); |
934 |
|
|
RETVAL = poll_cb (); |
935 |
root |
1.91 |
OUTPUT: |
936 |
|
|
RETVAL |
937 |
root |
1.7 |
|
938 |
root |
1.1 |
int |
939 |
|
|
poll_fileno() |
940 |
|
|
PROTOTYPE: |
941 |
|
|
CODE: |
942 |
root |
1.3 |
RETVAL = respipe [0]; |
943 |
root |
1.1 |
OUTPUT: |
944 |
|
|
RETVAL |
945 |
|
|
|
946 |
|
|
int |
947 |
|
|
poll_cb(...) |
948 |
|
|
PROTOTYPE: |
949 |
|
|
CODE: |
950 |
root |
1.85 |
RETVAL = poll_cb (); |
951 |
root |
1.1 |
OUTPUT: |
952 |
|
|
RETVAL |
953 |
|
|
|
954 |
|
|
void |
955 |
|
|
poll_wait() |
956 |
|
|
PROTOTYPE: |
957 |
|
|
CODE: |
958 |
root |
1.92 |
poll_wait (); |
959 |
root |
1.1 |
|
960 |
|
|
int |
961 |
|
|
nreqs() |
962 |
|
|
PROTOTYPE: |
963 |
|
|
CODE: |
964 |
root |
1.115 |
RETVAL = eio_nreqs (); |
965 |
root |
1.1 |
OUTPUT: |
966 |
|
|
RETVAL |
967 |
|
|
|
968 |
root |
1.79 |
int |
969 |
|
|
nready() |
970 |
|
|
PROTOTYPE: |
971 |
|
|
CODE: |
972 |
root |
1.115 |
RETVAL = eio_nready (); |
973 |
root |
1.79 |
OUTPUT: |
974 |
|
|
RETVAL |
975 |
|
|
|
976 |
|
|
int |
977 |
|
|
npending() |
978 |
|
|
PROTOTYPE: |
979 |
|
|
CODE: |
980 |
root |
1.115 |
RETVAL = eio_npending (); |
981 |
root |
1.79 |
OUTPUT: |
982 |
|
|
RETVAL |
983 |
|
|
|
984 |
root |
1.85 |
int |
985 |
|
|
nthreads() |
986 |
|
|
PROTOTYPE: |
987 |
|
|
CODE: |
988 |
root |
1.103 |
if (WORDACCESS_UNSAFE) X_LOCK (wrklock); |
989 |
root |
1.85 |
RETVAL = started; |
990 |
root |
1.103 |
if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock); |
991 |
root |
1.85 |
OUTPUT: |
992 |
|
|
RETVAL |
993 |
|
|
|
994 |
root |
1.48 |
PROTOTYPES: DISABLE |
995 |
|
|
|
996 |
root |
1.44 |
MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
997 |
root |
1.43 |
|
998 |
|
|
void |
999 |
|
|
cancel (aio_req_ornot req) |
1000 |
|
|
CODE: |
1001 |
root |
1.115 |
eio_cancel (req); |
1002 |
root |
1.45 |
|
1003 |
root |
1.56 |
void |
1004 |
root |
1.59 |
cb (aio_req_ornot req, SV *callback=&PL_sv_undef) |
1005 |
root |
1.56 |
CODE: |
1006 |
|
|
SvREFCNT_dec (req->callback); |
1007 |
|
|
req->callback = newSVsv (callback); |
1008 |
|
|
|
1009 |
root |
1.45 |
MODULE = IO::AIO PACKAGE = IO::AIO::GRP |
1010 |
|
|
|
1011 |
|
|
void |
1012 |
|
|
add (aio_req grp, ...) |
1013 |
|
|
PPCODE: |
1014 |
|
|
{ |
1015 |
|
|
int i; |
1016 |
root |
1.94 |
|
1017 |
root |
1.86 |
if (grp->int1 == 2) |
1018 |
root |
1.49 |
croak ("cannot add requests to IO::AIO::GRP after the group finished"); |
1019 |
|
|
|
1020 |
root |
1.45 |
for (i = 1; i < items; ++i ) |
1021 |
|
|
{ |
1022 |
root |
1.115 |
aio_req req; |
1023 |
|
|
|
1024 |
root |
1.46 |
if (GIMME_V != G_VOID) |
1025 |
|
|
XPUSHs (sv_2mortal (newSVsv (ST (i)))); |
1026 |
|
|
|
1027 |
root |
1.53 |
req = SvAIO_REQ (ST (i)); |
1028 |
root |
1.45 |
|
1029 |
root |
1.46 |
if (req) |
1030 |
root |
1.115 |
eio_grp_add (grp, req); |
1031 |
root |
1.45 |
} |
1032 |
|
|
} |
1033 |
root |
1.43 |
|
1034 |
root |
1.48 |
void |
1035 |
root |
1.72 |
cancel_subs (aio_req_ornot req) |
1036 |
|
|
CODE: |
1037 |
|
|
req_cancel_subs (req); |
1038 |
|
|
|
1039 |
|
|
void |
1040 |
root |
1.51 |
result (aio_req grp, ...) |
1041 |
|
|
CODE: |
1042 |
|
|
{ |
1043 |
|
|
int i; |
1044 |
root |
1.79 |
AV *av; |
1045 |
|
|
|
1046 |
|
|
grp->errorno = errno; |
1047 |
|
|
|
1048 |
|
|
av = newAV (); |
1049 |
root |
1.51 |
|
1050 |
|
|
for (i = 1; i < items; ++i ) |
1051 |
|
|
av_push (av, newSVsv (ST (i))); |
1052 |
|
|
|
1053 |
root |
1.86 |
SvREFCNT_dec (grp->sv1); |
1054 |
|
|
grp->sv1 = (SV *)av; |
1055 |
root |
1.51 |
} |
1056 |
|
|
|
1057 |
|
|
void |
1058 |
root |
1.79 |
errno (aio_req grp, int errorno = errno) |
1059 |
|
|
CODE: |
1060 |
|
|
grp->errorno = errorno; |
1061 |
|
|
|
1062 |
|
|
void |
1063 |
root |
1.67 |
limit (aio_req grp, int limit) |
1064 |
root |
1.49 |
CODE: |
1065 |
root |
1.115 |
eio_grp_limit (grp, limit); |
1066 |
root |
1.49 |
|
1067 |
|
|
void |
1068 |
root |
1.56 |
feed (aio_req grp, SV *callback=&PL_sv_undef) |
1069 |
root |
1.49 |
CODE: |
1070 |
|
|
{ |
1071 |
root |
1.86 |
SvREFCNT_dec (grp->sv2); |
1072 |
|
|
grp->sv2 = newSVsv (callback); |
1073 |
root |
1.49 |
|
1074 |
root |
1.86 |
if (grp->int2 <= 0) |
1075 |
|
|
grp->int2 = 2; |
1076 |
root |
1.49 |
|
1077 |
root |
1.115 |
eio_grp_limit (grp, grp->int2); |
1078 |
root |
1.49 |
} |
1079 |
|
|
|