… | |
… | |
3 | #include <errno.h> |
3 | #include <errno.h> |
4 | |
4 | |
5 | #include "EXTERN.h" |
5 | #include "EXTERN.h" |
6 | #include "perl.h" |
6 | #include "perl.h" |
7 | #include "XSUB.h" |
7 | #include "XSUB.h" |
|
|
8 | |
|
|
9 | #include "schmorp.h" |
8 | |
10 | |
9 | #include <stddef.h> |
11 | #include <stddef.h> |
10 | #include <stdlib.h> |
12 | #include <stdlib.h> |
11 | #include <errno.h> |
13 | #include <errno.h> |
12 | #include <sys/types.h> |
14 | #include <sys/types.h> |
13 | #include <sys/stat.h> |
15 | #include <sys/stat.h> |
14 | #include <limits.h> |
16 | #include <limits.h> |
15 | #include <fcntl.h> |
17 | #include <fcntl.h> |
16 | #include <sched.h> |
18 | #include <sched.h> |
17 | |
19 | |
|
|
20 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
|
|
21 | # include <sys/mman.h> |
|
|
22 | #endif |
|
|
23 | |
|
|
24 | /* perl namespace pollution */ |
|
|
25 | #undef VERSION |
|
|
26 | |
|
|
27 | /* perl stupidly overrides readdir and maybe others */ |
|
|
28 | /* with thread-unsafe versions, imagine that :( */ |
|
|
29 | #undef readdir |
|
|
30 | #undef opendir |
|
|
31 | #undef closedir |
|
|
32 | |
18 | #ifdef _WIN32 |
33 | #ifdef _WIN32 |
19 | |
34 | |
20 | # define EIO_STRUCT_DIRENT Direntry_t |
|
|
21 | # undef malloc |
|
|
22 | # undef free |
|
|
23 | |
|
|
24 | // perl overrides all those nice win32 functions |
35 | // perl overrides all those nice libc functions |
|
|
36 | |
|
|
37 | #undef malloc |
|
|
38 | #undef free |
25 | # undef open |
39 | #undef open |
26 | # undef read |
40 | #undef read |
27 | # undef write |
41 | #undef write |
28 | # undef send |
42 | #undef send |
29 | # undef recv |
43 | #undef recv |
30 | # undef stat |
44 | #undef stat |
|
|
45 | #undef lstat |
31 | # undef fstat |
46 | #undef fstat |
32 | # define lstat stat |
|
|
33 | # undef truncate |
47 | #undef truncate |
34 | # undef ftruncate |
48 | #undef ftruncate |
35 | # undef open |
49 | #undef open |
|
|
50 | #undef link |
36 | # undef close |
51 | #undef close |
37 | # undef unlink |
52 | #undef unlink |
|
|
53 | #undef mkdir |
38 | # undef rmdir |
54 | #undef rmdir |
39 | # undef rename |
55 | #undef rename |
40 | # undef lseek |
56 | #undef lseek |
41 | |
57 | #undef opendir |
42 | # define chown(a,b,c) (errno = ENOSYS, -1) |
58 | #undef readdir |
43 | # define fchown(a,b,c) (errno = ENOSYS, -1) |
59 | #undef closedir |
44 | # define fchmod(a,b) (errno = ENOSYS, -1) |
60 | #undef chmod |
45 | # define symlink(a,b) (errno = ENOSYS, -1) |
61 | #undef fchmod |
46 | # define readlink(a,b,c) (errno = ENOSYS, -1) |
62 | #undef dup |
47 | # define mknod(a,b,c) (errno = ENOSYS, -1) |
63 | #undef dup2 |
48 | # define truncate(a,b) (errno = ENOSYS, -1) |
64 | #undef abort |
49 | # define ftruncate(fd,o) chsize ((fd), (o)) |
65 | #undef pipe |
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 | |
66 | |
56 | #else |
67 | #else |
57 | |
68 | |
58 | # include <sys/time.h> |
69 | #include <sys/time.h> |
59 | # include <sys/select.h> |
70 | #include <sys/select.h> |
60 | # include <unistd.h> |
71 | #include <unistd.h> |
61 | # include <utime.h> |
72 | #include <utime.h> |
62 | # include <signal.h> |
73 | #include <signal.h> |
63 | # define EIO_STRUCT_DIRENT struct dirent |
|
|
64 | |
74 | |
65 | #endif |
75 | #endif |
66 | |
76 | |
67 | #define EIO_STRUCT_STAT Stat_t |
77 | #define EIO_STRUCT_STAT Stat_t |
68 | |
78 | |
69 | /* use NV for 32 bit perls as it allows larger offsets */ |
79 | /* use NV for 32 bit perls as it allows larger offsets */ |
70 | #if IVSIZE >= 8 |
80 | #if IVSIZE >= 8 |
|
|
81 | # define VAL64 IV |
71 | # define SvVAL64 SvIV |
82 | # define SvVAL64 SvIV |
|
|
83 | # define newSVval64 newSViv |
72 | #else |
84 | #else |
|
|
85 | # define VAL64 NV |
73 | # define SvVAL64 SvNV |
86 | # define SvVAL64 SvNV |
|
|
87 | # define newSVval64 newSVnv |
74 | #endif |
88 | #endif |
75 | |
89 | |
76 | static HV *stash; |
90 | /*****************************************************************************/ |
|
|
91 | |
|
|
92 | #if __GNUC__ >= 3 |
|
|
93 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
|
|
94 | #else |
|
|
95 | # define expect(expr,value) (expr) |
|
|
96 | #endif |
|
|
97 | |
|
|
98 | #define expect_false(expr) expect ((expr) != 0, 0) |
|
|
99 | #define expect_true(expr) expect ((expr) != 0, 1) |
|
|
100 | |
|
|
101 | /*****************************************************************************/ |
|
|
102 | |
77 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
103 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
|
|
104 | typedef int aio_rfd; /* read file desriptor */ |
|
|
105 | typedef int aio_wfd; /* write file descriptor */ |
78 | |
106 | |
79 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
107 | static HV *aio_stash, *aio_req_stash, *aio_grp_stash; |
80 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
|
|
81 | |
108 | |
82 | #define EIO_COMMON \ |
109 | #define EIO_REQ_MEMBERS \ |
83 | SV *callback; \ |
110 | SV *callback; \ |
84 | SV *sv1, *sv2; \ |
111 | SV *sv1, *sv2; \ |
85 | STRLEN stroffset; \ |
112 | STRLEN stroffset; \ |
86 | SV *self |
113 | SV *self; |
87 | |
114 | |
|
|
115 | #define EIO_NO_WRAPPERS 1 |
|
|
116 | |
|
|
117 | #include "libeio/config.h" |
88 | #include "libeio/eio.h" |
118 | #include "libeio/eio.h" |
89 | |
119 | |
90 | static int req_invoke (eio_req *req); |
120 | static int req_invoke (eio_req *req); |
91 | #define EIO_FINISH(req) req_invoke (req) |
121 | #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); |
122 | static void req_destroy (eio_req *grp); |
95 | #define EIO_DESTROY(req) req_destroy (req) |
123 | #define EIO_DESTROY(req) req_destroy (req) |
|
|
124 | |
|
|
125 | #include "libeio/eio.c" |
|
|
126 | |
|
|
127 | /* Linux/others */ |
|
|
128 | #ifndef O_ASYNC |
|
|
129 | # define O_ASYNC 0 |
|
|
130 | #endif |
|
|
131 | #ifndef O_DIRECT |
|
|
132 | # define O_DIRECT 0 |
|
|
133 | #endif |
|
|
134 | #ifndef O_NOATIME |
|
|
135 | # define O_NOATIME 0 |
|
|
136 | #endif |
|
|
137 | |
|
|
138 | /* POSIX */ |
|
|
139 | #ifndef O_CLOEXEC |
|
|
140 | # define O_CLOEXEC 0 |
|
|
141 | #endif |
|
|
142 | #ifndef O_NOFOLLOW |
|
|
143 | # define O_NOFOLLOW 0 |
|
|
144 | #endif |
|
|
145 | #ifndef O_NOCTTY |
|
|
146 | # define O_NOCTTY 0 |
|
|
147 | #endif |
|
|
148 | #ifndef O_NONBLOCK |
|
|
149 | # define O_NONBLOCK 0 |
|
|
150 | #endif |
|
|
151 | #ifndef O_EXEC |
|
|
152 | # define O_EXEC 0 |
|
|
153 | #endif |
|
|
154 | #ifndef O_SEARCH |
|
|
155 | # define O_SEARCH 0 |
|
|
156 | #endif |
|
|
157 | #ifndef O_DIRECTORY |
|
|
158 | # define O_DIRECTORY 0 |
|
|
159 | #endif |
|
|
160 | #ifndef O_DSYNC |
|
|
161 | # define O_DSYNC 0 |
|
|
162 | #endif |
|
|
163 | #ifndef O_RSYNC |
|
|
164 | # define O_RSYNC 0 |
|
|
165 | #endif |
|
|
166 | #ifndef O_SYNC |
|
|
167 | # define O_SYNC 0 |
|
|
168 | #endif |
|
|
169 | #ifndef O_TTY_INIT |
|
|
170 | # define O_TTY_INIT 0 |
|
|
171 | #endif |
|
|
172 | |
|
|
173 | #ifndef POSIX_FADV_NORMAL |
|
|
174 | # define POSIX_FADV_NORMAL 0 |
|
|
175 | #endif |
|
|
176 | #ifndef POSIX_FADV_SEQUENTIAL |
|
|
177 | # define POSIX_FADV_SEQUENTIAL 0 |
|
|
178 | #endif |
|
|
179 | #ifndef POSIX_FADV_RANDOM |
|
|
180 | # define POSIX_FADV_RANDOM 0 |
|
|
181 | #endif |
|
|
182 | #ifndef POSIX_FADV_NOREUSE |
|
|
183 | # define POSIX_FADV_NOREUSE 0 |
|
|
184 | #endif |
|
|
185 | #ifndef POSIX_FADV_WILLNEED |
|
|
186 | # define POSIX_FADV_WILLNEED 0 |
|
|
187 | #endif |
|
|
188 | #ifndef POSIX_FADV_DONTNEED |
|
|
189 | # define POSIX_FADV_DONTNEED 0 |
|
|
190 | #endif |
|
|
191 | |
|
|
192 | #if !HAVE_POSIX_FADVISE |
|
|
193 | # define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */ |
|
|
194 | #endif |
|
|
195 | |
|
|
196 | #ifndef POSIX_MADV_NORMAL |
|
|
197 | # define POSIX_MADV_NORMAL 0 |
|
|
198 | #endif |
|
|
199 | #ifndef POSIX_MADV_SEQUENTIAL |
|
|
200 | # define POSIX_MADV_SEQUENTIAL 0 |
|
|
201 | #endif |
|
|
202 | #ifndef POSIX_MADV_RANDOM |
|
|
203 | # define POSIX_MADV_RANDOM 0 |
|
|
204 | #endif |
|
|
205 | #ifndef POSIX_MADV_WILLNEED |
|
|
206 | # define POSIX_MADV_WILLNEED 0 |
|
|
207 | #endif |
|
|
208 | #ifndef POSIX_MADV_DONTNEED |
|
|
209 | # define POSIX_MADV_DONTNEED 0 |
|
|
210 | #endif |
|
|
211 | |
|
|
212 | #if !HAVE_POSIX_MADVISE |
|
|
213 | # define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ |
|
|
214 | #endif |
|
|
215 | |
|
|
216 | #ifndef PROT_NONE |
|
|
217 | # define PROT_NONE 0 |
|
|
218 | #endif |
|
|
219 | #ifndef PROT_READ |
|
|
220 | # define PROT_READ 0 |
|
|
221 | #endif |
|
|
222 | #ifndef PROT_WRITE |
|
|
223 | # define PROT_READ 0 |
|
|
224 | #endif |
|
|
225 | #ifndef PROT_EXEC |
|
|
226 | # define PROT_EXEC 0 |
|
|
227 | #endif |
|
|
228 | |
|
|
229 | #ifndef ST_RDONLY |
|
|
230 | # define ST_RDONLY 0 |
|
|
231 | #endif |
|
|
232 | #ifndef ST_NOSUID |
|
|
233 | # define ST_NOSUID 0 |
|
|
234 | #endif |
|
|
235 | #ifndef ST_NODEV |
|
|
236 | # define ST_NODEV 0 |
|
|
237 | #endif |
|
|
238 | #ifndef ST_NOEXEC |
|
|
239 | # define ST_NOEXEC 0 |
|
|
240 | #endif |
|
|
241 | #ifndef ST_SYNCHRONOUS |
|
|
242 | # define ST_SYNCHRONOUS 0 |
|
|
243 | #endif |
|
|
244 | #ifndef ST_MANDLOCK |
|
|
245 | # define ST_MANDLOCK 0 |
|
|
246 | #endif |
|
|
247 | #ifndef ST_WRITE |
|
|
248 | # define ST_WRITE 0 |
|
|
249 | #endif |
|
|
250 | #ifndef ST_APPEND |
|
|
251 | # define ST_APPEND 0 |
|
|
252 | #endif |
|
|
253 | #ifndef ST_IMMUTABLE |
|
|
254 | # define ST_IMMUTABLE 0 |
|
|
255 | #endif |
|
|
256 | #ifndef ST_NOATIME |
|
|
257 | # define ST_NOATIME 0 |
|
|
258 | #endif |
|
|
259 | #ifndef ST_NODIRATIME |
|
|
260 | # define ST_NODIRATIME 0 |
|
|
261 | #endif |
|
|
262 | #ifndef ST_RELATIME |
|
|
263 | # define ST_RELATIME 0 |
|
|
264 | #endif |
|
|
265 | |
|
|
266 | #ifndef S_IFIFO |
|
|
267 | # define S_IFIFO 0 |
|
|
268 | #endif |
|
|
269 | #ifndef S_IFCHR |
|
|
270 | # define S_IFCHR 0 |
|
|
271 | #endif |
|
|
272 | #ifndef S_IFBLK |
|
|
273 | # define S_IFBLK 0 |
|
|
274 | #endif |
|
|
275 | #ifndef S_IFLNK |
|
|
276 | # define S_IFLNK 0 |
|
|
277 | #endif |
|
|
278 | #ifndef S_IFREG |
|
|
279 | # define S_IFREG 0 |
|
|
280 | #endif |
|
|
281 | #ifndef S_IFDIR |
|
|
282 | # define S_IFDIR 0 |
|
|
283 | #endif |
|
|
284 | #ifndef S_IFWHT |
|
|
285 | # define S_IFWHT 0 |
|
|
286 | #endif |
|
|
287 | #ifndef S_IFSOCK |
|
|
288 | # define S_IFSOCK 0 |
|
|
289 | #endif |
|
|
290 | |
|
|
291 | #ifndef MAP_ANONYMOUS |
|
|
292 | # ifdef MAP_ANON |
|
|
293 | # define MAP_ANONYMOUS MAP_ANON |
|
|
294 | # else |
|
|
295 | # define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ |
|
|
296 | # endif |
|
|
297 | #endif |
|
|
298 | #ifndef MAP_HUGETLB |
|
|
299 | # define MAP_HUGETLB 0 |
|
|
300 | #endif |
|
|
301 | #ifndef MAP_LOCKED |
|
|
302 | # define MAP_LOCKED 0 |
|
|
303 | #endif |
|
|
304 | #ifndef MAP_NORESERVE |
|
|
305 | # define MAP_NORESERVE 0 |
|
|
306 | #endif |
|
|
307 | #ifndef MAP_POPULATE |
|
|
308 | # define MAP_POPULATE 0 |
|
|
309 | #endif |
|
|
310 | #ifndef MAP_NONBLOCK |
|
|
311 | # define MAP_NONBLOCK 0 |
|
|
312 | #endif |
|
|
313 | |
|
|
314 | #ifndef makedev |
|
|
315 | # define makedev(maj,min) (((maj) << 8) | (min)) |
|
|
316 | #endif |
|
|
317 | #ifndef major |
|
|
318 | # define major(dev) ((dev) >> 8) |
|
|
319 | #endif |
|
|
320 | #ifndef minor |
|
|
321 | # define minor(dev) ((dev) & 0xff) |
|
|
322 | #endif |
|
|
323 | |
|
|
324 | #ifndef PAGESIZE |
|
|
325 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
|
|
326 | #endif |
96 | |
327 | |
97 | enum { |
328 | enum { |
98 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
329 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
99 | }; |
330 | }; |
100 | |
331 | |
101 | #include "libeio/eio.c" |
|
|
102 | |
|
|
103 | typedef eio_req *aio_req; |
332 | typedef eio_req *aio_req; |
104 | typedef eio_req *aio_req_ornot; |
333 | typedef eio_req *aio_req_ornot; |
105 | |
334 | |
|
|
335 | static SV *on_next_submit; |
|
|
336 | static int next_pri = EIO_PRI_DEFAULT; |
106 | static int max_outstanding = 0; |
337 | static int max_outstanding; |
107 | |
338 | |
108 | static int next_pri = EIO_DEFAULT_PRI + EIO_PRI_BIAS; |
339 | static s_epipe respipe; |
109 | |
|
|
110 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
|
|
111 | |
340 | |
112 | static void req_destroy (aio_req req); |
341 | static void req_destroy (aio_req req); |
113 | static void req_cancel (aio_req req); |
342 | static void req_cancel (aio_req req); |
114 | |
343 | |
115 | static void want_poll (void) |
344 | static void want_poll (void) |
116 | { |
345 | { |
117 | /* write a dummy byte to the pipe so fh becomes ready */ |
346 | /* write a dummy byte to the pipe so fh becomes ready */ |
118 | respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); |
347 | s_epipe_signal (&respipe); |
119 | } |
348 | } |
120 | |
349 | |
121 | static void done_poll (void) |
350 | static void done_poll (void) |
122 | { |
351 | { |
123 | /* read any signals sent by the worker threads */ |
352 | /* read any signals sent by the worker threads */ |
124 | char buf [4]; |
353 | s_epipe_drain (&respipe); |
125 | while (respipe_read (respipe [0], buf, 4) == 4) |
|
|
126 | ; |
|
|
127 | } |
354 | } |
128 | |
355 | |
129 | /* must be called at most once */ |
356 | /* must be called at most once */ |
130 | static SV *req_sv (aio_req req, const char *klass) |
357 | static SV *req_sv (aio_req req, HV *stash) |
131 | { |
358 | { |
132 | if (!req->self) |
359 | if (!req->self) |
133 | { |
360 | { |
134 | req->self = (SV *)newHV (); |
361 | req->self = (SV *)newHV (); |
135 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
362 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
136 | } |
363 | } |
137 | |
364 | |
138 | return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1))); |
365 | return sv_2mortal (sv_bless (newRV_inc (req->self), stash)); |
139 | } |
366 | } |
140 | |
367 | |
141 | static aio_req SvAIO_REQ (SV *sv) |
368 | static aio_req SvAIO_REQ (SV *sv) |
142 | { |
369 | { |
143 | MAGIC *mg; |
370 | MAGIC *mg; |
144 | |
371 | |
145 | if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv)) |
372 | if (!SvROK (sv) |
|
|
373 | || (SvSTASH (SvRV (sv)) != aio_grp_stash |
|
|
374 | && SvSTASH (SvRV (sv)) != aio_req_stash |
|
|
375 | && !sv_derived_from (sv, "IO::AIO::REQ"))) |
146 | croak ("object of class " AIO_REQ_KLASS " expected"); |
376 | croak ("object of class IO::AIO::REQ expected"); |
147 | |
377 | |
148 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
378 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
149 | |
379 | |
150 | return mg ? (aio_req)mg->mg_ptr : 0; |
380 | return mg ? (aio_req)mg->mg_ptr : 0; |
151 | } |
381 | } |
… | |
… | |
157 | dSP; |
387 | dSP; |
158 | |
388 | |
159 | ENTER; |
389 | ENTER; |
160 | SAVETMPS; |
390 | SAVETMPS; |
161 | PUSHMARK (SP); |
391 | PUSHMARK (SP); |
162 | XPUSHs (req_sv (grp, AIO_GRP_KLASS)); |
392 | XPUSHs (req_sv (grp, aio_grp_stash)); |
163 | PUTBACK; |
393 | PUTBACK; |
164 | call_sv (grp->sv2, G_VOID | G_EVAL | G_KEEPERR); |
394 | call_sv (grp->sv2, G_VOID | G_EVAL | G_KEEPERR); |
165 | SPAGAIN; |
395 | SPAGAIN; |
166 | FREETMPS; |
396 | FREETMPS; |
167 | LEAVE; |
397 | LEAVE; |
168 | } |
398 | } |
169 | } |
399 | } |
170 | |
400 | |
|
|
401 | static void req_submit (eio_req *req) |
|
|
402 | { |
|
|
403 | eio_submit (req); |
|
|
404 | |
|
|
405 | if (expect_false (on_next_submit)) |
|
|
406 | { |
|
|
407 | dSP; |
|
|
408 | SV *cb = sv_2mortal (on_next_submit); |
|
|
409 | |
|
|
410 | on_next_submit = 0; |
|
|
411 | |
|
|
412 | PUSHMARK (SP); |
|
|
413 | PUTBACK; |
|
|
414 | call_sv (cb, G_DISCARD | G_EVAL); |
|
|
415 | } |
|
|
416 | } |
|
|
417 | |
171 | static int req_invoke (eio_req *req) |
418 | static int req_invoke (eio_req *req) |
172 | { |
419 | { |
173 | dSP; |
|
|
174 | |
|
|
175 | if (req->flags & FLAG_SV2_RO_OFF) |
420 | if (req->flags & FLAG_SV2_RO_OFF) |
176 | SvREADONLY_off (req->sv2); |
421 | SvREADONLY_off (req->sv2); |
177 | |
422 | |
178 | if (!EIO_CANCELLED (req) && SvOK (req->callback)) |
423 | if (!EIO_CANCELLED (req) && req->callback) |
179 | { |
424 | { |
|
|
425 | dSP; |
|
|
426 | static SV *sv_result_cache; /* caches the result integer SV */ |
|
|
427 | SV *sv_result; |
|
|
428 | |
180 | ENTER; |
429 | ENTER; |
181 | SAVETMPS; |
430 | SAVETMPS; |
182 | PUSHMARK (SP); |
431 | PUSHMARK (SP); |
183 | EXTEND (SP, 1); |
432 | EXTEND (SP, 1); |
|
|
433 | |
|
|
434 | /* do not recreate the result IV from scratch each time */ |
|
|
435 | if (expect_true (sv_result_cache)) |
|
|
436 | { |
|
|
437 | sv_result = sv_result_cache; sv_result_cache = 0; |
|
|
438 | SvIV_set (sv_result, req->result); |
|
|
439 | SvIOK_only (sv_result); |
|
|
440 | } |
|
|
441 | else |
|
|
442 | { |
|
|
443 | sv_result = newSViv (req->result); |
|
|
444 | SvREADONLY_on (sv_result); |
|
|
445 | } |
184 | |
446 | |
185 | switch (req->type) |
447 | switch (req->type) |
186 | { |
448 | { |
187 | case EIO_READDIR: |
449 | case EIO_READDIR: |
188 | { |
450 | { |
189 | SV *rv = &PL_sv_undef; |
451 | SV *rv = &PL_sv_undef; |
190 | |
452 | |
191 | if (req->result >= 0) |
453 | if (req->result >= 0) |
192 | { |
454 | { |
193 | int i; |
455 | int i; |
194 | char *buf = req->ptr2; |
456 | char *names = (char *)req->ptr2; |
|
|
457 | eio_dirent *ent = (eio_dirent *)req->ptr1; /* might be 0 */ |
195 | AV *av = newAV (); |
458 | AV *av = newAV (); |
196 | |
459 | |
197 | av_extend (av, req->result - 1); |
460 | av_extend (av, req->result - 1); |
198 | |
461 | |
199 | for (i = 0; i < req->result; ++i) |
462 | for (i = 0; i < req->result; ++i) |
200 | { |
463 | { |
201 | SV *sv = newSVpv (buf, 0); |
464 | if (req->int1 & EIO_READDIR_DENTS) |
|
|
465 | { |
|
|
466 | SV *namesv = newSVpvn (names + ent->nameofs, ent->namelen); |
202 | |
467 | |
|
|
468 | if (req->int1 & EIO_READDIR_CUSTOM2) |
|
|
469 | { |
|
|
470 | static SV *sv_type [EIO_DT_MAX + 1]; /* type sv cache */ |
|
|
471 | AV *avent = newAV (); |
|
|
472 | |
|
|
473 | av_extend (avent, 2); |
|
|
474 | |
|
|
475 | if (!sv_type [ent->type]) |
|
|
476 | { |
|
|
477 | sv_type [ent->type] = newSViv (ent->type); |
|
|
478 | SvREADONLY_on (sv_type [ent->type]); |
|
|
479 | } |
|
|
480 | |
|
|
481 | av_store (avent, 0, namesv); |
|
|
482 | av_store (avent, 1, SvREFCNT_inc (sv_type [ent->type])); |
|
|
483 | av_store (avent, 2, IVSIZE >= 8 ? newSVuv (ent->inode) : newSVnv (ent->inode)); |
|
|
484 | |
|
|
485 | av_store (av, i, newRV_noinc ((SV *)avent)); |
|
|
486 | } |
|
|
487 | else |
203 | av_store (av, i, sv); |
488 | av_store (av, i, namesv); |
|
|
489 | |
|
|
490 | ++ent; |
|
|
491 | } |
|
|
492 | else |
|
|
493 | { |
|
|
494 | SV *name = newSVpv (names, 0); |
|
|
495 | av_store (av, i, name); |
204 | buf += SvCUR (sv) + 1; |
496 | names += SvCUR (name) + 1; |
|
|
497 | } |
205 | } |
498 | } |
206 | |
499 | |
207 | rv = sv_2mortal (newRV_noinc ((SV *)av)); |
500 | rv = sv_2mortal (newRV_noinc ((SV *)av)); |
208 | } |
501 | } |
209 | |
502 | |
210 | PUSHs (rv); |
503 | PUSHs (rv); |
|
|
504 | |
|
|
505 | if (req->int1 & EIO_READDIR_CUSTOM1) |
|
|
506 | XPUSHs (sv_2mortal (newSViv (req->int1 & ~(EIO_READDIR_CUSTOM1 | EIO_READDIR_CUSTOM2)))); |
211 | } |
507 | } |
212 | break; |
508 | break; |
213 | |
509 | |
214 | case EIO_OPEN: |
510 | case EIO_OPEN: |
215 | { |
511 | { |
… | |
… | |
221 | GV *gv = (GV *)sv_newmortal (); |
517 | GV *gv = (GV *)sv_newmortal (); |
222 | int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR); |
518 | int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR); |
223 | char sym [64]; |
519 | char sym [64]; |
224 | int symlen; |
520 | int symlen; |
225 | |
521 | |
226 | symlen = snprintf (sym, sizeof (sym), "fd#%d", req->result); |
522 | symlen = snprintf (sym, sizeof (sym), "fd#%d", (int)req->result); |
227 | gv_init (gv, stash, sym, symlen, 0); |
523 | gv_init (gv, aio_stash, sym, symlen, 0); |
228 | |
524 | |
229 | symlen = snprintf ( |
525 | symlen = snprintf ( |
230 | sym, |
526 | sym, |
231 | sizeof (sym), |
527 | sizeof (sym), |
232 | "%s&=%d", |
528 | "%s&=%d", |
233 | flags == O_RDONLY ? "<" : flags == O_WRONLY ? ">" : "+<", |
529 | flags == O_RDONLY ? "<" : flags == O_WRONLY ? ">" : "+<", |
234 | req->result |
530 | (int)req->result |
235 | ); |
531 | ); |
236 | |
532 | |
237 | if (do_open (gv, sym, symlen, 0, 0, 0, 0)) |
533 | if (do_open (gv, sym, symlen, 0, 0, 0, 0)) |
238 | fh = (SV *)gv; |
534 | fh = (SV *)gv; |
239 | } |
535 | } |
240 | |
536 | |
241 | PUSHs (fh); |
537 | PUSHs (fh); |
242 | } |
538 | } |
|
|
539 | break; |
|
|
540 | |
|
|
541 | case EIO_STATVFS: |
|
|
542 | case EIO_FSTATVFS: |
|
|
543 | { |
|
|
544 | SV *rv = &PL_sv_undef; |
|
|
545 | |
|
|
546 | #ifndef _WIN32 |
|
|
547 | if (req->result >= 0) |
|
|
548 | { |
|
|
549 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
|
|
550 | HV *hv = newHV (); |
|
|
551 | |
|
|
552 | rv = sv_2mortal (newRV_noinc ((SV *)hv)); |
|
|
553 | |
|
|
554 | hv_store (hv, "bsize" , sizeof ("bsize" ) - 1, newSVval64 (f->f_bsize ), 0); |
|
|
555 | hv_store (hv, "frsize" , sizeof ("frsize" ) - 1, newSVval64 (f->f_frsize ), 0); |
|
|
556 | hv_store (hv, "blocks" , sizeof ("blocks" ) - 1, newSVval64 (f->f_blocks ), 0); |
|
|
557 | hv_store (hv, "bfree" , sizeof ("bfree" ) - 1, newSVval64 (f->f_bfree ), 0); |
|
|
558 | hv_store (hv, "bavail" , sizeof ("bavail" ) - 1, newSVval64 (f->f_bavail ), 0); |
|
|
559 | hv_store (hv, "files" , sizeof ("files" ) - 1, newSVval64 (f->f_files ), 0); |
|
|
560 | hv_store (hv, "ffree" , sizeof ("ffree" ) - 1, newSVval64 (f->f_ffree ), 0); |
|
|
561 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
|
|
562 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
|
|
563 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
|
|
564 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
|
|
565 | } |
|
|
566 | #endif |
|
|
567 | |
|
|
568 | PUSHs (rv); |
|
|
569 | } |
|
|
570 | |
243 | break; |
571 | break; |
244 | |
572 | |
245 | case EIO_GROUP: |
573 | case EIO_GROUP: |
246 | req->int1 = 2; /* mark group as finished */ |
574 | req->int1 = 2; /* mark group as finished */ |
247 | |
575 | |
… | |
… | |
259 | case EIO_NOP: |
587 | case EIO_NOP: |
260 | case EIO_BUSY: |
588 | case EIO_BUSY: |
261 | break; |
589 | break; |
262 | |
590 | |
263 | case EIO_READLINK: |
591 | case EIO_READLINK: |
|
|
592 | case EIO_REALPATH: |
264 | if (req->result > 0) |
593 | if (req->result > 0) |
265 | { |
594 | PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); |
266 | SvCUR_set (req->sv2, req->result); |
|
|
267 | *SvEND (req->sv2) = 0; |
|
|
268 | PUSHs (req->sv2); |
|
|
269 | } |
|
|
270 | break; |
595 | break; |
271 | |
596 | |
272 | case EIO_STAT: |
597 | case EIO_STAT: |
273 | case EIO_LSTAT: |
598 | case EIO_LSTAT: |
274 | case EIO_FSTAT: |
599 | case EIO_FSTAT: |
275 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
600 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
276 | PL_laststatval = req->result; |
601 | PL_laststatval = req->result; |
|
|
602 | /* if compilation fails here then perl's Stat_t is not struct _stati64 */ |
277 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
603 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
278 | PUSHs (sv_2mortal (newSViv (req->result))); |
604 | PUSHs (sv_result); |
279 | break; |
605 | break; |
280 | |
606 | |
281 | case EIO_READ: |
607 | case EIO_READ: |
|
|
608 | { |
282 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
609 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
283 | *SvEND (req->sv2) = 0; |
610 | *SvEND (req->sv2) = 0; |
284 | PUSHs (sv_2mortal (newSViv (req->result))); |
611 | SvPOK_only (req->sv2); |
|
|
612 | SvSETMAGIC (req->sv2); |
|
|
613 | PUSHs (sv_result); |
|
|
614 | } |
285 | break; |
615 | break; |
286 | |
616 | |
287 | case EIO_DUP2: |
617 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), so fudge result value */ |
288 | if (req->result > 0) |
618 | if (req->result > 0) |
289 | req->result = 0; |
619 | SvIV_set (sv_result, 0); |
290 | /* FALLTHROUGH */ |
620 | /* FALLTHROUGH */ |
291 | |
621 | |
292 | default: |
622 | default: |
293 | PUSHs (sv_2mortal (newSViv (req->result))); |
623 | PUSHs (sv_result); |
294 | break; |
624 | break; |
295 | } |
625 | } |
296 | |
626 | |
297 | errno = req->errorno; |
627 | errno = req->errorno; |
298 | |
628 | |
299 | PUTBACK; |
629 | PUTBACK; |
300 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
630 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
301 | SPAGAIN; |
631 | SPAGAIN; |
|
|
632 | |
|
|
633 | if (expect_false (SvREFCNT (sv_result) != 1 || sv_result_cache)) |
|
|
634 | SvREFCNT_dec (sv_result); |
|
|
635 | else |
|
|
636 | sv_result_cache = sv_result; |
302 | |
637 | |
303 | FREETMPS; |
638 | FREETMPS; |
304 | LEAVE; |
639 | LEAVE; |
305 | |
640 | |
306 | PUTBACK; |
641 | PUTBACK; |
… | |
… | |
324 | Safefree (req); |
659 | Safefree (req); |
325 | } |
660 | } |
326 | |
661 | |
327 | static void req_cancel_subs (aio_req grp) |
662 | static void req_cancel_subs (aio_req grp) |
328 | { |
663 | { |
329 | aio_req sub; |
|
|
330 | |
|
|
331 | if (grp->type != EIO_GROUP) |
664 | if (grp->type != EIO_GROUP) |
332 | return; |
665 | return; |
333 | |
666 | |
334 | SvREFCNT_dec (grp->sv2); |
667 | SvREFCNT_dec (grp->sv2); |
335 | grp->sv2 = 0; |
668 | grp->sv2 = 0; |
336 | |
669 | |
337 | eio_grp_cancel (grp); |
670 | eio_grp_cancel (grp); |
338 | } |
671 | } |
339 | |
672 | |
340 | #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 | create_respipe (void) |
673 | static void create_respipe (void) |
348 | { |
674 | { |
349 | 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)) |
675 | if (s_epipe_renew (&respipe)) |
358 | #endif |
|
|
359 | croak ("unable to initialize result pipe"); |
676 | croak ("IO::AIO: 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 | #ifdef _WIN32 |
|
|
371 | int arg = 1; |
|
|
372 | if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) |
|
|
373 | || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) |
|
|
374 | #else |
|
|
375 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) |
|
|
376 | || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
377 | #endif |
|
|
378 | croak ("unable to initialize result pipe(3)"); |
|
|
379 | |
|
|
380 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
|
|
381 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
|
|
382 | } |
677 | } |
383 | |
678 | |
384 | static void poll_wait (void) |
679 | static void poll_wait (void) |
385 | { |
680 | { |
386 | fd_set rfd; |
|
|
387 | |
|
|
388 | while (eio_nreqs ()) |
681 | while (eio_nreqs ()) |
389 | { |
682 | { |
390 | int size; |
683 | int size; |
391 | |
684 | |
392 | X_LOCK (reslock); |
685 | X_LOCK (reslock); |
… | |
… | |
394 | X_UNLOCK (reslock); |
687 | X_UNLOCK (reslock); |
395 | |
688 | |
396 | if (size) |
689 | if (size) |
397 | return; |
690 | return; |
398 | |
691 | |
399 | maybe_start_thread (); |
692 | etp_maybe_start_thread (); |
400 | |
693 | |
401 | FD_ZERO (&rfd); |
694 | s_epipe_wait (&respipe); |
402 | FD_SET (respipe [0], &rfd); |
|
|
403 | |
|
|
404 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
405 | } |
695 | } |
406 | } |
696 | } |
407 | |
697 | |
408 | static int poll_cb (void) |
698 | static int poll_cb (void) |
409 | { |
699 | { |
410 | int res; |
700 | for (;;) |
411 | |
|
|
412 | do |
|
|
413 | { |
701 | { |
414 | res = eio_poll (); |
702 | int res = eio_poll (); |
415 | |
703 | |
416 | if (res > 0) |
704 | if (res > 0) |
417 | croak (0); |
705 | croak (0); |
|
|
706 | |
|
|
707 | if (!max_outstanding || max_outstanding > eio_nreqs ()) |
|
|
708 | return res; |
|
|
709 | |
|
|
710 | poll_wait (); |
418 | } |
711 | } |
419 | while (max_outstanding && max_outstanding <= eio_nreqs ()); |
|
|
420 | |
|
|
421 | return res; |
|
|
422 | } |
712 | } |
423 | |
713 | |
424 | static void atfork_child (void) |
714 | static void ecb_cold |
|
|
715 | reinit (void) |
425 | { |
716 | { |
426 | create_respipe (); |
717 | create_respipe (); |
|
|
718 | |
|
|
719 | if (eio_init (want_poll, done_poll) < 0) |
|
|
720 | croak ("IO::AIO: unable to initialise eio library"); |
|
|
721 | } |
|
|
722 | |
|
|
723 | /*****************************************************************************/ |
|
|
724 | |
|
|
725 | #if !_POSIX_MAPPED_FILES |
|
|
726 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
|
|
727 | # define munmap(addr,length) (errno = ENOSYS, -1) |
|
|
728 | #endif |
|
|
729 | |
|
|
730 | #if !_POSIX_MEMORY_PROTECTION |
|
|
731 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
|
|
732 | # define PROT_NONE 0 |
|
|
733 | # define PROT_WRITE 0 |
|
|
734 | # define MAP_PRIVATE 0 |
|
|
735 | # define MAP_SHARED 0 |
|
|
736 | # define MAP_FIXED 0 |
|
|
737 | #endif |
|
|
738 | |
|
|
739 | #define MMAP_MAGIC PERL_MAGIC_ext |
|
|
740 | |
|
|
741 | static int mmap_free (pTHX_ SV *sv, MAGIC *mg) |
|
|
742 | { |
|
|
743 | int old_errno = errno; |
|
|
744 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
|
|
745 | errno = old_errno; |
|
|
746 | |
|
|
747 | mg->mg_obj = 0; /* just in case */ |
|
|
748 | |
|
|
749 | SvREADONLY_off (sv); |
|
|
750 | |
|
|
751 | if (SvPVX (sv) != mg->mg_ptr) |
|
|
752 | croak ("ERROR: IO::AIO::mmap-mapped scalar changed location, detected"); |
|
|
753 | |
|
|
754 | SvCUR_set (sv, 0); |
|
|
755 | SvPVX (sv) = 0; |
|
|
756 | SvOK_off (sv); |
|
|
757 | |
|
|
758 | return 0; |
|
|
759 | } |
|
|
760 | |
|
|
761 | static MGVTBL mmap_vtbl = { |
|
|
762 | 0, 0, 0, 0, mmap_free |
|
|
763 | }; |
|
|
764 | |
|
|
765 | /*****************************************************************************/ |
|
|
766 | |
|
|
767 | static SV * get_cb (SV *cb_sv) |
|
|
768 | { |
|
|
769 | SvGETMAGIC (cb_sv); |
|
|
770 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
427 | } |
771 | } |
428 | |
772 | |
429 | #define dREQ \ |
773 | #define dREQ \ |
|
|
774 | SV *cb_cv; \ |
430 | aio_req req; \ |
775 | aio_req req; \ |
431 | int req_pri = next_pri; \ |
776 | int req_pri = next_pri; \ |
432 | next_pri = EIO_DEFAULT_PRI + EIO_PRI_BIAS; \ |
777 | next_pri = EIO_PRI_DEFAULT; \ |
433 | \ |
778 | \ |
434 | if (SvOK (callback) && !SvROK (callback)) \ |
779 | cb_cv = get_cb (callback); \ |
435 | croak ("callback must be undef or of reference type"); \ |
|
|
436 | \ |
780 | \ |
437 | Newz (0, req, 1, eio_req); \ |
781 | Newz (0, req, 1, eio_req); \ |
438 | if (!req) \ |
782 | if (!req) \ |
439 | croak ("out of memory during eio_req allocation"); \ |
783 | croak ("out of memory during eio_req allocation"); \ |
440 | \ |
784 | \ |
441 | req->callback = newSVsv (callback); \ |
785 | req->callback = SvREFCNT_inc (cb_cv); \ |
442 | req->pri = req_pri |
786 | req->pri = req_pri |
443 | |
787 | |
444 | #define REQ_SEND \ |
788 | #define REQ_SEND \ |
|
|
789 | PUTBACK; \ |
445 | eio_submit (req); \ |
790 | req_submit (req); \ |
|
|
791 | SPAGAIN; \ |
446 | \ |
792 | \ |
447 | if (GIMME_V != G_VOID) \ |
793 | if (GIMME_V != G_VOID) \ |
448 | XPUSHs (req_sv (req, AIO_REQ_KLASS)); |
794 | XPUSHs (req_sv (req, aio_req_stash)); |
449 | |
795 | |
450 | MODULE = IO::AIO PACKAGE = IO::AIO |
796 | MODULE = IO::AIO PACKAGE = IO::AIO |
451 | |
797 | |
452 | PROTOTYPES: ENABLE |
798 | PROTOTYPES: ENABLE |
453 | |
799 | |
454 | BOOT: |
800 | BOOT: |
455 | { |
801 | { |
|
|
802 | static const struct { |
|
|
803 | const char *name; |
|
|
804 | IV iv; |
|
|
805 | } *civ, const_iv[] = { |
|
|
806 | # define const_niv(name, value) { # name, (IV) value }, |
|
|
807 | # define const_iv(name) { # name, (IV) name }, |
|
|
808 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
|
|
809 | const_iv (EXDEV) |
|
|
810 | const_iv (ENOSYS) |
|
|
811 | const_iv (O_RDONLY) |
|
|
812 | const_iv (O_WRONLY) |
|
|
813 | const_iv (O_RDWR) |
|
|
814 | const_iv (O_CREAT) |
|
|
815 | const_iv (O_TRUNC) |
|
|
816 | const_iv (O_EXCL) |
|
|
817 | const_iv (O_APPEND) |
|
|
818 | |
|
|
819 | const_iv (O_ASYNC) |
|
|
820 | const_iv (O_DIRECT) |
|
|
821 | const_iv (O_NOATIME) |
|
|
822 | |
|
|
823 | const_iv (O_CLOEXEC) |
|
|
824 | const_iv (O_NOCTTY) |
|
|
825 | const_iv (O_NOFOLLOW) |
|
|
826 | const_iv (O_NONBLOCK) |
|
|
827 | const_iv (O_EXEC) |
|
|
828 | const_iv (O_SEARCH) |
|
|
829 | const_iv (O_DIRECTORY) |
|
|
830 | const_iv (O_DSYNC) |
|
|
831 | const_iv (O_RSYNC) |
|
|
832 | const_iv (O_SYNC) |
|
|
833 | const_iv (O_TTY_INIT) |
|
|
834 | |
|
|
835 | const_iv (S_IFIFO) |
|
|
836 | const_iv (S_IFCHR) |
|
|
837 | const_iv (S_IFBLK) |
|
|
838 | const_iv (S_IFLNK) |
|
|
839 | const_iv (S_IFREG) |
|
|
840 | const_iv (S_IFDIR) |
|
|
841 | const_iv (S_IFWHT) |
|
|
842 | const_iv (S_IFSOCK) |
|
|
843 | const_iv (S_IFMT) |
|
|
844 | |
|
|
845 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
|
|
846 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
|
|
847 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
|
|
848 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
|
|
849 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
|
|
850 | const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
|
|
851 | |
|
|
852 | const_niv (MADV_NORMAL , POSIX_MADV_NORMAL) |
|
|
853 | const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL) |
|
|
854 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
|
|
855 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
|
|
856 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
|
|
857 | |
|
|
858 | const_iv (ST_RDONLY) |
|
|
859 | const_iv (ST_NOSUID) |
|
|
860 | const_iv (ST_NODEV) |
|
|
861 | const_iv (ST_NOEXEC) |
|
|
862 | const_iv (ST_SYNCHRONOUS) |
|
|
863 | const_iv (ST_MANDLOCK) |
|
|
864 | const_iv (ST_WRITE) |
|
|
865 | const_iv (ST_APPEND) |
|
|
866 | const_iv (ST_IMMUTABLE) |
|
|
867 | const_iv (ST_NOATIME) |
|
|
868 | const_iv (ST_NODIRATIME) |
|
|
869 | const_iv (ST_RELATIME) |
|
|
870 | |
|
|
871 | const_iv (PROT_NONE) |
|
|
872 | const_iv (PROT_EXEC) |
|
|
873 | const_iv (PROT_READ) |
|
|
874 | const_iv (PROT_WRITE) |
|
|
875 | |
|
|
876 | /*const_iv (MAP_FIXED)*/ |
|
|
877 | const_iv (MAP_PRIVATE) |
|
|
878 | const_iv (MAP_SHARED) |
|
|
879 | const_iv (MAP_ANONYMOUS) |
|
|
880 | |
|
|
881 | /* linuxish */ |
|
|
882 | const_iv (MAP_HUGETLB) |
|
|
883 | const_iv (MAP_LOCKED) |
|
|
884 | const_iv (MAP_NORESERVE) |
|
|
885 | const_iv (MAP_POPULATE) |
|
|
886 | const_iv (MAP_NONBLOCK) |
|
|
887 | |
|
|
888 | const_eio (MCL_FUTURE) |
|
|
889 | const_eio (MCL_CURRENT) |
|
|
890 | |
|
|
891 | const_eio (MS_ASYNC) |
|
|
892 | const_eio (MS_INVALIDATE) |
|
|
893 | const_eio (MS_SYNC) |
|
|
894 | |
|
|
895 | const_eio (MT_MODIFY) |
|
|
896 | |
|
|
897 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
|
|
898 | const_eio (SYNC_FILE_RANGE_WRITE) |
|
|
899 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
|
|
900 | |
|
|
901 | const_eio (FALLOC_FL_KEEP_SIZE) |
|
|
902 | |
|
|
903 | const_eio (READDIR_DENTS) |
|
|
904 | const_eio (READDIR_DIRS_FIRST) |
|
|
905 | const_eio (READDIR_STAT_ORDER) |
|
|
906 | const_eio (READDIR_FOUND_UNKNOWN) |
|
|
907 | |
|
|
908 | const_eio (DT_UNKNOWN) |
|
|
909 | const_eio (DT_FIFO) |
|
|
910 | const_eio (DT_CHR) |
|
|
911 | const_eio (DT_DIR) |
|
|
912 | const_eio (DT_BLK) |
|
|
913 | const_eio (DT_REG) |
|
|
914 | const_eio (DT_LNK) |
|
|
915 | const_eio (DT_SOCK) |
|
|
916 | const_eio (DT_WHT) |
|
|
917 | }; |
|
|
918 | |
456 | stash = gv_stashpv ("IO::AIO", 1); |
919 | aio_stash = gv_stashpv ("IO::AIO" , 1); |
|
|
920 | aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); |
|
|
921 | aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); |
457 | |
922 | |
458 | newCONSTSUB (stash, "EXDEV", newSViv (EXDEV)); |
923 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
459 | newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY)); |
924 | newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); |
460 | newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY)); |
|
|
461 | newCONSTSUB (stash, "O_CREAT", newSViv (O_CREAT)); |
|
|
462 | newCONSTSUB (stash, "O_TRUNC", newSViv (O_TRUNC)); |
|
|
463 | #ifdef _WIN32 |
|
|
464 | X_MUTEX_CHECK (wrklock); |
|
|
465 | X_MUTEX_CHECK (reslock); |
|
|
466 | X_MUTEX_CHECK (reqlock); |
|
|
467 | X_MUTEX_CHECK (reqwait); |
|
|
468 | X_MUTEX_CHECK (preadwritelock); |
|
|
469 | X_MUTEX_CHECK (readdirlock); |
|
|
470 | |
925 | |
471 | X_COND_CHECK (reqwait); |
926 | newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); |
472 | #else |
|
|
473 | newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO)); |
|
|
474 | #endif |
|
|
475 | |
927 | |
476 | create_respipe (); |
928 | reinit (); |
477 | |
|
|
478 | if (eio_init (want_poll, done_poll) < 0) |
|
|
479 | croak ("IO::AIO: unable to initialise eio library"); |
|
|
480 | |
|
|
481 | /* atfork child called in fifo order, so before eio's handler */ |
|
|
482 | X_THREAD_ATFORK (0, 0, atfork_child); |
|
|
483 | } |
929 | } |
484 | |
930 | |
485 | void |
931 | void |
|
|
932 | reinit () |
|
|
933 | PROTOTYPE: |
|
|
934 | CODE: |
|
|
935 | reinit (); |
|
|
936 | |
|
|
937 | void |
486 | max_poll_reqs (int nreqs) |
938 | max_poll_reqs (unsigned int nreqs) |
487 | PROTOTYPE: $ |
939 | PROTOTYPE: $ |
488 | CODE: |
940 | CODE: |
489 | eio_set_max_poll_reqs (nreqs); |
941 | eio_set_max_poll_reqs (nreqs); |
490 | |
942 | |
491 | void |
943 | void |
… | |
… | |
493 | PROTOTYPE: $ |
945 | PROTOTYPE: $ |
494 | CODE: |
946 | CODE: |
495 | eio_set_max_poll_time (nseconds); |
947 | eio_set_max_poll_time (nseconds); |
496 | |
948 | |
497 | void |
949 | void |
498 | min_parallel (int nthreads) |
950 | min_parallel (unsigned int nthreads) |
499 | PROTOTYPE: $ |
951 | PROTOTYPE: $ |
500 | CODE: |
952 | CODE: |
501 | eio_set_min_parallel (nthreads); |
953 | eio_set_min_parallel (nthreads); |
502 | |
954 | |
503 | void |
955 | void |
504 | max_parallel (int nthreads) |
956 | max_parallel (unsigned int nthreads) |
505 | PROTOTYPE: $ |
957 | PROTOTYPE: $ |
506 | CODE: |
958 | CODE: |
507 | eio_set_max_parallel (nthreads); |
959 | eio_set_max_parallel (nthreads); |
508 | |
960 | |
509 | void |
961 | void |
510 | max_idle (int nthreads) |
962 | max_idle (unsigned int nthreads) |
511 | PROTOTYPE: $ |
963 | PROTOTYPE: $ |
512 | CODE: |
964 | CODE: |
513 | eio_set_max_idle (nthreads); |
965 | eio_set_max_idle (nthreads); |
514 | |
966 | |
515 | void |
967 | void |
|
|
968 | idle_timeout (unsigned int seconds) |
|
|
969 | PROTOTYPE: $ |
|
|
970 | CODE: |
|
|
971 | eio_set_idle_timeout (seconds); |
|
|
972 | |
|
|
973 | void |
516 | max_outstanding (int maxreqs) |
974 | max_outstanding (unsigned int maxreqs) |
517 | PROTOTYPE: $ |
975 | PROTOTYPE: $ |
518 | CODE: |
976 | CODE: |
519 | max_outstanding = maxreqs; |
977 | max_outstanding = maxreqs; |
520 | |
978 | |
521 | void |
979 | void |
522 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
980 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
523 | PROTOTYPE: $$$;$ |
|
|
524 | PPCODE: |
981 | PPCODE: |
525 | { |
982 | { |
526 | dREQ; |
983 | dREQ; |
527 | |
984 | |
528 | req->type = EIO_OPEN; |
985 | req->type = EIO_OPEN; |
… | |
… | |
534 | REQ_SEND; |
991 | REQ_SEND; |
535 | } |
992 | } |
536 | |
993 | |
537 | void |
994 | void |
538 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
995 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
539 | PROTOTYPE: $;$ |
|
|
540 | ALIAS: |
996 | ALIAS: |
541 | aio_fsync = EIO_FSYNC |
997 | aio_fsync = EIO_FSYNC |
542 | aio_fdatasync = EIO_FDATASYNC |
998 | aio_fdatasync = EIO_FDATASYNC |
|
|
999 | aio_syncfs = EIO_SYNCFS |
543 | PPCODE: |
1000 | PPCODE: |
544 | { |
1001 | { |
|
|
1002 | int fd = s_fileno_croak (fh, 0); |
545 | dREQ; |
1003 | dREQ; |
546 | |
1004 | |
547 | req->type = ix; |
1005 | req->type = ix; |
548 | req->sv1 = newSVsv (fh); |
1006 | req->sv1 = newSVsv (fh); |
549 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
1007 | req->int1 = fd; |
550 | |
1008 | |
551 | REQ_SEND (req); |
1009 | REQ_SEND (req); |
552 | } |
1010 | } |
553 | |
1011 | |
554 | void |
1012 | void |
|
|
1013 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
|
|
1014 | PPCODE: |
|
|
1015 | { |
|
|
1016 | int fd = s_fileno_croak (fh, 0); |
|
|
1017 | dREQ; |
|
|
1018 | |
|
|
1019 | req->type = EIO_SYNC_FILE_RANGE; |
|
|
1020 | req->sv1 = newSVsv (fh); |
|
|
1021 | req->int1 = fd; |
|
|
1022 | req->offs = offset; |
|
|
1023 | req->size = nbytes; |
|
|
1024 | req->int2 = flags; |
|
|
1025 | |
|
|
1026 | REQ_SEND (req); |
|
|
1027 | } |
|
|
1028 | |
|
|
1029 | void |
|
|
1030 | aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) |
|
|
1031 | PPCODE: |
|
|
1032 | { |
|
|
1033 | int fd = s_fileno_croak (fh, 0); |
|
|
1034 | dREQ; |
|
|
1035 | |
|
|
1036 | req->type = EIO_FALLOCATE; |
|
|
1037 | req->sv1 = newSVsv (fh); |
|
|
1038 | req->int1 = fd; |
|
|
1039 | req->int2 = mode; |
|
|
1040 | req->offs = offset; |
|
|
1041 | req->size = len; |
|
|
1042 | |
|
|
1043 | REQ_SEND (req); |
|
|
1044 | } |
|
|
1045 | |
|
|
1046 | void |
555 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1047 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
556 | PROTOTYPE: $;$ |
|
|
557 | PPCODE: |
1048 | PPCODE: |
558 | { |
1049 | { |
559 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
1050 | static int close_fd = -1; /* dummy fd to close fds via dup2 */ |
|
|
1051 | int fd = s_fileno_croak (fh, 0); |
560 | dREQ; |
1052 | dREQ; |
561 | |
1053 | |
562 | if (close_pipe < 0) |
1054 | if (expect_false (close_fd < 0)) |
563 | { |
1055 | { |
564 | int pipefd [2]; |
1056 | int pipefd [2]; |
565 | |
1057 | |
|
|
1058 | if ( |
|
|
1059 | #ifdef _WIN32 |
|
|
1060 | _pipe (pipefd, 1, _O_BINARY) < 0 |
|
|
1061 | #else |
566 | if (pipe (pipefd) < 0 |
1062 | pipe (pipefd) < 0 |
567 | || close (pipefd [1]) < 0 |
|
|
568 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) |
1063 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0 |
|
|
1064 | #endif |
|
|
1065 | || close (pipefd [1]) < 0 |
|
|
1066 | ) |
569 | abort (); /*D*/ |
1067 | abort (); /*D*/ |
570 | |
1068 | |
571 | close_pipe = pipefd [0]; |
1069 | close_fd = pipefd [0]; |
572 | } |
1070 | } |
573 | |
1071 | |
574 | req->type = EIO_DUP2; |
1072 | req->type = EIO_DUP2; |
575 | req->int1 = close_pipe; |
1073 | req->int1 = close_fd; |
576 | req->sv2 = newSVsv (fh); |
1074 | req->sv2 = newSVsv (fh); |
577 | req->int2 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
1075 | req->int2 = fd; |
578 | |
1076 | |
579 | REQ_SEND (req); |
1077 | REQ_SEND (req); |
580 | } |
1078 | } |
581 | |
1079 | |
582 | void |
1080 | void |
583 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
1081 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
584 | ALIAS: |
1082 | ALIAS: |
585 | aio_read = EIO_READ |
1083 | aio_read = EIO_READ |
586 | aio_write = EIO_WRITE |
1084 | aio_write = EIO_WRITE |
587 | PROTOTYPE: $$$$$;$ |
|
|
588 | PPCODE: |
1085 | PPCODE: |
589 | { |
1086 | { |
590 | STRLEN svlen; |
1087 | STRLEN svlen; |
|
|
1088 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
591 | char *svptr = SvPVbyte (data, svlen); |
1089 | char *svptr = SvPVbyte (data, svlen); |
592 | UV len = SvUV (length); |
1090 | UV len = SvUV (length); |
593 | |
|
|
594 | SvUPGRADE (data, SVt_PV); |
|
|
595 | SvPOK_on (data); |
|
|
596 | |
1091 | |
597 | if (dataoffset < 0) |
1092 | if (dataoffset < 0) |
598 | dataoffset += svlen; |
1093 | dataoffset += svlen; |
599 | |
1094 | |
600 | if (dataoffset < 0 || dataoffset > svlen) |
1095 | if (dataoffset < 0 || dataoffset > svlen) |
… | |
… | |
606 | if (!SvOK (length) || len + dataoffset > svlen) |
1101 | if (!SvOK (length) || len + dataoffset > svlen) |
607 | len = svlen - dataoffset; |
1102 | len = svlen - dataoffset; |
608 | } |
1103 | } |
609 | else |
1104 | else |
610 | { |
1105 | { |
611 | /* read: grow scalar as necessary */ |
1106 | /* read: check type and grow scalar as necessary */ |
|
|
1107 | SvUPGRADE (data, SVt_PV); |
612 | svptr = SvGROW (data, len + dataoffset + 1); |
1108 | svptr = SvGROW (data, len + dataoffset + 1); |
613 | } |
1109 | } |
614 | |
1110 | |
615 | if (len < 0) |
|
|
616 | croak ("length must not be negative"); |
|
|
617 | |
|
|
618 | { |
1111 | { |
619 | dREQ; |
1112 | dREQ; |
620 | |
1113 | |
621 | req->type = ix; |
1114 | req->type = ix; |
622 | req->sv1 = newSVsv (fh); |
1115 | req->sv1 = newSVsv (fh); |
623 | req->int1 = PerlIO_fileno (ix == EIO_READ ? IoIFP (sv_2io (fh)) |
1116 | req->int1 = fd; |
624 | : IoOFP (sv_2io (fh))); |
|
|
625 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
1117 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
626 | req->size = len; |
1118 | req->size = len; |
627 | req->sv2 = SvREFCNT_inc (data); |
1119 | req->sv2 = SvREFCNT_inc (data); |
628 | req->ptr2 = (char *)svptr + dataoffset; |
1120 | req->ptr2 = (char *)svptr + dataoffset; |
629 | req->stroffset = dataoffset; |
1121 | req->stroffset = dataoffset; |
… | |
… | |
638 | } |
1130 | } |
639 | } |
1131 | } |
640 | |
1132 | |
641 | void |
1133 | void |
642 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
1134 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
643 | PROTOTYPE: $$;$ |
1135 | ALIAS: |
|
|
1136 | aio_readlink = EIO_READLINK |
|
|
1137 | aio_realpath = EIO_REALPATH |
644 | PPCODE: |
1138 | PPCODE: |
645 | { |
1139 | { |
646 | SV *data; |
|
|
647 | dREQ; |
1140 | dREQ; |
648 | |
1141 | |
649 | data = newSV (NAME_MAX); |
|
|
650 | SvPOK_on (data); |
|
|
651 | |
|
|
652 | req->type = EIO_READLINK; |
1142 | req->type = ix; |
653 | req->sv1 = newSVsv (path); |
1143 | req->sv1 = newSVsv (path); |
654 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1144 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
655 | req->sv2 = data; |
|
|
656 | req->ptr2 = SvPVbyte_nolen (data); |
|
|
657 | |
1145 | |
658 | REQ_SEND; |
1146 | REQ_SEND; |
659 | } |
1147 | } |
660 | |
1148 | |
661 | void |
1149 | void |
662 | aio_sendfile (SV *out_fh, SV *in_fh, SV *in_offset, UV length, SV *callback=&PL_sv_undef) |
1150 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
663 | PROTOTYPE: $$$$;$ |
|
|
664 | PPCODE: |
1151 | PPCODE: |
665 | { |
1152 | { |
|
|
1153 | int ifd = s_fileno_croak (in_fh , 0); |
|
|
1154 | int ofd = s_fileno_croak (out_fh, 1); |
666 | dREQ; |
1155 | dREQ; |
667 | |
1156 | |
668 | req->type = EIO_SENDFILE; |
1157 | req->type = EIO_SENDFILE; |
669 | req->sv1 = newSVsv (out_fh); |
1158 | req->sv1 = newSVsv (out_fh); |
670 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (out_fh))); |
1159 | req->int1 = ofd; |
671 | req->sv2 = newSVsv (in_fh); |
1160 | req->sv2 = newSVsv (in_fh); |
672 | req->int2 = PerlIO_fileno (IoIFP (sv_2io (in_fh))); |
1161 | req->int2 = ifd; |
673 | req->offs = SvVAL64 (in_offset); |
1162 | req->offs = in_offset; |
674 | req->size = length; |
1163 | req->size = length; |
675 | |
1164 | |
676 | REQ_SEND; |
1165 | REQ_SEND; |
677 | } |
1166 | } |
678 | |
1167 | |
679 | void |
1168 | void |
680 | aio_readahead (SV *fh, SV *offset, IV length, SV *callback=&PL_sv_undef) |
1169 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
681 | PROTOTYPE: $$$;$ |
|
|
682 | PPCODE: |
1170 | PPCODE: |
683 | { |
1171 | { |
|
|
1172 | int fd = s_fileno_croak (fh, 0); |
684 | dREQ; |
1173 | dREQ; |
685 | |
1174 | |
686 | req->type = EIO_READAHEAD; |
1175 | req->type = EIO_READAHEAD; |
687 | req->sv1 = newSVsv (fh); |
1176 | req->sv1 = newSVsv (fh); |
688 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
1177 | req->int1 = fd; |
689 | req->offs = SvVAL64 (offset); |
1178 | req->offs = offset; |
690 | req->size = length; |
1179 | req->size = length; |
691 | |
1180 | |
692 | REQ_SEND; |
1181 | REQ_SEND; |
693 | } |
1182 | } |
694 | |
1183 | |
695 | void |
1184 | void |
696 | aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) |
1185 | aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) |
697 | ALIAS: |
1186 | ALIAS: |
698 | aio_stat = EIO_STAT |
1187 | aio_stat = EIO_STAT |
699 | aio_lstat = EIO_LSTAT |
1188 | aio_lstat = EIO_LSTAT |
|
|
1189 | aio_statvfs = EIO_STATVFS |
700 | PPCODE: |
1190 | PPCODE: |
701 | { |
1191 | { |
702 | dREQ; |
1192 | dREQ; |
703 | |
1193 | |
704 | req->ptr2 = malloc (sizeof (EIO_STRUCT_STAT)); |
|
|
705 | if (!req->ptr2) |
|
|
706 | { |
|
|
707 | req_destroy (req); |
|
|
708 | croak ("out of memory during aio_stat statdata allocation"); |
|
|
709 | } |
|
|
710 | |
|
|
711 | req->flags |= EIO_FLAG_PTR2_FREE; |
|
|
712 | req->sv1 = newSVsv (fh_or_path); |
1194 | req->sv1 = newSVsv (fh_or_path); |
713 | |
1195 | |
714 | if (SvPOK (fh_or_path)) |
1196 | if (SvPOK (req->sv1)) |
715 | { |
1197 | { |
716 | req->type = ix; |
1198 | req->type = ix; |
717 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1199 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
718 | } |
1200 | } |
719 | else |
1201 | else |
720 | { |
1202 | { |
721 | req->type = EIO_FSTAT; |
1203 | req->type = ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT; |
722 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
1204 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
723 | } |
1205 | } |
724 | |
1206 | |
725 | REQ_SEND; |
1207 | REQ_SEND; |
726 | } |
1208 | } |
|
|
1209 | |
|
|
1210 | UV |
|
|
1211 | major (UV dev) |
|
|
1212 | ALIAS: |
|
|
1213 | minor = 1 |
|
|
1214 | CODE: |
|
|
1215 | RETVAL = ix ? major (dev) : minor (dev); |
|
|
1216 | OUTPUT: |
|
|
1217 | RETVAL |
|
|
1218 | |
|
|
1219 | UV |
|
|
1220 | makedev (UV maj, UV min) |
|
|
1221 | CODE: |
|
|
1222 | RETVAL = makedev (maj, min); |
|
|
1223 | OUTPUT: |
|
|
1224 | RETVAL |
727 | |
1225 | |
728 | void |
1226 | void |
729 | aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
1227 | aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
730 | PPCODE: |
1228 | PPCODE: |
731 | { |
1229 | { |
… | |
… | |
733 | |
1231 | |
734 | req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; |
1232 | req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; |
735 | req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; |
1233 | req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; |
736 | req->sv1 = newSVsv (fh_or_path); |
1234 | req->sv1 = newSVsv (fh_or_path); |
737 | |
1235 | |
738 | if (SvPOK (fh_or_path)) |
1236 | if (SvPOK (req->sv1)) |
739 | { |
1237 | { |
740 | req->type = EIO_UTIME; |
1238 | req->type = EIO_UTIME; |
741 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1239 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
742 | } |
1240 | } |
743 | else |
1241 | else |
… | |
… | |
756 | dREQ; |
1254 | dREQ; |
757 | |
1255 | |
758 | req->sv1 = newSVsv (fh_or_path); |
1256 | req->sv1 = newSVsv (fh_or_path); |
759 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
1257 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
760 | |
1258 | |
761 | if (SvPOK (fh_or_path)) |
1259 | if (SvPOK (req->sv1)) |
762 | { |
1260 | { |
763 | req->type = EIO_TRUNCATE; |
1261 | req->type = EIO_TRUNCATE; |
764 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1262 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
765 | } |
1263 | } |
766 | else |
1264 | else |
… | |
… | |
774 | |
1272 | |
775 | void |
1273 | void |
776 | aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) |
1274 | aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) |
777 | ALIAS: |
1275 | ALIAS: |
778 | aio_chmod = EIO_CHMOD |
1276 | aio_chmod = EIO_CHMOD |
779 | aio_fchmod = EIO_FCHMOD |
|
|
780 | aio_mkdir = EIO_MKDIR |
1277 | aio_mkdir = EIO_MKDIR |
781 | PPCODE: |
1278 | PPCODE: |
782 | { |
1279 | { |
783 | dREQ; |
1280 | dREQ; |
784 | |
1281 | |
785 | req->type = ix; |
|
|
786 | req->int2 = mode; |
1282 | req->int2 = mode; |
787 | req->sv1 = newSVsv (fh_or_path); |
1283 | req->sv1 = newSVsv (fh_or_path); |
788 | |
1284 | |
789 | if (ix == EIO_FCHMOD) |
1285 | if (SvPOK (req->sv1)) |
790 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
1286 | { |
|
|
1287 | req->type = ix; |
|
|
1288 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1289 | } |
791 | else |
1290 | else |
792 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1291 | { |
|
|
1292 | req->type = EIO_FCHMOD; |
|
|
1293 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1294 | } |
793 | |
1295 | |
794 | REQ_SEND; |
1296 | REQ_SEND; |
795 | } |
1297 | } |
796 | |
1298 | |
797 | void |
1299 | void |
… | |
… | |
802 | |
1304 | |
803 | req->int2 = SvOK (uid) ? SvIV (uid) : -1; |
1305 | req->int2 = SvOK (uid) ? SvIV (uid) : -1; |
804 | req->int3 = SvOK (gid) ? SvIV (gid) : -1; |
1306 | req->int3 = SvOK (gid) ? SvIV (gid) : -1; |
805 | req->sv1 = newSVsv (fh_or_path); |
1307 | req->sv1 = newSVsv (fh_or_path); |
806 | |
1308 | |
807 | if (SvPOK (fh_or_path)) |
1309 | if (SvPOK (req->sv1)) |
808 | { |
1310 | { |
809 | req->type = EIO_CHOWN; |
1311 | req->type = EIO_CHOWN; |
810 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1312 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
811 | } |
1313 | } |
812 | else |
1314 | else |
… | |
… | |
817 | |
1319 | |
818 | REQ_SEND; |
1320 | REQ_SEND; |
819 | } |
1321 | } |
820 | |
1322 | |
821 | void |
1323 | void |
|
|
1324 | aio_readdirx (SV8 *pathname, IV flags, SV *callback=&PL_sv_undef) |
|
|
1325 | PPCODE: |
|
|
1326 | { |
|
|
1327 | dREQ; |
|
|
1328 | |
|
|
1329 | req->type = EIO_READDIR; |
|
|
1330 | req->sv1 = newSVsv (pathname); |
|
|
1331 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1332 | req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; |
|
|
1333 | |
|
|
1334 | if (flags & EIO_READDIR_DENTS) |
|
|
1335 | req->int1 |= EIO_READDIR_CUSTOM2; |
|
|
1336 | |
|
|
1337 | REQ_SEND; |
|
|
1338 | } |
|
|
1339 | |
|
|
1340 | void |
822 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
1341 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
823 | ALIAS: |
1342 | ALIAS: |
824 | aio_unlink = EIO_UNLINK |
1343 | aio_unlink = EIO_UNLINK |
825 | aio_rmdir = EIO_RMDIR |
1344 | aio_rmdir = EIO_RMDIR |
826 | aio_readdir = EIO_READDIR |
1345 | aio_readdir = EIO_READDIR |
… | |
… | |
868 | |
1387 | |
869 | REQ_SEND; |
1388 | REQ_SEND; |
870 | } |
1389 | } |
871 | |
1390 | |
872 | void |
1391 | void |
|
|
1392 | aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) |
|
|
1393 | ALIAS: |
|
|
1394 | aio_mtouch = EIO_MTOUCH |
|
|
1395 | aio_msync = EIO_MSYNC |
|
|
1396 | PPCODE: |
|
|
1397 | { |
|
|
1398 | STRLEN svlen; |
|
|
1399 | char *svptr = SvPVbyte (data, svlen); |
|
|
1400 | UV len = SvUV (length); |
|
|
1401 | |
|
|
1402 | if (offset < 0) |
|
|
1403 | offset += svlen; |
|
|
1404 | |
|
|
1405 | if (offset < 0 || offset > svlen) |
|
|
1406 | croak ("offset outside of scalar"); |
|
|
1407 | |
|
|
1408 | if (!SvOK (length) || len + offset > svlen) |
|
|
1409 | len = svlen - offset; |
|
|
1410 | |
|
|
1411 | { |
|
|
1412 | dREQ; |
|
|
1413 | |
|
|
1414 | req->type = ix; |
|
|
1415 | req->sv2 = SvREFCNT_inc (data); |
|
|
1416 | req->ptr2 = (char *)svptr + offset; |
|
|
1417 | req->size = len; |
|
|
1418 | req->int1 = flags; |
|
|
1419 | |
|
|
1420 | REQ_SEND; |
|
|
1421 | } |
|
|
1422 | } |
|
|
1423 | |
|
|
1424 | void |
|
|
1425 | aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef) |
|
|
1426 | PPCODE: |
|
|
1427 | { |
|
|
1428 | STRLEN svlen; |
|
|
1429 | char *svptr = SvPVbyte (data, svlen); |
|
|
1430 | UV len = SvUV (length); |
|
|
1431 | |
|
|
1432 | if (offset < 0) |
|
|
1433 | offset += svlen; |
|
|
1434 | |
|
|
1435 | if (offset < 0 || offset > svlen) |
|
|
1436 | croak ("offset outside of scalar"); |
|
|
1437 | |
|
|
1438 | if (!SvOK (length) || len + offset > svlen) |
|
|
1439 | len = svlen - offset; |
|
|
1440 | |
|
|
1441 | { |
|
|
1442 | dREQ; |
|
|
1443 | |
|
|
1444 | req->type = EIO_MLOCK; |
|
|
1445 | req->sv2 = SvREFCNT_inc (data); |
|
|
1446 | req->ptr2 = (char *)svptr + offset; |
|
|
1447 | req->size = len; |
|
|
1448 | |
|
|
1449 | REQ_SEND; |
|
|
1450 | } |
|
|
1451 | } |
|
|
1452 | |
|
|
1453 | void |
|
|
1454 | aio_mlockall (IV flags, SV *callback=&PL_sv_undef) |
|
|
1455 | PPCODE: |
|
|
1456 | { |
|
|
1457 | dREQ; |
|
|
1458 | |
|
|
1459 | req->type = EIO_MLOCKALL; |
|
|
1460 | req->int1 = flags; |
|
|
1461 | |
|
|
1462 | REQ_SEND; |
|
|
1463 | } |
|
|
1464 | |
|
|
1465 | void |
873 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1466 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
874 | PPCODE: |
1467 | PPCODE: |
875 | { |
1468 | { |
876 | dREQ; |
1469 | dREQ; |
877 | |
1470 | |
… | |
… | |
881 | REQ_SEND; |
1474 | REQ_SEND; |
882 | } |
1475 | } |
883 | |
1476 | |
884 | void |
1477 | void |
885 | aio_group (SV *callback=&PL_sv_undef) |
1478 | aio_group (SV *callback=&PL_sv_undef) |
886 | PROTOTYPE: ;$ |
|
|
887 | PPCODE: |
1479 | PPCODE: |
888 | { |
1480 | { |
889 | dREQ; |
1481 | dREQ; |
890 | |
1482 | |
891 | req->type = EIO_GROUP; |
1483 | req->type = EIO_GROUP; |
892 | |
1484 | |
893 | eio_submit (req); |
1485 | req_submit (req); |
894 | XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
1486 | XPUSHs (req_sv (req, aio_grp_stash)); |
895 | } |
1487 | } |
896 | |
1488 | |
897 | void |
1489 | void |
898 | aio_nop (SV *callback=&PL_sv_undef) |
1490 | aio_nop (SV *callback=&PL_sv_undef) |
899 | ALIAS: |
1491 | ALIAS: |
… | |
… | |
908 | REQ_SEND; |
1500 | REQ_SEND; |
909 | } |
1501 | } |
910 | |
1502 | |
911 | int |
1503 | int |
912 | aioreq_pri (int pri = 0) |
1504 | aioreq_pri (int pri = 0) |
913 | PROTOTYPE: ;$ |
|
|
914 | CODE: |
1505 | CODE: |
915 | RETVAL = next_pri - EIO_PRI_BIAS; |
1506 | RETVAL = next_pri; |
916 | if (items > 0) |
1507 | if (items > 0) |
917 | { |
1508 | { |
918 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
1509 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
919 | if (pri > EIO_PRI_MAX) pri = EIO_PRI_MAX; |
1510 | if (pri > EIO_PRI_MAX) pri = EIO_PRI_MAX; |
920 | next_pri = pri + EIO_PRI_BIAS; |
1511 | next_pri = pri; |
921 | } |
1512 | } |
922 | OUTPUT: |
1513 | OUTPUT: |
923 | RETVAL |
1514 | RETVAL |
924 | |
1515 | |
925 | void |
1516 | void |
926 | aioreq_nice (int nice = 0) |
1517 | aioreq_nice (int nice = 0) |
927 | CODE: |
1518 | CODE: |
928 | nice = next_pri - nice; |
1519 | nice = next_pri - nice; |
929 | if (nice < EIO_PRI_MIN) nice = EIO_PRI_MIN; |
1520 | if (nice < EIO_PRI_MIN) nice = EIO_PRI_MIN; |
930 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1521 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
931 | next_pri = nice + EIO_PRI_BIAS; |
1522 | next_pri = nice; |
932 | |
1523 | |
933 | void |
1524 | void |
934 | flush () |
1525 | flush () |
935 | PROTOTYPE: |
|
|
936 | CODE: |
1526 | CODE: |
937 | while (eio_nreqs ()) |
1527 | while (eio_nreqs ()) |
938 | { |
1528 | { |
939 | poll_wait (); |
1529 | poll_wait (); |
940 | poll_cb (); |
1530 | poll_cb (); |
941 | } |
1531 | } |
942 | |
1532 | |
943 | int |
1533 | int |
944 | poll() |
1534 | poll () |
945 | PROTOTYPE: |
|
|
946 | CODE: |
1535 | CODE: |
947 | poll_wait (); |
1536 | poll_wait (); |
948 | RETVAL = poll_cb (); |
1537 | RETVAL = poll_cb (); |
949 | OUTPUT: |
1538 | OUTPUT: |
950 | RETVAL |
1539 | RETVAL |
951 | |
1540 | |
952 | int |
1541 | int |
953 | poll_fileno() |
1542 | poll_fileno () |
954 | PROTOTYPE: |
|
|
955 | CODE: |
1543 | CODE: |
956 | RETVAL = respipe [0]; |
1544 | RETVAL = s_epipe_fd (&respipe); |
957 | OUTPUT: |
1545 | OUTPUT: |
958 | RETVAL |
1546 | RETVAL |
959 | |
1547 | |
960 | int |
1548 | int |
961 | poll_cb(...) |
1549 | poll_cb (...) |
962 | PROTOTYPE: |
1550 | PROTOTYPE: |
963 | CODE: |
1551 | CODE: |
964 | RETVAL = poll_cb (); |
1552 | RETVAL = poll_cb (); |
965 | OUTPUT: |
1553 | OUTPUT: |
966 | RETVAL |
1554 | RETVAL |
967 | |
1555 | |
968 | void |
1556 | void |
969 | poll_wait() |
1557 | poll_wait () |
970 | PROTOTYPE: |
|
|
971 | CODE: |
1558 | CODE: |
972 | poll_wait (); |
1559 | poll_wait (); |
973 | |
1560 | |
974 | int |
1561 | int |
975 | nreqs() |
1562 | nreqs () |
976 | PROTOTYPE: |
|
|
977 | CODE: |
1563 | CODE: |
978 | RETVAL = eio_nreqs (); |
1564 | RETVAL = eio_nreqs (); |
979 | OUTPUT: |
1565 | OUTPUT: |
980 | RETVAL |
1566 | RETVAL |
981 | |
1567 | |
982 | int |
1568 | int |
983 | nready() |
1569 | nready () |
984 | PROTOTYPE: |
|
|
985 | CODE: |
1570 | CODE: |
986 | RETVAL = eio_nready (); |
1571 | RETVAL = eio_nready (); |
987 | OUTPUT: |
1572 | OUTPUT: |
988 | RETVAL |
1573 | RETVAL |
989 | |
1574 | |
990 | int |
1575 | int |
991 | npending() |
1576 | npending () |
992 | PROTOTYPE: |
|
|
993 | CODE: |
1577 | CODE: |
994 | RETVAL = eio_npending (); |
1578 | RETVAL = eio_npending (); |
995 | OUTPUT: |
1579 | OUTPUT: |
996 | RETVAL |
1580 | RETVAL |
997 | |
1581 | |
998 | int |
1582 | int |
999 | nthreads() |
1583 | nthreads () |
1000 | PROTOTYPE: |
|
|
1001 | CODE: |
1584 | CODE: |
1002 | if (WORDACCESS_UNSAFE) X_LOCK (wrklock); |
1585 | RETVAL = eio_nthreads (); |
1003 | RETVAL = started; |
|
|
1004 | if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock); |
|
|
1005 | OUTPUT: |
1586 | OUTPUT: |
1006 | RETVAL |
1587 | RETVAL |
1007 | |
1588 | |
|
|
1589 | int |
|
|
1590 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
|
|
1591 | CODE: |
|
|
1592 | RETVAL = posix_fadvise (fh, offset, length, advice); |
|
|
1593 | OUTPUT: |
|
|
1594 | RETVAL |
|
|
1595 | |
|
|
1596 | IV |
|
|
1597 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
|
|
1598 | CODE: |
|
|
1599 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
|
|
1600 | OUTPUT: |
|
|
1601 | RETVAL |
|
|
1602 | |
|
|
1603 | void |
|
|
1604 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) |
|
|
1605 | PPCODE: |
|
|
1606 | sv_unmagic (scalar, MMAP_MAGIC); |
|
|
1607 | { |
|
|
1608 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
|
|
1609 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
|
|
1610 | if (addr == (void *)-1) |
|
|
1611 | XSRETURN_NO; |
|
|
1612 | |
|
|
1613 | sv_force_normal (scalar); |
|
|
1614 | |
|
|
1615 | /* we store the length in mg_obj, as namlen is I32 :/ */ |
|
|
1616 | sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0) |
|
|
1617 | ->mg_obj = (SV *)length; |
|
|
1618 | |
|
|
1619 | SvUPGRADE (scalar, SVt_PV); /* nop... */ |
|
|
1620 | |
|
|
1621 | if (!(prot & PROT_WRITE)) |
|
|
1622 | SvREADONLY_on (scalar); |
|
|
1623 | |
|
|
1624 | if (SvLEN (scalar)) |
|
|
1625 | Safefree (SvPVX (scalar)); |
|
|
1626 | |
|
|
1627 | SvPVX (scalar) = (char *)addr; |
|
|
1628 | SvCUR_set (scalar, length); |
|
|
1629 | SvLEN_set (scalar, 0); |
|
|
1630 | SvPOK_only (scalar); |
|
|
1631 | |
|
|
1632 | XSRETURN_YES; |
|
|
1633 | } |
|
|
1634 | |
|
|
1635 | void |
|
|
1636 | munmap (SV *scalar) |
|
|
1637 | CODE: |
|
|
1638 | sv_unmagic (scalar, MMAP_MAGIC); |
|
|
1639 | |
|
|
1640 | int |
|
|
1641 | madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
|
|
1642 | ALIAS: |
|
|
1643 | mprotect = 1 |
|
|
1644 | CODE: |
|
|
1645 | { |
|
|
1646 | STRLEN svlen; |
|
|
1647 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1648 | size_t len = SvUV (length); |
|
|
1649 | |
|
|
1650 | if (offset < 0) |
|
|
1651 | offset += svlen; |
|
|
1652 | |
|
|
1653 | if (offset < 0 || offset > svlen) |
|
|
1654 | croak ("offset outside of scalar"); |
|
|
1655 | |
|
|
1656 | if (!SvOK (length) || len + offset > svlen) |
|
|
1657 | len = svlen - offset; |
|
|
1658 | |
|
|
1659 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1660 | eio_page_align (&addr, &len); |
|
|
1661 | |
|
|
1662 | switch (ix) |
|
|
1663 | { |
|
|
1664 | case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break; |
|
|
1665 | case 1: RETVAL = mprotect (addr, len, advice_or_prot); break; |
|
|
1666 | } |
|
|
1667 | } |
|
|
1668 | OUTPUT: |
|
|
1669 | RETVAL |
|
|
1670 | |
|
|
1671 | int |
|
|
1672 | munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) |
|
|
1673 | CODE: |
|
|
1674 | { |
|
|
1675 | STRLEN svlen; |
|
|
1676 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1677 | size_t len = SvUV (length); |
|
|
1678 | |
|
|
1679 | if (offset < 0) |
|
|
1680 | offset += svlen; |
|
|
1681 | |
|
|
1682 | if (offset < 0 || offset > svlen) |
|
|
1683 | croak ("offset outside of scalar"); |
|
|
1684 | |
|
|
1685 | if (!SvOK (length) || len + offset > svlen) |
|
|
1686 | len = svlen - offset; |
|
|
1687 | |
|
|
1688 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1689 | eio_page_align (&addr, &len); |
|
|
1690 | #if _POSIX_MEMLOCK_RANGE |
|
|
1691 | RETVAL = munlock (addr, len); |
|
|
1692 | #else |
|
|
1693 | RETVAL = ((errno = ENOSYS), -1); |
|
|
1694 | #endif |
|
|
1695 | } |
|
|
1696 | OUTPUT: |
|
|
1697 | RETVAL |
|
|
1698 | |
|
|
1699 | int |
|
|
1700 | munlockall () |
|
|
1701 | CODE: |
|
|
1702 | #if _POSIX_MEMLOCK |
|
|
1703 | munlockall (); |
|
|
1704 | #else |
|
|
1705 | RETVAL = -1; |
|
|
1706 | errno = ENOSYS; |
|
|
1707 | #endif |
|
|
1708 | OUTPUT: |
|
|
1709 | RETVAL |
|
|
1710 | |
|
|
1711 | void _on_next_submit (SV *cb) |
|
|
1712 | CODE: |
|
|
1713 | SvREFCNT_dec (on_next_submit); |
|
|
1714 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
|
|
1715 | |
1008 | PROTOTYPES: DISABLE |
1716 | PROTOTYPES: DISABLE |
1009 | |
1717 | |
1010 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1718 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1011 | |
1719 | |
1012 | void |
1720 | void |
… | |
… | |
1014 | CODE: |
1722 | CODE: |
1015 | eio_cancel (req); |
1723 | eio_cancel (req); |
1016 | |
1724 | |
1017 | void |
1725 | void |
1018 | cb (aio_req_ornot req, SV *callback=&PL_sv_undef) |
1726 | cb (aio_req_ornot req, SV *callback=&PL_sv_undef) |
1019 | CODE: |
1727 | PPCODE: |
|
|
1728 | { |
|
|
1729 | if (GIMME_V != G_VOID) |
|
|
1730 | XPUSHs (req->callback ? sv_2mortal (newRV_inc (req->callback)) : &PL_sv_undef); |
|
|
1731 | |
|
|
1732 | if (items > 1) |
|
|
1733 | { |
|
|
1734 | SV *cb_cv =get_cb (callback); |
|
|
1735 | |
1020 | SvREFCNT_dec (req->callback); |
1736 | SvREFCNT_dec (req->callback); |
1021 | req->callback = newSVsv (callback); |
1737 | req->callback = SvREFCNT_inc (cb_cv); |
|
|
1738 | } |
|
|
1739 | } |
1022 | |
1740 | |
1023 | MODULE = IO::AIO PACKAGE = IO::AIO::GRP |
1741 | MODULE = IO::AIO PACKAGE = IO::AIO::GRP |
1024 | |
1742 | |
1025 | void |
1743 | void |
1026 | add (aio_req grp, ...) |
1744 | add (aio_req grp, ...) |
… | |
… | |
1058 | AV *av; |
1776 | AV *av; |
1059 | |
1777 | |
1060 | grp->errorno = errno; |
1778 | grp->errorno = errno; |
1061 | |
1779 | |
1062 | av = newAV (); |
1780 | av = newAV (); |
|
|
1781 | av_extend (av, items - 1); |
1063 | |
1782 | |
1064 | for (i = 1; i < items; ++i ) |
1783 | for (i = 1; i < items; ++i ) |
1065 | av_push (av, newSVsv (ST (i))); |
1784 | av_push (av, newSVsv (ST (i))); |
1066 | |
1785 | |
1067 | SvREFCNT_dec (grp->sv1); |
1786 | SvREFCNT_dec (grp->sv1); |
… | |
… | |
1081 | void |
1800 | void |
1082 | feed (aio_req grp, SV *callback=&PL_sv_undef) |
1801 | feed (aio_req grp, SV *callback=&PL_sv_undef) |
1083 | CODE: |
1802 | CODE: |
1084 | { |
1803 | { |
1085 | SvREFCNT_dec (grp->sv2); |
1804 | SvREFCNT_dec (grp->sv2); |
1086 | grp->sv2 = newSVsv (callback); |
1805 | grp->sv2 = newSVsv (callback); |
|
|
1806 | grp->feed = aio_grp_feed; |
1087 | |
1807 | |
1088 | if (grp->int2 <= 0) |
1808 | if (grp->int2 <= 0) |
1089 | grp->int2 = 2; |
1809 | grp->int2 = 2; |
1090 | |
1810 | |
1091 | eio_grp_limit (grp, grp->int2); |
1811 | eio_grp_limit (grp, grp->int2); |