… | |
… | |
11 | #include <stddef.h> |
11 | #include <stddef.h> |
12 | #include <stdlib.h> |
12 | #include <stdlib.h> |
13 | #include <errno.h> |
13 | #include <errno.h> |
14 | #include <sys/types.h> |
14 | #include <sys/types.h> |
15 | #include <sys/stat.h> |
15 | #include <sys/stat.h> |
16 | #include <sys/statvfs.h> |
|
|
17 | #include <limits.h> |
16 | #include <limits.h> |
18 | #include <fcntl.h> |
17 | #include <fcntl.h> |
19 | #include <sched.h> |
18 | #include <sched.h> |
20 | |
19 | |
21 | #if _POSIX_MEMLOCK || _POSIX_MAPPED_FILES |
20 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
22 | # include <sys/mman.h> |
21 | # include <sys/mman.h> |
23 | #endif |
22 | #endif |
24 | |
23 | |
25 | /* perl namespace pollution */ |
24 | /* perl namespace pollution */ |
26 | #undef VERSION |
25 | #undef VERSION |
27 | |
|
|
28 | #ifdef _WIN32 |
|
|
29 | |
|
|
30 | # define EIO_STRUCT_DIRENT Direntry_t |
|
|
31 | # undef malloc |
|
|
32 | # undef free |
|
|
33 | |
|
|
34 | // perl overrides all those nice win32 functions |
|
|
35 | # undef open |
|
|
36 | # undef read |
|
|
37 | # undef write |
|
|
38 | # undef send |
|
|
39 | # undef recv |
|
|
40 | # undef stat |
|
|
41 | # undef fstat |
|
|
42 | # define lstat stat |
|
|
43 | # undef truncate |
|
|
44 | # undef ftruncate |
|
|
45 | # undef open |
|
|
46 | # undef close |
|
|
47 | # undef unlink |
|
|
48 | # undef rmdir |
|
|
49 | # undef rename |
|
|
50 | # undef lseek |
|
|
51 | |
|
|
52 | # define chown(a,b,c) (errno = ENOSYS, -1) |
|
|
53 | # define fchown(a,b,c) (errno = ENOSYS, -1) |
|
|
54 | # define fchmod(a,b) (errno = ENOSYS, -1) |
|
|
55 | # define symlink(a,b) (errno = ENOSYS, -1) |
|
|
56 | # define readlink(a,b,c) (errno = ENOSYS, -1) |
|
|
57 | # define mknod(a,b,c) (errno = ENOSYS, -1) |
|
|
58 | # define truncate(a,b) (errno = ENOSYS, -1) |
|
|
59 | # define ftruncate(fd,o) chsize ((fd), (o)) |
|
|
60 | # define fsync(fd) _commit (fd) |
|
|
61 | # define opendir(fd) (errno = ENOSYS, 0) |
|
|
62 | # define readdir(fd) (errno = ENOSYS, -1) |
|
|
63 | # define closedir(fd) (errno = ENOSYS, -1) |
|
|
64 | # define mkdir(a,b) mkdir (a) |
|
|
65 | |
|
|
66 | #else |
|
|
67 | |
|
|
68 | # include <sys/time.h> |
|
|
69 | # include <sys/select.h> |
|
|
70 | # include <unistd.h> |
|
|
71 | # include <utime.h> |
|
|
72 | # include <signal.h> |
|
|
73 | # define EIO_STRUCT_DIRENT struct dirent |
|
|
74 | |
|
|
75 | #endif |
|
|
76 | |
26 | |
77 | /* perl stupidly overrides readdir and maybe others */ |
27 | /* perl stupidly overrides readdir and maybe others */ |
78 | /* with thread-unsafe versions, imagine that :( */ |
28 | /* with thread-unsafe versions, imagine that :( */ |
79 | #undef readdir |
29 | #undef readdir |
80 | #undef opendir |
30 | #undef opendir |
81 | #undef closedir |
31 | #undef closedir |
82 | |
32 | |
|
|
33 | #ifdef _WIN32 |
|
|
34 | |
|
|
35 | // perl overrides all those nice libc functions |
|
|
36 | |
|
|
37 | #undef malloc |
|
|
38 | #undef free |
|
|
39 | #undef open |
|
|
40 | #undef read |
|
|
41 | #undef write |
|
|
42 | #undef send |
|
|
43 | #undef recv |
|
|
44 | #undef stat |
|
|
45 | #undef lstat |
|
|
46 | #undef fstat |
|
|
47 | #undef truncate |
|
|
48 | #undef ftruncate |
|
|
49 | #undef open |
|
|
50 | #undef link |
|
|
51 | #undef close |
|
|
52 | #undef unlink |
|
|
53 | #undef mkdir |
|
|
54 | #undef rmdir |
|
|
55 | #undef rename |
|
|
56 | #undef lseek |
|
|
57 | #undef opendir |
|
|
58 | #undef readdir |
|
|
59 | #undef closedir |
|
|
60 | #undef chmod |
|
|
61 | #undef fchmod |
|
|
62 | #undef dup |
|
|
63 | #undef dup2 |
|
|
64 | #undef abort |
|
|
65 | #undef pipe |
|
|
66 | |
|
|
67 | #define EIO_STRUCT_STAT struct _stati64 |
|
|
68 | #define EIO_STRUCT_STATI64 |
|
|
69 | |
|
|
70 | #else |
|
|
71 | |
|
|
72 | #include <sys/time.h> |
|
|
73 | #include <sys/select.h> |
|
|
74 | #include <unistd.h> |
|
|
75 | #include <utime.h> |
|
|
76 | #include <signal.h> |
|
|
77 | |
83 | #define EIO_STRUCT_STAT Stat_t |
78 | #define EIO_STRUCT_STAT Stat_t |
|
|
79 | |
|
|
80 | #endif |
84 | |
81 | |
85 | /* use NV for 32 bit perls as it allows larger offsets */ |
82 | /* use NV for 32 bit perls as it allows larger offsets */ |
86 | #if IVSIZE >= 8 |
83 | #if IVSIZE >= 8 |
87 | # define VAL64 IV |
84 | # define VAL64 IV |
88 | # define SvVAL64 SvIV |
85 | # define SvVAL64 SvIV |
… | |
… | |
108 | |
105 | |
109 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
106 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
110 | typedef int aio_rfd; /* read file desriptor */ |
107 | typedef int aio_rfd; /* read file desriptor */ |
111 | typedef int aio_wfd; /* write file descriptor */ |
108 | typedef int aio_wfd; /* write file descriptor */ |
112 | |
109 | |
113 | static HV *aio_stash, *aio_req_stash, *aio_grp_stash; |
110 | static HV *aio_stash, *aio_req_stash, *aio_grp_stash, *aio_wd_stash; |
114 | |
111 | |
115 | #define EIO_REQ_MEMBERS \ |
112 | #define EIO_REQ_MEMBERS \ |
116 | SV *callback; \ |
113 | SV *callback; \ |
117 | SV *sv1, *sv2; \ |
114 | SV *sv1, *sv2; \ |
|
|
115 | SV *sv3, *sv4; \ |
118 | STRLEN stroffset; \ |
116 | STRLEN stroffset; \ |
119 | SV *self; |
117 | SV *self; |
120 | |
118 | |
121 | #define EIO_NO_WRAPPERS 1 |
119 | #define EIO_NO_WRAPPERS 1 |
122 | |
120 | |
|
|
121 | #include "libeio/config.h" |
123 | #include "libeio/eio.h" |
122 | #include "libeio/eio.h" |
|
|
123 | |
|
|
124 | static int req_invoke (eio_req *req); |
|
|
125 | #define EIO_FINISH(req) req_invoke (req) |
|
|
126 | static void req_destroy (eio_req *grp); |
|
|
127 | #define EIO_DESTROY(req) req_destroy (req) |
|
|
128 | |
|
|
129 | #include "libeio/eio.c" |
|
|
130 | |
|
|
131 | /* Linux/others */ |
|
|
132 | #ifndef O_ASYNC |
|
|
133 | # define O_ASYNC 0 |
|
|
134 | #endif |
|
|
135 | #ifndef O_DIRECT |
|
|
136 | # define O_DIRECT 0 |
|
|
137 | #endif |
|
|
138 | #ifndef O_NOATIME |
|
|
139 | # define O_NOATIME 0 |
|
|
140 | #endif |
|
|
141 | |
|
|
142 | /* POSIX */ |
|
|
143 | #ifndef O_CLOEXEC |
|
|
144 | # define O_CLOEXEC 0 |
|
|
145 | #endif |
|
|
146 | #ifndef O_NOFOLLOW |
|
|
147 | # define O_NOFOLLOW 0 |
|
|
148 | #endif |
|
|
149 | #ifndef O_NOCTTY |
|
|
150 | # define O_NOCTTY 0 |
|
|
151 | #endif |
|
|
152 | #ifndef O_NONBLOCK |
|
|
153 | # define O_NONBLOCK 0 |
|
|
154 | #endif |
|
|
155 | #ifndef O_EXEC |
|
|
156 | # define O_EXEC 0 |
|
|
157 | #endif |
|
|
158 | #ifndef O_SEARCH |
|
|
159 | # define O_SEARCH 0 |
|
|
160 | #endif |
|
|
161 | #ifndef O_DIRECTORY |
|
|
162 | # define O_DIRECTORY 0 |
|
|
163 | #endif |
|
|
164 | #ifndef O_DSYNC |
|
|
165 | # define O_DSYNC 0 |
|
|
166 | #endif |
|
|
167 | #ifndef O_RSYNC |
|
|
168 | # define O_RSYNC 0 |
|
|
169 | #endif |
|
|
170 | #ifndef O_SYNC |
|
|
171 | # define O_SYNC 0 |
|
|
172 | #endif |
|
|
173 | #ifndef O_TTY_INIT |
|
|
174 | # define O_TTY_INIT 0 |
|
|
175 | #endif |
124 | |
176 | |
125 | #ifndef POSIX_FADV_NORMAL |
177 | #ifndef POSIX_FADV_NORMAL |
126 | # define POSIX_FADV_NORMAL 0 |
178 | # define POSIX_FADV_NORMAL 0 |
127 | # define NO_FADVISE 1 |
|
|
128 | #endif |
179 | #endif |
129 | #ifndef POSIX_FADV_SEQUENTIAL |
180 | #ifndef POSIX_FADV_SEQUENTIAL |
130 | # define POSIX_FADV_SEQUENTIAL 0 |
181 | # define POSIX_FADV_SEQUENTIAL 0 |
131 | #endif |
182 | #endif |
132 | #ifndef POSIX_FADV_RANDOM |
183 | #ifndef POSIX_FADV_RANDOM |
… | |
… | |
140 | #endif |
191 | #endif |
141 | #ifndef POSIX_FADV_DONTNEED |
192 | #ifndef POSIX_FADV_DONTNEED |
142 | # define POSIX_FADV_DONTNEED 0 |
193 | # define POSIX_FADV_DONTNEED 0 |
143 | #endif |
194 | #endif |
144 | |
195 | |
145 | #if _XOPEN_SOURCE < 600 || NO_FADVISE |
196 | #if !HAVE_POSIX_FADVISE |
146 | # define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */ |
197 | # define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */ |
147 | #endif |
198 | #endif |
148 | |
199 | |
149 | #ifndef POSIX_MADV_NORMAL |
200 | #ifndef POSIX_MADV_NORMAL |
150 | # define POSIX_MADV_NORMAL 0 |
201 | # define POSIX_MADV_NORMAL 0 |
151 | # define NO_MADVISE 1 |
|
|
152 | #endif |
202 | #endif |
153 | #ifndef POSIX_MADV_SEQUENTIAL |
203 | #ifndef POSIX_MADV_SEQUENTIAL |
154 | # define POSIX_MADV_SEQUENTIAL 0 |
204 | # define POSIX_MADV_SEQUENTIAL 0 |
155 | #endif |
205 | #endif |
156 | #ifndef POSIX_MADV_RANDOM |
206 | #ifndef POSIX_MADV_RANDOM |
… | |
… | |
161 | #endif |
211 | #endif |
162 | #ifndef POSIX_MADV_DONTNEED |
212 | #ifndef POSIX_MADV_DONTNEED |
163 | # define POSIX_MADV_DONTNEED 0 |
213 | # define POSIX_MADV_DONTNEED 0 |
164 | #endif |
214 | #endif |
165 | |
215 | |
166 | #if _XOPEN_SOURCE < 600 || NO_MADVISE |
216 | #if !HAVE_POSIX_MADVISE |
167 | # define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ |
217 | # define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ |
168 | #endif |
218 | #endif |
169 | |
219 | |
170 | #ifndef PROT_NONE |
220 | #ifndef PROT_NONE |
171 | # define PROT_NONE 0 |
221 | # define PROT_NONE 0 |
… | |
… | |
178 | #endif |
228 | #endif |
179 | #ifndef PROT_EXEC |
229 | #ifndef PROT_EXEC |
180 | # define PROT_EXEC 0 |
230 | # define PROT_EXEC 0 |
181 | #endif |
231 | #endif |
182 | |
232 | |
|
|
233 | #ifndef ST_RDONLY |
|
|
234 | # define ST_RDONLY 0 |
|
|
235 | #endif |
|
|
236 | #ifndef ST_NOSUID |
|
|
237 | # define ST_NOSUID 0 |
|
|
238 | #endif |
183 | #ifndef ST_NODEV |
239 | #ifndef ST_NODEV |
184 | # define ST_NODEV 0 |
240 | # define ST_NODEV 0 |
185 | #endif |
241 | #endif |
186 | #ifndef ST_NOEXEC |
242 | #ifndef ST_NOEXEC |
187 | # define ST_NOEXEC 0 |
243 | # define ST_NOEXEC 0 |
… | |
… | |
209 | #endif |
265 | #endif |
210 | #ifndef ST_RELATIME |
266 | #ifndef ST_RELATIME |
211 | # define ST_RELATIME 0 |
267 | # define ST_RELATIME 0 |
212 | #endif |
268 | #endif |
213 | |
269 | |
214 | #ifndef MCL_CURRENT |
270 | #ifndef S_IFIFO |
215 | # define MCL_CURRENT 0 |
271 | # define S_IFIFO 0 |
216 | #endif |
272 | #endif |
217 | #ifndef MCL_FUTURE |
273 | #ifndef S_IFCHR |
218 | # define MCL_FUTURE 0 |
274 | # define S_IFCHR 0 |
|
|
275 | #endif |
|
|
276 | #ifndef S_IFBLK |
|
|
277 | # define S_IFBLK 0 |
|
|
278 | #endif |
|
|
279 | #ifndef S_IFLNK |
|
|
280 | # define S_IFLNK 0 |
|
|
281 | #endif |
|
|
282 | #ifndef S_IFREG |
|
|
283 | # define S_IFREG 0 |
|
|
284 | #endif |
|
|
285 | #ifndef S_IFDIR |
|
|
286 | # define S_IFDIR 0 |
|
|
287 | #endif |
|
|
288 | #ifndef S_IFWHT |
|
|
289 | # define S_IFWHT 0 |
|
|
290 | #endif |
|
|
291 | #ifndef S_IFSOCK |
|
|
292 | # define S_IFSOCK 0 |
219 | #endif |
293 | #endif |
220 | |
294 | |
221 | #ifndef MAP_ANONYMOUS |
295 | #ifndef MAP_ANONYMOUS |
222 | # ifdef MAP_ANON |
296 | # ifdef MAP_ANON |
223 | # define MAP_ANONYMOUS MAP_ANON |
297 | # define MAP_ANONYMOUS MAP_ANON |
… | |
… | |
239 | #endif |
313 | #endif |
240 | #ifndef MAP_NONBLOCK |
314 | #ifndef MAP_NONBLOCK |
241 | # define MAP_NONBLOCK 0 |
315 | # define MAP_NONBLOCK 0 |
242 | #endif |
316 | #endif |
243 | |
317 | |
|
|
318 | #ifndef makedev |
|
|
319 | # define makedev(maj,min) (((maj) << 8) | (min)) |
|
|
320 | #endif |
|
|
321 | #ifndef major |
|
|
322 | # define major(dev) ((dev) >> 8) |
|
|
323 | #endif |
|
|
324 | #ifndef minor |
|
|
325 | # define minor(dev) ((dev) & 0xff) |
|
|
326 | #endif |
|
|
327 | |
244 | #ifndef PAGESIZE |
328 | #ifndef PAGESIZE |
245 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
329 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
246 | #endif |
330 | #endif |
247 | |
|
|
248 | static int req_invoke (eio_req *req); |
|
|
249 | #define EIO_FINISH(req) req_invoke (req) |
|
|
250 | static void req_destroy (eio_req *grp); |
|
|
251 | #define EIO_DESTROY(req) req_destroy (req) |
|
|
252 | |
331 | |
253 | enum { |
332 | enum { |
254 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
333 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
255 | }; |
334 | }; |
256 | |
335 | |
257 | #include "libeio/eio.c" |
|
|
258 | |
|
|
259 | typedef eio_req *aio_req; |
336 | typedef eio_req *aio_req; |
260 | typedef eio_req *aio_req_ornot; |
337 | typedef eio_req *aio_req_ornot; |
|
|
338 | typedef eio_wd aio_wd; |
261 | |
339 | |
262 | static SV *on_next_submit; |
340 | static SV *on_next_submit; |
263 | static int next_pri = EIO_PRI_DEFAULT; |
341 | static int next_pri = EIO_PRI_DEFAULT; |
264 | static int max_outstanding; |
342 | static int max_outstanding; |
265 | |
343 | |
266 | static s_epipe respipe; |
344 | static s_epipe respipe; |
267 | |
345 | |
268 | static void req_destroy (aio_req req); |
346 | static void req_destroy (aio_req req); |
269 | static void req_cancel (aio_req req); |
347 | static void req_cancel (aio_req req); |
270 | |
348 | |
271 | static void want_poll (void) |
349 | static void |
|
|
350 | want_poll (void) |
272 | { |
351 | { |
273 | /* write a dummy byte to the pipe so fh becomes ready */ |
352 | /* write a dummy byte to the pipe so fh becomes ready */ |
274 | s_epipe_signal (&respipe); |
353 | s_epipe_signal (&respipe); |
275 | } |
354 | } |
276 | |
355 | |
277 | static void done_poll (void) |
356 | static void |
|
|
357 | done_poll (void) |
278 | { |
358 | { |
279 | /* read any signals sent by the worker threads */ |
359 | /* read any signals sent by the worker threads */ |
280 | s_epipe_drain (&respipe); |
360 | s_epipe_drain (&respipe); |
281 | } |
361 | } |
282 | |
362 | |
283 | /* must be called at most once */ |
363 | /* must be called at most once */ |
|
|
364 | static SV * |
284 | static SV *req_sv (aio_req req, HV *stash) |
365 | req_sv (aio_req req, HV *stash) |
285 | { |
366 | { |
286 | if (!req->self) |
367 | if (!req->self) |
287 | { |
368 | { |
288 | req->self = (SV *)newHV (); |
369 | req->self = (SV *)newHV (); |
289 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
370 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
290 | } |
371 | } |
291 | |
372 | |
292 | return sv_2mortal (sv_bless (newRV_inc (req->self), stash)); |
373 | return sv_2mortal (sv_bless (newRV_inc (req->self), stash)); |
293 | } |
374 | } |
294 | |
375 | |
295 | static aio_req SvAIO_REQ (SV *sv) |
376 | static SV * |
|
|
377 | newSVaio_wd (aio_wd wd) |
|
|
378 | { |
|
|
379 | return sv_bless (newRV_noinc (newSViv ((IV)wd)), aio_wd_stash); |
|
|
380 | } |
|
|
381 | |
|
|
382 | static aio_req |
|
|
383 | SvAIO_REQ (SV *sv) |
296 | { |
384 | { |
297 | MAGIC *mg; |
385 | MAGIC *mg; |
298 | |
386 | |
299 | if (!SvROK (sv) |
387 | if (!SvROK (sv) |
|
|
388 | /* for speed reasons, we do not verify that SvROK actually has a stash ptr */ |
300 | || (SvSTASH (SvRV (sv)) != aio_grp_stash |
389 | || (SvSTASH (SvRV (sv)) != aio_grp_stash |
301 | && SvSTASH (SvRV (sv)) != aio_req_stash |
390 | && SvSTASH (SvRV (sv)) != aio_req_stash |
302 | && !sv_derived_from (sv, "IO::AIO::REQ"))) |
391 | && !sv_derived_from (sv, "IO::AIO::REQ"))) |
303 | croak ("object of class IO::AIO::REQ expected"); |
392 | croak ("object of class IO::AIO::REQ expected"); |
304 | |
393 | |
305 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
394 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
306 | |
395 | |
307 | return mg ? (aio_req)mg->mg_ptr : 0; |
396 | return mg ? (aio_req)mg->mg_ptr : 0; |
308 | } |
397 | } |
309 | |
398 | |
|
|
399 | static aio_wd |
|
|
400 | SvAIO_WD (SV *sv) |
|
|
401 | { |
|
|
402 | if (!SvROK (sv) |
|
|
403 | || SvTYPE (SvRV (sv)) != SVt_PVMG |
|
|
404 | || SvSTASH (SvRV (sv)) != aio_wd_stash) |
|
|
405 | croak ("IO::AIO: expected a working directory object as returned by aio_wd"); |
|
|
406 | |
|
|
407 | return (aio_wd)(long)SvIVX (SvRV (sv)); |
|
|
408 | } |
|
|
409 | |
|
|
410 | static void |
310 | static void aio_grp_feed (aio_req grp) |
411 | aio_grp_feed (aio_req grp) |
311 | { |
412 | { |
312 | if (grp->sv2 && SvOK (grp->sv2)) |
413 | if (grp->sv2 && SvOK (grp->sv2)) |
313 | { |
414 | { |
314 | dSP; |
415 | dSP; |
315 | |
416 | |
… | |
… | |
323 | FREETMPS; |
424 | FREETMPS; |
324 | LEAVE; |
425 | LEAVE; |
325 | } |
426 | } |
326 | } |
427 | } |
327 | |
428 | |
|
|
429 | static void |
328 | static void req_submit (eio_req *req) |
430 | req_submit (eio_req *req) |
329 | { |
431 | { |
330 | eio_submit (req); |
432 | eio_submit (req); |
331 | |
433 | |
332 | if (expect_false (on_next_submit)) |
434 | if (expect_false (on_next_submit)) |
333 | { |
435 | { |
… | |
… | |
340 | PUTBACK; |
442 | PUTBACK; |
341 | call_sv (cb, G_DISCARD | G_EVAL); |
443 | call_sv (cb, G_DISCARD | G_EVAL); |
342 | } |
444 | } |
343 | } |
445 | } |
344 | |
446 | |
|
|
447 | static int |
345 | static int req_invoke (eio_req *req) |
448 | req_invoke (eio_req *req) |
346 | { |
449 | { |
347 | if (req->flags & FLAG_SV2_RO_OFF) |
450 | if (req->flags & FLAG_SV2_RO_OFF) |
348 | SvREADONLY_off (req->sv2); |
451 | SvREADONLY_off (req->sv2); |
349 | |
452 | |
350 | if (!EIO_CANCELLED (req) && req->callback) |
453 | if (!EIO_CANCELLED (req) && req->callback) |
… | |
… | |
361 | /* do not recreate the result IV from scratch each time */ |
464 | /* do not recreate the result IV from scratch each time */ |
362 | if (expect_true (sv_result_cache)) |
465 | if (expect_true (sv_result_cache)) |
363 | { |
466 | { |
364 | sv_result = sv_result_cache; sv_result_cache = 0; |
467 | sv_result = sv_result_cache; sv_result_cache = 0; |
365 | SvIV_set (sv_result, req->result); |
468 | SvIV_set (sv_result, req->result); |
|
|
469 | SvIOK_only (sv_result); |
366 | } |
470 | } |
367 | else |
471 | else |
368 | { |
472 | { |
369 | sv_result = newSViv (req->result); |
473 | sv_result = newSViv (req->result); |
370 | SvREADONLY_on (sv_result); |
474 | SvREADONLY_on (sv_result); |
371 | } |
475 | } |
372 | |
476 | |
373 | switch (req->type) |
477 | switch (req->type) |
374 | { |
478 | { |
|
|
479 | case EIO_WD_OPEN: |
|
|
480 | PUSHs (req->result ? &PL_sv_undef : sv_2mortal (newSVaio_wd (req->wd))); |
|
|
481 | break; |
|
|
482 | |
375 | case EIO_READDIR: |
483 | case EIO_READDIR: |
376 | { |
484 | { |
377 | SV *rv = &PL_sv_undef; |
485 | SV *rv = &PL_sv_undef; |
378 | |
486 | |
379 | if (req->result >= 0) |
487 | if (req->result >= 0) |
… | |
… | |
467 | case EIO_STATVFS: |
575 | case EIO_STATVFS: |
468 | case EIO_FSTATVFS: |
576 | case EIO_FSTATVFS: |
469 | { |
577 | { |
470 | SV *rv = &PL_sv_undef; |
578 | SV *rv = &PL_sv_undef; |
471 | |
579 | |
|
|
580 | #ifndef _WIN32 |
472 | if (req->result >= 0) |
581 | if (req->result >= 0) |
473 | { |
582 | { |
474 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
583 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
475 | HV *hv = newHV (); |
584 | HV *hv = newHV (); |
476 | |
585 | |
… | |
… | |
486 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
595 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
487 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
596 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
488 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
597 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
489 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
598 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
490 | } |
599 | } |
|
|
600 | #endif |
491 | |
601 | |
492 | PUSHs (rv); |
602 | PUSHs (rv); |
493 | } |
603 | } |
494 | |
604 | |
495 | break; |
605 | break; |
… | |
… | |
511 | case EIO_NOP: |
621 | case EIO_NOP: |
512 | case EIO_BUSY: |
622 | case EIO_BUSY: |
513 | break; |
623 | break; |
514 | |
624 | |
515 | case EIO_READLINK: |
625 | case EIO_READLINK: |
|
|
626 | case EIO_REALPATH: |
516 | if (req->result > 0) |
627 | if (req->result > 0) |
517 | PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); |
628 | PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); |
518 | break; |
629 | break; |
519 | |
630 | |
520 | case EIO_STAT: |
631 | case EIO_STAT: |
521 | case EIO_LSTAT: |
632 | case EIO_LSTAT: |
522 | case EIO_FSTAT: |
633 | case EIO_FSTAT: |
523 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
634 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
|
|
635 | |
524 | PL_laststatval = req->result; |
636 | if (!(PL_laststatval = req->result)) |
|
|
637 | /* if compilation fails here then perl's Stat_t is not struct _stati64 */ |
525 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
638 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
|
|
639 | |
526 | PUSHs (sv_result); |
640 | PUSHs (sv_result); |
|
|
641 | break; |
|
|
642 | |
|
|
643 | case EIO_SEEK: |
|
|
644 | PUSHs (req->result ? sv_result : sv_2mortal (newSVval64 (req->offs))); |
527 | break; |
645 | break; |
528 | |
646 | |
529 | case EIO_READ: |
647 | case EIO_READ: |
530 | { |
648 | { |
531 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
649 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
… | |
… | |
534 | SvSETMAGIC (req->sv2); |
652 | SvSETMAGIC (req->sv2); |
535 | PUSHs (sv_result); |
653 | PUSHs (sv_result); |
536 | } |
654 | } |
537 | break; |
655 | break; |
538 | |
656 | |
539 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), su fudge result value */ |
657 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), so fudge result value */ |
540 | if (req->result > 0) |
658 | if (req->result > 0) |
541 | SvIV_set (sv_result, 0); |
659 | SvIV_set (sv_result, 0); |
542 | /* FALLTHROUGH */ |
660 | /* FALLTHROUGH */ |
543 | |
661 | |
544 | default: |
662 | default: |
… | |
… | |
564 | } |
682 | } |
565 | |
683 | |
566 | return !!SvTRUE (ERRSV); |
684 | return !!SvTRUE (ERRSV); |
567 | } |
685 | } |
568 | |
686 | |
|
|
687 | static void |
569 | static void req_destroy (aio_req req) |
688 | req_destroy (aio_req req) |
570 | { |
689 | { |
571 | if (req->self) |
690 | if (req->self) |
572 | { |
691 | { |
573 | sv_unmagic (req->self, PERL_MAGIC_ext); |
692 | sv_unmagic (req->self, PERL_MAGIC_ext); |
574 | SvREFCNT_dec (req->self); |
693 | SvREFCNT_dec (req->self); |
575 | } |
694 | } |
576 | |
695 | |
577 | SvREFCNT_dec (req->sv1); |
696 | SvREFCNT_dec (req->sv1); |
578 | SvREFCNT_dec (req->sv2); |
697 | SvREFCNT_dec (req->sv2); |
|
|
698 | SvREFCNT_dec (req->sv3); |
|
|
699 | SvREFCNT_dec (req->sv4); |
579 | SvREFCNT_dec (req->callback); |
700 | SvREFCNT_dec (req->callback); |
580 | |
701 | |
581 | Safefree (req); |
702 | free (req); |
582 | } |
703 | } |
583 | |
704 | |
|
|
705 | static void |
584 | static void req_cancel_subs (aio_req grp) |
706 | req_cancel_subs (aio_req grp) |
585 | { |
707 | { |
586 | aio_req sub; |
|
|
587 | |
|
|
588 | if (grp->type != EIO_GROUP) |
708 | if (grp->type != EIO_GROUP) |
589 | return; |
709 | return; |
590 | |
710 | |
591 | SvREFCNT_dec (grp->sv2); |
711 | SvREFCNT_dec (grp->sv2); |
592 | grp->sv2 = 0; |
712 | grp->sv2 = 0; |
593 | |
713 | |
594 | eio_grp_cancel (grp); |
714 | eio_grp_cancel (grp); |
595 | } |
715 | } |
596 | |
716 | |
597 | static void |
717 | static void ecb_cold |
598 | create_respipe (void) |
718 | create_respipe (void) |
599 | { |
719 | { |
600 | if (s_epipe_renew (&respipe)) |
720 | if (s_epipe_renew (&respipe)) |
601 | croak ("IO::AIO: unable to initialize result pipe"); |
721 | croak ("IO::AIO: unable to initialize result pipe"); |
602 | } |
722 | } |
603 | |
723 | |
604 | static void poll_wait (void) |
724 | static void |
|
|
725 | poll_wait (void) |
605 | { |
726 | { |
606 | while (eio_nreqs ()) |
727 | while (eio_nreqs ()) |
607 | { |
728 | { |
608 | int size; |
729 | int size; |
609 | |
730 | |
… | |
… | |
618 | |
739 | |
619 | s_epipe_wait (&respipe); |
740 | s_epipe_wait (&respipe); |
620 | } |
741 | } |
621 | } |
742 | } |
622 | |
743 | |
623 | static int poll_cb (void) |
744 | static int |
|
|
745 | poll_cb (void) |
624 | { |
746 | { |
625 | for (;;) |
747 | for (;;) |
626 | { |
748 | { |
627 | int res = eio_poll (); |
749 | int res = eio_poll (); |
628 | |
750 | |
… | |
… | |
634 | |
756 | |
635 | poll_wait (); |
757 | poll_wait (); |
636 | } |
758 | } |
637 | } |
759 | } |
638 | |
760 | |
639 | static void atfork_child (void) |
761 | static void ecb_cold |
|
|
762 | reinit (void) |
640 | { |
763 | { |
641 | create_respipe (); |
764 | create_respipe (); |
|
|
765 | |
|
|
766 | if (eio_init (want_poll, done_poll) < 0) |
|
|
767 | croak ("IO::AIO: unable to initialise eio library"); |
642 | } |
768 | } |
643 | |
769 | |
644 | /*****************************************************************************/ |
770 | /*****************************************************************************/ |
645 | |
771 | |
646 | #if !_POSIX_MAPPED_FILES |
772 | #if !_POSIX_MAPPED_FILES |
647 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
773 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
648 | # define munmap(addr,length) (errno = ENOSYS, -1) |
774 | # define munmap(addr,length) (errno = ENOSYS, -1) |
|
|
775 | #endif |
|
|
776 | |
|
|
777 | #if !_POSIX_MEMORY_PROTECTION |
649 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
778 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
|
|
779 | # define PROT_NONE 0 |
|
|
780 | # define PROT_WRITE 0 |
|
|
781 | # define MAP_PRIVATE 0 |
|
|
782 | # define MAP_SHARED 0 |
|
|
783 | # define MAP_FIXED 0 |
650 | #endif |
784 | #endif |
651 | |
785 | |
652 | #define MMAP_MAGIC PERL_MAGIC_ext |
786 | #define MMAP_MAGIC PERL_MAGIC_ext |
653 | |
787 | |
654 | static int |
788 | static int ecb_cold |
655 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
789 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
656 | { |
790 | { |
657 | int old_errno = errno; |
791 | int old_errno = errno; |
658 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
792 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
659 | errno = old_errno; |
793 | errno = old_errno; |
… | |
… | |
683 | { |
817 | { |
684 | SvGETMAGIC (cb_sv); |
818 | SvGETMAGIC (cb_sv); |
685 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
819 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
686 | } |
820 | } |
687 | |
821 | |
|
|
822 | static aio_req ecb_noinline |
|
|
823 | dreq (SV *callback) |
|
|
824 | { |
|
|
825 | SV *cb_cv; |
|
|
826 | aio_req req; |
|
|
827 | int req_pri = next_pri; |
|
|
828 | next_pri = EIO_PRI_DEFAULT; |
|
|
829 | |
|
|
830 | cb_cv = get_cb (callback); |
|
|
831 | |
|
|
832 | req = calloc (sizeof (*req), 1); |
|
|
833 | if (!req) |
|
|
834 | croak ("out of memory during eio_req allocation"); |
|
|
835 | |
|
|
836 | req->callback = SvREFCNT_inc (cb_cv); |
|
|
837 | req->pri = req_pri; |
|
|
838 | |
|
|
839 | return req; |
|
|
840 | } |
|
|
841 | |
688 | #define dREQ \ |
842 | #define dREQ \ |
689 | SV *cb_cv; \ |
843 | aio_req req = dreq (callback); \ |
690 | aio_req req; \ |
|
|
691 | int req_pri = next_pri; \ |
|
|
692 | next_pri = EIO_PRI_DEFAULT; \ |
|
|
693 | \ |
|
|
694 | cb_cv = get_cb (callback); \ |
|
|
695 | \ |
|
|
696 | Newz (0, req, 1, eio_req); \ |
|
|
697 | if (!req) \ |
|
|
698 | croak ("out of memory during eio_req allocation"); \ |
|
|
699 | \ |
|
|
700 | req->callback = SvREFCNT_inc (cb_cv); \ |
|
|
701 | req->pri = req_pri |
|
|
702 | |
844 | |
703 | #define REQ_SEND \ |
845 | #define REQ_SEND \ |
704 | PUTBACK; \ |
846 | PUTBACK; \ |
705 | req_submit (req); \ |
847 | req_submit (req); \ |
706 | SPAGAIN; \ |
848 | SPAGAIN; \ |
707 | \ |
849 | \ |
708 | if (GIMME_V != G_VOID) \ |
850 | if (GIMME_V != G_VOID) \ |
709 | XPUSHs (req_sv (req, aio_req_stash)); |
851 | XPUSHs (req_sv (req, aio_req_stash)); |
|
|
852 | |
|
|
853 | ecb_inline void |
|
|
854 | req_set_path (aio_req req, SV *path, SV **wdsv, SV **pathsv, eio_wd *wd, void **ptr) |
|
|
855 | { |
|
|
856 | if (expect_false (SvROK (path))) |
|
|
857 | { |
|
|
858 | SV *rv = SvRV (path); |
|
|
859 | SV *wdob; |
|
|
860 | |
|
|
861 | if (SvTYPE (rv) == SVt_PVAV && AvFILLp (rv) == 1) |
|
|
862 | { |
|
|
863 | path = AvARRAY (rv)[1]; |
|
|
864 | wdob = AvARRAY (rv)[0]; |
|
|
865 | |
|
|
866 | if (SvOK (wdob)) |
|
|
867 | { |
|
|
868 | *wd = SvAIO_WD (wdob); |
|
|
869 | *wdsv = SvREFCNT_inc_NN (SvRV (wdob)); |
|
|
870 | } |
|
|
871 | else |
|
|
872 | *wd = EIO_INVALID_WD; |
|
|
873 | } |
|
|
874 | else if (SvTYPE (rv) == SVt_PVMG && SvSTASH (rv) == aio_wd_stash) |
|
|
875 | { |
|
|
876 | *wd = (aio_wd)(long)SvIVX (rv); |
|
|
877 | *wdsv = SvREFCNT_inc_NN (rv); |
|
|
878 | *ptr = "."; |
|
|
879 | return; /* path set to "." */ |
|
|
880 | } |
|
|
881 | else |
|
|
882 | croak ("IO::AIO: pathname arguments must be specified as a string, an IO::AIO::WD object or a [IO::AIO::WD, path] pair"); |
|
|
883 | } |
|
|
884 | |
|
|
885 | *pathsv = newSVsv (path); |
|
|
886 | *ptr = SvPVbyte_nolen (*pathsv); |
|
|
887 | } |
|
|
888 | |
|
|
889 | static void ecb_noinline |
|
|
890 | req_set_path1 (aio_req req, SV *path) |
|
|
891 | { |
|
|
892 | req_set_path (req, path, &req->sv1, &req->sv3, &req->wd, &req->ptr1); |
|
|
893 | } |
|
|
894 | |
|
|
895 | static void ecb_noinline |
|
|
896 | req_set_fh_or_path (aio_req req, int type_path, int type_fh, SV *fh_or_path) |
|
|
897 | { |
|
|
898 | SV *rv = SvROK (fh_or_path) ? SvRV (fh_or_path) : fh_or_path; |
|
|
899 | |
|
|
900 | switch (SvTYPE (rv)) |
|
|
901 | { |
|
|
902 | case SVt_PVIO: |
|
|
903 | case SVt_PVLV: |
|
|
904 | case SVt_PVGV: |
|
|
905 | req->type = type_fh; |
|
|
906 | req->sv1 = newSVsv (fh_or_path); |
|
|
907 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
908 | break; |
|
|
909 | |
|
|
910 | default: |
|
|
911 | req->type = type_path; |
|
|
912 | req_set_path1 (req, fh_or_path); |
|
|
913 | break; |
|
|
914 | } |
|
|
915 | } |
|
|
916 | |
|
|
917 | XS(boot_IO__AIO) ecb_cold; |
710 | |
918 | |
711 | MODULE = IO::AIO PACKAGE = IO::AIO |
919 | MODULE = IO::AIO PACKAGE = IO::AIO |
712 | |
920 | |
713 | PROTOTYPES: ENABLE |
921 | PROTOTYPES: ENABLE |
714 | |
922 | |
… | |
… | |
728 | const_iv (O_RDWR) |
936 | const_iv (O_RDWR) |
729 | const_iv (O_CREAT) |
937 | const_iv (O_CREAT) |
730 | const_iv (O_TRUNC) |
938 | const_iv (O_TRUNC) |
731 | const_iv (O_EXCL) |
939 | const_iv (O_EXCL) |
732 | const_iv (O_APPEND) |
940 | const_iv (O_APPEND) |
733 | #ifndef _WIN32 |
941 | |
|
|
942 | const_iv (O_ASYNC) |
|
|
943 | const_iv (O_DIRECT) |
|
|
944 | const_iv (O_NOATIME) |
|
|
945 | |
|
|
946 | const_iv (O_CLOEXEC) |
|
|
947 | const_iv (O_NOCTTY) |
|
|
948 | const_iv (O_NOFOLLOW) |
|
|
949 | const_iv (O_NONBLOCK) |
|
|
950 | const_iv (O_EXEC) |
|
|
951 | const_iv (O_SEARCH) |
|
|
952 | const_iv (O_DIRECTORY) |
|
|
953 | const_iv (O_DSYNC) |
|
|
954 | const_iv (O_RSYNC) |
|
|
955 | const_iv (O_SYNC) |
|
|
956 | const_iv (O_TTY_INIT) |
|
|
957 | |
734 | const_iv (S_IFIFO) |
958 | const_iv (S_IFIFO) |
735 | #endif |
959 | const_iv (S_IFCHR) |
|
|
960 | const_iv (S_IFBLK) |
|
|
961 | const_iv (S_IFLNK) |
|
|
962 | const_iv (S_IFREG) |
|
|
963 | const_iv (S_IFDIR) |
|
|
964 | const_iv (S_IFWHT) |
|
|
965 | const_iv (S_IFSOCK) |
|
|
966 | const_iv (S_IFMT) |
|
|
967 | |
736 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
968 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
737 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
969 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
738 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
970 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
739 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
971 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
740 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
972 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
… | |
… | |
774 | const_iv (MAP_LOCKED) |
1006 | const_iv (MAP_LOCKED) |
775 | const_iv (MAP_NORESERVE) |
1007 | const_iv (MAP_NORESERVE) |
776 | const_iv (MAP_POPULATE) |
1008 | const_iv (MAP_POPULATE) |
777 | const_iv (MAP_NONBLOCK) |
1009 | const_iv (MAP_NONBLOCK) |
778 | |
1010 | |
|
|
1011 | const_eio (SEEK_SET) |
|
|
1012 | const_eio (SEEK_CUR) |
|
|
1013 | const_eio (SEEK_END) |
|
|
1014 | |
779 | const_iv (MCL_FUTURE) |
1015 | const_eio (MCL_FUTURE) |
780 | const_iv (MCL_CURRENT) |
1016 | const_eio (MCL_CURRENT) |
781 | |
1017 | |
782 | const_eio (MS_ASYNC) |
1018 | const_eio (MS_ASYNC) |
783 | const_eio (MS_INVALIDATE) |
1019 | const_eio (MS_INVALIDATE) |
784 | const_eio (MS_SYNC) |
1020 | const_eio (MS_SYNC) |
785 | |
1021 | |
786 | const_eio (MT_MODIFY) |
1022 | const_eio (MT_MODIFY) |
787 | |
1023 | |
788 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
1024 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
789 | const_eio (SYNC_FILE_RANGE_WRITE) |
1025 | const_eio (SYNC_FILE_RANGE_WRITE) |
790 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
1026 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
|
|
1027 | |
|
|
1028 | const_eio (FALLOC_FL_KEEP_SIZE) |
791 | |
1029 | |
792 | const_eio (READDIR_DENTS) |
1030 | const_eio (READDIR_DENTS) |
793 | const_eio (READDIR_DIRS_FIRST) |
1031 | const_eio (READDIR_DIRS_FIRST) |
794 | const_eio (READDIR_STAT_ORDER) |
1032 | const_eio (READDIR_STAT_ORDER) |
795 | const_eio (READDIR_FOUND_UNKNOWN) |
1033 | const_eio (READDIR_FOUND_UNKNOWN) |
… | |
… | |
806 | }; |
1044 | }; |
807 | |
1045 | |
808 | aio_stash = gv_stashpv ("IO::AIO" , 1); |
1046 | aio_stash = gv_stashpv ("IO::AIO" , 1); |
809 | aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); |
1047 | aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); |
810 | aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); |
1048 | aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); |
|
|
1049 | aio_wd_stash = gv_stashpv ("IO::AIO::WD" , 1); |
811 | |
1050 | |
812 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1051 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
813 | newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); |
1052 | newCONSTSUB (aio_stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
814 | |
1053 | |
815 | newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); |
1054 | newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); |
816 | |
1055 | |
817 | create_respipe (); |
1056 | reinit (); |
818 | |
|
|
819 | if (eio_init (want_poll, done_poll) < 0) |
|
|
820 | croak ("IO::AIO: unable to initialise eio library"); |
|
|
821 | |
|
|
822 | /* atfork child called in fifo order, so before eio's handler */ |
|
|
823 | X_THREAD_ATFORK (0, 0, atfork_child); |
|
|
824 | } |
1057 | } |
825 | |
1058 | |
826 | void |
1059 | void |
|
|
1060 | reinit () |
|
|
1061 | PROTOTYPE: |
|
|
1062 | |
|
|
1063 | void |
827 | max_poll_reqs (int nreqs) |
1064 | max_poll_reqs (unsigned int nreqs) |
828 | PROTOTYPE: $ |
1065 | PROTOTYPE: $ |
829 | CODE: |
1066 | CODE: |
830 | eio_set_max_poll_reqs (nreqs); |
1067 | eio_set_max_poll_reqs (nreqs); |
831 | |
1068 | |
832 | void |
1069 | void |
… | |
… | |
834 | PROTOTYPE: $ |
1071 | PROTOTYPE: $ |
835 | CODE: |
1072 | CODE: |
836 | eio_set_max_poll_time (nseconds); |
1073 | eio_set_max_poll_time (nseconds); |
837 | |
1074 | |
838 | void |
1075 | void |
839 | min_parallel (int nthreads) |
1076 | min_parallel (unsigned int nthreads) |
840 | PROTOTYPE: $ |
1077 | PROTOTYPE: $ |
841 | CODE: |
1078 | CODE: |
842 | eio_set_min_parallel (nthreads); |
1079 | eio_set_min_parallel (nthreads); |
843 | |
1080 | |
844 | void |
1081 | void |
845 | max_parallel (int nthreads) |
1082 | max_parallel (unsigned int nthreads) |
846 | PROTOTYPE: $ |
1083 | PROTOTYPE: $ |
847 | CODE: |
1084 | CODE: |
848 | eio_set_max_parallel (nthreads); |
1085 | eio_set_max_parallel (nthreads); |
849 | |
1086 | |
850 | void |
1087 | void |
851 | max_idle (int nthreads) |
1088 | max_idle (unsigned int nthreads) |
852 | PROTOTYPE: $ |
1089 | PROTOTYPE: $ |
853 | CODE: |
1090 | CODE: |
854 | eio_set_max_idle (nthreads); |
1091 | eio_set_max_idle (nthreads); |
855 | |
1092 | |
856 | void |
1093 | void |
|
|
1094 | idle_timeout (unsigned int seconds) |
|
|
1095 | PROTOTYPE: $ |
|
|
1096 | CODE: |
|
|
1097 | eio_set_idle_timeout (seconds); |
|
|
1098 | |
|
|
1099 | void |
857 | max_outstanding (int maxreqs) |
1100 | max_outstanding (unsigned int maxreqs) |
858 | PROTOTYPE: $ |
1101 | PROTOTYPE: $ |
859 | CODE: |
1102 | CODE: |
860 | max_outstanding = maxreqs; |
1103 | max_outstanding = maxreqs; |
861 | |
1104 | |
862 | void |
1105 | void |
|
|
1106 | aio_wd (SV8 *pathname, SV *callback=&PL_sv_undef) |
|
|
1107 | PPCODE: |
|
|
1108 | { |
|
|
1109 | dREQ; |
|
|
1110 | |
|
|
1111 | req->type = EIO_WD_OPEN; |
|
|
1112 | req_set_path1 (req, pathname); |
|
|
1113 | |
|
|
1114 | REQ_SEND; |
|
|
1115 | } |
|
|
1116 | |
|
|
1117 | void |
863 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
1118 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
864 | PROTOTYPE: $$$;$ |
|
|
865 | PPCODE: |
1119 | PPCODE: |
866 | { |
1120 | { |
867 | dREQ; |
1121 | dREQ; |
868 | |
1122 | |
869 | req->type = EIO_OPEN; |
1123 | req->type = EIO_OPEN; |
870 | req->sv1 = newSVsv (pathname); |
1124 | req_set_path1 (req, pathname); |
871 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
872 | req->int1 = flags; |
1125 | req->int1 = flags; |
873 | req->int2 = mode; |
1126 | req->int2 = mode; |
874 | |
1127 | |
875 | REQ_SEND; |
1128 | REQ_SEND; |
876 | } |
1129 | } |
877 | |
1130 | |
878 | void |
1131 | void |
879 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
1132 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
880 | PROTOTYPE: $;$ |
|
|
881 | ALIAS: |
1133 | ALIAS: |
882 | aio_fsync = EIO_FSYNC |
1134 | aio_fsync = EIO_FSYNC |
883 | aio_fdatasync = EIO_FDATASYNC |
1135 | aio_fdatasync = EIO_FDATASYNC |
|
|
1136 | aio_syncfs = EIO_SYNCFS |
884 | PPCODE: |
1137 | PPCODE: |
885 | { |
1138 | { |
886 | int fd = s_fileno_croak (fh, 0); |
1139 | int fd = s_fileno_croak (fh, 0); |
887 | dREQ; |
1140 | dREQ; |
888 | |
1141 | |
889 | req->type = ix; |
1142 | req->type = ix; |
890 | req->sv1 = newSVsv (fh); |
1143 | req->sv1 = newSVsv (fh); |
891 | req->int1 = fd; |
1144 | req->int1 = fd; |
892 | |
1145 | |
893 | REQ_SEND (req); |
1146 | REQ_SEND; |
894 | } |
1147 | } |
895 | |
1148 | |
896 | void |
1149 | void |
897 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
1150 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
898 | PROTOTYPE: $$$$;$ |
|
|
899 | PPCODE: |
1151 | PPCODE: |
900 | { |
1152 | { |
901 | int fd = s_fileno_croak (fh, 0); |
1153 | int fd = s_fileno_croak (fh, 0); |
902 | dREQ; |
1154 | dREQ; |
903 | |
1155 | |
… | |
… | |
906 | req->int1 = fd; |
1158 | req->int1 = fd; |
907 | req->offs = offset; |
1159 | req->offs = offset; |
908 | req->size = nbytes; |
1160 | req->size = nbytes; |
909 | req->int2 = flags; |
1161 | req->int2 = flags; |
910 | |
1162 | |
911 | REQ_SEND (req); |
1163 | REQ_SEND; |
912 | } |
1164 | } |
913 | |
1165 | |
914 | void |
1166 | void |
915 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1167 | aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) |
916 | PROTOTYPE: $;$ |
|
|
917 | PPCODE: |
1168 | PPCODE: |
918 | { |
1169 | { |
919 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
|
|
920 | int fd = s_fileno_croak (fh, 0); |
1170 | int fd = s_fileno_croak (fh, 0); |
921 | dREQ; |
1171 | dREQ; |
922 | |
1172 | |
923 | if (close_pipe < 0) |
1173 | req->type = EIO_FALLOCATE; |
|
|
1174 | req->sv1 = newSVsv (fh); |
|
|
1175 | req->int1 = fd; |
|
|
1176 | req->int2 = mode; |
|
|
1177 | req->offs = offset; |
|
|
1178 | req->size = len; |
|
|
1179 | |
|
|
1180 | REQ_SEND; |
|
|
1181 | } |
|
|
1182 | |
|
|
1183 | void |
|
|
1184 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
|
|
1185 | PPCODE: |
|
|
1186 | { |
|
|
1187 | static int close_fd = -1; /* dummy fd to close fds via dup2 */ |
|
|
1188 | int fd = s_fileno_croak (fh, 0); |
|
|
1189 | dREQ; |
|
|
1190 | |
|
|
1191 | if (expect_false (close_fd < 0)) |
924 | { |
1192 | { |
925 | int pipefd [2]; |
1193 | int pipefd [2]; |
926 | |
1194 | |
|
|
1195 | if ( |
|
|
1196 | #ifdef _WIN32 |
|
|
1197 | _pipe (pipefd, 1, _O_BINARY) < 0 |
|
|
1198 | #else |
927 | if (pipe (pipefd) < 0 |
1199 | pipe (pipefd) < 0 |
928 | || close (pipefd [1]) < 0 |
|
|
929 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) |
1200 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0 |
|
|
1201 | #endif |
|
|
1202 | || close (pipefd [1]) < 0 |
|
|
1203 | ) |
930 | abort (); /*D*/ |
1204 | abort (); /*D*/ |
931 | |
1205 | |
932 | close_pipe = pipefd [0]; |
1206 | close_fd = pipefd [0]; |
933 | } |
1207 | } |
934 | |
1208 | |
935 | req->type = EIO_DUP2; |
1209 | req->type = EIO_DUP2; |
936 | req->int1 = close_pipe; |
1210 | req->int1 = close_fd; |
937 | req->sv2 = newSVsv (fh); |
1211 | req->sv2 = newSVsv (fh); |
938 | req->int2 = fd; |
1212 | req->int2 = fd; |
939 | |
1213 | |
940 | REQ_SEND (req); |
1214 | REQ_SEND; |
|
|
1215 | } |
|
|
1216 | |
|
|
1217 | void |
|
|
1218 | aio_seek (SV *fh, SV *offset, int whence, SV *callback=&PL_sv_undef) |
|
|
1219 | PPCODE: |
|
|
1220 | { |
|
|
1221 | STRLEN svlen; |
|
|
1222 | int fd = s_fileno_croak (fh, 0); |
|
|
1223 | dREQ; |
|
|
1224 | |
|
|
1225 | req->type = EIO_SEEK; |
|
|
1226 | req->sv1 = newSVsv (fh); |
|
|
1227 | req->int1 = fd; |
|
|
1228 | req->offs = SvVAL64 (offset); |
|
|
1229 | req->int2 = whence; |
|
|
1230 | |
|
|
1231 | REQ_SEND; |
941 | } |
1232 | } |
942 | |
1233 | |
943 | void |
1234 | void |
944 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
1235 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
945 | ALIAS: |
1236 | ALIAS: |
946 | aio_read = EIO_READ |
1237 | aio_read = EIO_READ |
947 | aio_write = EIO_WRITE |
1238 | aio_write = EIO_WRITE |
948 | PROTOTYPE: $$$$$;$ |
|
|
949 | PPCODE: |
1239 | PPCODE: |
950 | { |
1240 | { |
951 | STRLEN svlen; |
1241 | STRLEN svlen; |
952 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
1242 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
953 | char *svptr = SvPVbyte (data, svlen); |
1243 | char *svptr = SvPVbyte (data, svlen); |
… | |
… | |
993 | REQ_SEND; |
1283 | REQ_SEND; |
994 | } |
1284 | } |
995 | } |
1285 | } |
996 | |
1286 | |
997 | void |
1287 | void |
998 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
1288 | aio_readlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
999 | PROTOTYPE: $$;$ |
1289 | ALIAS: |
|
|
1290 | aio_readlink = EIO_READLINK |
|
|
1291 | aio_realpath = EIO_REALPATH |
1000 | PPCODE: |
1292 | PPCODE: |
1001 | { |
1293 | { |
1002 | SV *data; |
|
|
1003 | dREQ; |
1294 | dREQ; |
1004 | |
1295 | |
1005 | req->type = EIO_READLINK; |
1296 | req->type = ix; |
1006 | req->sv1 = newSVsv (path); |
1297 | req_set_path1 (req, pathname); |
1007 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1008 | |
1298 | |
1009 | REQ_SEND; |
1299 | REQ_SEND; |
1010 | } |
1300 | } |
1011 | |
1301 | |
1012 | void |
1302 | void |
1013 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
1303 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
1014 | PROTOTYPE: $$$$;$ |
|
|
1015 | PPCODE: |
1304 | PPCODE: |
1016 | { |
1305 | { |
1017 | int ifd = s_fileno_croak (in_fh , 0); |
1306 | int ifd = s_fileno_croak (in_fh , 0); |
1018 | int ofd = s_fileno_croak (out_fh, 1); |
1307 | int ofd = s_fileno_croak (out_fh, 1); |
1019 | dREQ; |
1308 | dREQ; |
… | |
… | |
1029 | REQ_SEND; |
1318 | REQ_SEND; |
1030 | } |
1319 | } |
1031 | |
1320 | |
1032 | void |
1321 | void |
1033 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
1322 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
1034 | PROTOTYPE: $$$;$ |
|
|
1035 | PPCODE: |
1323 | PPCODE: |
1036 | { |
1324 | { |
1037 | int fd = s_fileno_croak (fh, 0); |
1325 | int fd = s_fileno_croak (fh, 0); |
1038 | dREQ; |
1326 | dREQ; |
1039 | |
1327 | |
… | |
… | |
1054 | aio_statvfs = EIO_STATVFS |
1342 | aio_statvfs = EIO_STATVFS |
1055 | PPCODE: |
1343 | PPCODE: |
1056 | { |
1344 | { |
1057 | dREQ; |
1345 | dREQ; |
1058 | |
1346 | |
1059 | req->sv1 = newSVsv (fh_or_path); |
1347 | req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path); |
1060 | |
|
|
1061 | if (SvPOK (req->sv1)) |
|
|
1062 | { |
|
|
1063 | req->type = ix; |
|
|
1064 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1065 | } |
|
|
1066 | else |
|
|
1067 | { |
|
|
1068 | req->type = ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT; |
|
|
1069 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1070 | } |
|
|
1071 | |
1348 | |
1072 | REQ_SEND; |
1349 | REQ_SEND; |
1073 | } |
1350 | } |
|
|
1351 | |
|
|
1352 | UV |
|
|
1353 | major (UV dev) |
|
|
1354 | ALIAS: |
|
|
1355 | minor = 1 |
|
|
1356 | CODE: |
|
|
1357 | RETVAL = ix ? major (dev) : minor (dev); |
|
|
1358 | OUTPUT: |
|
|
1359 | RETVAL |
|
|
1360 | |
|
|
1361 | UV |
|
|
1362 | makedev (UV maj, UV min) |
|
|
1363 | CODE: |
|
|
1364 | RETVAL = makedev (maj, min); |
|
|
1365 | OUTPUT: |
|
|
1366 | RETVAL |
1074 | |
1367 | |
1075 | void |
1368 | void |
1076 | aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
1369 | aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
1077 | PPCODE: |
1370 | PPCODE: |
1078 | { |
1371 | { |
1079 | dREQ; |
1372 | dREQ; |
1080 | |
1373 | |
1081 | req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; |
1374 | req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; |
1082 | req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; |
1375 | req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; |
1083 | req->sv1 = newSVsv (fh_or_path); |
1376 | req_set_fh_or_path (req, EIO_UTIME, EIO_FUTIME, fh_or_path); |
1084 | |
|
|
1085 | if (SvPOK (req->sv1)) |
|
|
1086 | { |
|
|
1087 | req->type = EIO_UTIME; |
|
|
1088 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1089 | } |
|
|
1090 | else |
|
|
1091 | { |
|
|
1092 | req->type = EIO_FUTIME; |
|
|
1093 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1094 | } |
|
|
1095 | |
1377 | |
1096 | REQ_SEND; |
1378 | REQ_SEND; |
1097 | } |
1379 | } |
1098 | |
1380 | |
1099 | void |
1381 | void |
1100 | aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) |
1382 | aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) |
1101 | PPCODE: |
1383 | PPCODE: |
1102 | { |
1384 | { |
1103 | dREQ; |
1385 | dREQ; |
1104 | |
1386 | |
1105 | req->sv1 = newSVsv (fh_or_path); |
|
|
1106 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
1387 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
1107 | |
1388 | req_set_fh_or_path (req, EIO_TRUNCATE, EIO_FTRUNCATE, fh_or_path); |
1108 | if (SvPOK (req->sv1)) |
|
|
1109 | { |
|
|
1110 | req->type = EIO_TRUNCATE; |
|
|
1111 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1112 | } |
|
|
1113 | else |
|
|
1114 | { |
|
|
1115 | req->type = EIO_FTRUNCATE; |
|
|
1116 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1117 | } |
|
|
1118 | |
1389 | |
1119 | REQ_SEND; |
1390 | REQ_SEND; |
1120 | } |
1391 | } |
1121 | |
1392 | |
1122 | void |
1393 | void |
1123 | aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) |
1394 | aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) |
1124 | ALIAS: |
|
|
1125 | aio_chmod = EIO_CHMOD |
|
|
1126 | aio_mkdir = EIO_MKDIR |
|
|
1127 | PPCODE: |
1395 | PPCODE: |
1128 | { |
1396 | { |
1129 | dREQ; |
1397 | dREQ; |
1130 | |
1398 | |
1131 | req->int2 = mode; |
1399 | req->int2 = mode; |
1132 | req->sv1 = newSVsv (fh_or_path); |
1400 | req_set_fh_or_path (req, EIO_CHMOD, EIO_FCHMOD, fh_or_path); |
1133 | |
|
|
1134 | if (SvPOK (req->sv1)) |
|
|
1135 | { |
|
|
1136 | req->type = ix; |
|
|
1137 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1138 | } |
|
|
1139 | else |
|
|
1140 | { |
|
|
1141 | req->type = EIO_FCHMOD; |
|
|
1142 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1143 | } |
|
|
1144 | |
1401 | |
1145 | REQ_SEND; |
1402 | REQ_SEND; |
1146 | } |
1403 | } |
1147 | |
1404 | |
1148 | void |
1405 | void |
… | |
… | |
1151 | { |
1408 | { |
1152 | dREQ; |
1409 | dREQ; |
1153 | |
1410 | |
1154 | req->int2 = SvOK (uid) ? SvIV (uid) : -1; |
1411 | req->int2 = SvOK (uid) ? SvIV (uid) : -1; |
1155 | req->int3 = SvOK (gid) ? SvIV (gid) : -1; |
1412 | req->int3 = SvOK (gid) ? SvIV (gid) : -1; |
1156 | req->sv1 = newSVsv (fh_or_path); |
1413 | req_set_fh_or_path (req, EIO_CHOWN, EIO_FCHOWN, fh_or_path); |
1157 | |
|
|
1158 | if (SvPOK (req->sv1)) |
|
|
1159 | { |
|
|
1160 | req->type = EIO_CHOWN; |
|
|
1161 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1162 | } |
|
|
1163 | else |
|
|
1164 | { |
|
|
1165 | req->type = EIO_FCHOWN; |
|
|
1166 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1167 | } |
|
|
1168 | |
1414 | |
1169 | REQ_SEND; |
1415 | REQ_SEND; |
1170 | } |
1416 | } |
1171 | |
1417 | |
1172 | void |
1418 | void |
… | |
… | |
1174 | PPCODE: |
1420 | PPCODE: |
1175 | { |
1421 | { |
1176 | dREQ; |
1422 | dREQ; |
1177 | |
1423 | |
1178 | req->type = EIO_READDIR; |
1424 | req->type = EIO_READDIR; |
1179 | req->sv1 = newSVsv (pathname); |
|
|
1180 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1181 | req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; |
1425 | req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; |
1182 | |
1426 | |
1183 | if (flags & EIO_READDIR_DENTS) |
1427 | if (flags & EIO_READDIR_DENTS) |
1184 | req->int1 |= EIO_READDIR_CUSTOM2; |
1428 | req->int1 |= EIO_READDIR_CUSTOM2; |
1185 | |
1429 | |
|
|
1430 | req_set_path1 (req, pathname); |
|
|
1431 | |
1186 | REQ_SEND; |
1432 | REQ_SEND; |
|
|
1433 | } |
|
|
1434 | |
|
|
1435 | void |
|
|
1436 | aio_mkdir (SV8 *pathname, int mode, SV *callback=&PL_sv_undef) |
|
|
1437 | PPCODE: |
|
|
1438 | { |
|
|
1439 | dREQ; |
|
|
1440 | |
|
|
1441 | req->type = EIO_MKDIR; |
|
|
1442 | req->int2 = mode; |
|
|
1443 | req_set_path1 (req, pathname); |
|
|
1444 | |
|
|
1445 | REQ_SEND; |
1187 | } |
1446 | } |
1188 | |
1447 | |
1189 | void |
1448 | void |
1190 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
1449 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
1191 | ALIAS: |
1450 | ALIAS: |
… | |
… | |
1195 | PPCODE: |
1454 | PPCODE: |
1196 | { |
1455 | { |
1197 | dREQ; |
1456 | dREQ; |
1198 | |
1457 | |
1199 | req->type = ix; |
1458 | req->type = ix; |
1200 | req->sv1 = newSVsv (pathname); |
1459 | req_set_path1 (req, pathname); |
1201 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1202 | |
1460 | |
1203 | REQ_SEND; |
1461 | REQ_SEND; |
1204 | } |
1462 | } |
1205 | |
1463 | |
1206 | void |
1464 | void |
… | |
… | |
1209 | aio_link = EIO_LINK |
1467 | aio_link = EIO_LINK |
1210 | aio_symlink = EIO_SYMLINK |
1468 | aio_symlink = EIO_SYMLINK |
1211 | aio_rename = EIO_RENAME |
1469 | aio_rename = EIO_RENAME |
1212 | PPCODE: |
1470 | PPCODE: |
1213 | { |
1471 | { |
|
|
1472 | eio_wd wd2 = 0; |
1214 | dREQ; |
1473 | dREQ; |
1215 | |
1474 | |
1216 | req->type = ix; |
1475 | req->type = ix; |
1217 | req->sv1 = newSVsv (oldpath); |
1476 | req_set_path1 (req, oldpath); |
1218 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1477 | req_set_path (req, newpath, &req->sv2, &req->sv4, &wd2, &req->ptr2); |
1219 | req->sv2 = newSVsv (newpath); |
1478 | req->int3 = (long)wd2; |
1220 | req->ptr2 = SvPVbyte_nolen (req->sv2); |
|
|
1221 | |
1479 | |
1222 | REQ_SEND; |
1480 | REQ_SEND; |
1223 | } |
1481 | } |
1224 | |
1482 | |
1225 | void |
1483 | void |
… | |
… | |
1227 | PPCODE: |
1485 | PPCODE: |
1228 | { |
1486 | { |
1229 | dREQ; |
1487 | dREQ; |
1230 | |
1488 | |
1231 | req->type = EIO_MKNOD; |
1489 | req->type = EIO_MKNOD; |
1232 | req->sv1 = newSVsv (pathname); |
|
|
1233 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1234 | req->int2 = (mode_t)mode; |
1490 | req->int2 = (mode_t)mode; |
1235 | req->offs = dev; |
1491 | req->offs = dev; |
|
|
1492 | req_set_path1 (req, pathname); |
1236 | |
1493 | |
1237 | REQ_SEND; |
1494 | REQ_SEND; |
1238 | } |
1495 | } |
1239 | |
1496 | |
1240 | void |
1497 | void |
1241 | aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) |
1498 | aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) |
1242 | ALIAS: |
1499 | ALIAS: |
1243 | aio_mtouch = EIO_MTOUCH |
1500 | aio_mtouch = EIO_MTOUCH |
1244 | aio_msync = EIO_MSYNC |
1501 | aio_msync = EIO_MSYNC |
1245 | PROTOTYPE: $$$$;$ |
|
|
1246 | PPCODE: |
1502 | PPCODE: |
1247 | { |
1503 | { |
1248 | STRLEN svlen; |
1504 | STRLEN svlen; |
|
|
1505 | char *svptr = SvPVbyte (data, svlen); |
1249 | UV len = SvUV (length); |
1506 | UV len = SvUV (length); |
1250 | char *svptr = SvPVbyte (data, svlen); |
|
|
1251 | |
1507 | |
1252 | if (offset < 0) |
1508 | if (offset < 0) |
1253 | offset += svlen; |
1509 | offset += svlen; |
1254 | |
1510 | |
1255 | if (offset < 0 || offset > svlen) |
1511 | if (offset < 0 || offset > svlen) |
… | |
… | |
1260 | |
1516 | |
1261 | { |
1517 | { |
1262 | dREQ; |
1518 | dREQ; |
1263 | |
1519 | |
1264 | req->type = ix; |
1520 | req->type = ix; |
1265 | req->size = len; |
|
|
1266 | req->sv2 = SvREFCNT_inc (data); |
1521 | req->sv2 = SvREFCNT_inc (data); |
1267 | req->ptr2 = (char *)svptr + offset; |
1522 | req->ptr2 = (char *)svptr + offset; |
|
|
1523 | req->size = len; |
1268 | req->int1 = flags; |
1524 | req->int1 = flags; |
1269 | |
1525 | |
1270 | REQ_SEND; |
1526 | REQ_SEND; |
1271 | } |
1527 | } |
1272 | } |
1528 | } |
1273 | |
1529 | |
1274 | void |
1530 | void |
|
|
1531 | aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef) |
|
|
1532 | PPCODE: |
|
|
1533 | { |
|
|
1534 | STRLEN svlen; |
|
|
1535 | char *svptr = SvPVbyte (data, svlen); |
|
|
1536 | UV len = SvUV (length); |
|
|
1537 | |
|
|
1538 | if (offset < 0) |
|
|
1539 | offset += svlen; |
|
|
1540 | |
|
|
1541 | if (offset < 0 || offset > svlen) |
|
|
1542 | croak ("offset outside of scalar"); |
|
|
1543 | |
|
|
1544 | if (!SvOK (length) || len + offset > svlen) |
|
|
1545 | len = svlen - offset; |
|
|
1546 | |
|
|
1547 | { |
|
|
1548 | dREQ; |
|
|
1549 | |
|
|
1550 | req->type = EIO_MLOCK; |
|
|
1551 | req->sv2 = SvREFCNT_inc (data); |
|
|
1552 | req->ptr2 = (char *)svptr + offset; |
|
|
1553 | req->size = len; |
|
|
1554 | |
|
|
1555 | REQ_SEND; |
|
|
1556 | } |
|
|
1557 | } |
|
|
1558 | |
|
|
1559 | void |
|
|
1560 | aio_mlockall (IV flags, SV *callback=&PL_sv_undef) |
|
|
1561 | PPCODE: |
|
|
1562 | { |
|
|
1563 | dREQ; |
|
|
1564 | |
|
|
1565 | req->type = EIO_MLOCKALL; |
|
|
1566 | req->int1 = flags; |
|
|
1567 | |
|
|
1568 | REQ_SEND; |
|
|
1569 | } |
|
|
1570 | |
|
|
1571 | void |
1275 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1572 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1276 | PPCODE: |
1573 | PPCODE: |
1277 | { |
1574 | { |
1278 | dREQ; |
1575 | dREQ; |
1279 | |
1576 | |
… | |
… | |
1283 | REQ_SEND; |
1580 | REQ_SEND; |
1284 | } |
1581 | } |
1285 | |
1582 | |
1286 | void |
1583 | void |
1287 | aio_group (SV *callback=&PL_sv_undef) |
1584 | aio_group (SV *callback=&PL_sv_undef) |
1288 | PROTOTYPE: ;$ |
|
|
1289 | PPCODE: |
1585 | PPCODE: |
1290 | { |
1586 | { |
1291 | dREQ; |
1587 | dREQ; |
1292 | |
1588 | |
1293 | req->type = EIO_GROUP; |
1589 | req->type = EIO_GROUP; |
… | |
… | |
1310 | REQ_SEND; |
1606 | REQ_SEND; |
1311 | } |
1607 | } |
1312 | |
1608 | |
1313 | int |
1609 | int |
1314 | aioreq_pri (int pri = 0) |
1610 | aioreq_pri (int pri = 0) |
1315 | PROTOTYPE: ;$ |
|
|
1316 | CODE: |
1611 | CODE: |
1317 | RETVAL = next_pri; |
1612 | RETVAL = next_pri; |
1318 | if (items > 0) |
1613 | if (items > 0) |
1319 | { |
1614 | { |
1320 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
1615 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
… | |
… | |
1332 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1627 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1333 | next_pri = nice; |
1628 | next_pri = nice; |
1334 | |
1629 | |
1335 | void |
1630 | void |
1336 | flush () |
1631 | flush () |
1337 | PROTOTYPE: |
|
|
1338 | CODE: |
1632 | CODE: |
1339 | while (eio_nreqs ()) |
1633 | while (eio_nreqs ()) |
1340 | { |
1634 | { |
1341 | poll_wait (); |
1635 | poll_wait (); |
1342 | poll_cb (); |
1636 | poll_cb (); |
1343 | } |
1637 | } |
1344 | |
1638 | |
1345 | int |
1639 | int |
1346 | poll() |
1640 | poll () |
1347 | PROTOTYPE: |
|
|
1348 | CODE: |
1641 | CODE: |
1349 | poll_wait (); |
1642 | poll_wait (); |
1350 | RETVAL = poll_cb (); |
1643 | RETVAL = poll_cb (); |
1351 | OUTPUT: |
1644 | OUTPUT: |
1352 | RETVAL |
1645 | RETVAL |
1353 | |
1646 | |
1354 | int |
1647 | int |
1355 | poll_fileno() |
1648 | poll_fileno () |
1356 | PROTOTYPE: |
|
|
1357 | CODE: |
1649 | CODE: |
1358 | RETVAL = s_epipe_fd (&respipe); |
1650 | RETVAL = s_epipe_fd (&respipe); |
1359 | OUTPUT: |
1651 | OUTPUT: |
1360 | RETVAL |
1652 | RETVAL |
1361 | |
1653 | |
1362 | int |
1654 | int |
1363 | poll_cb(...) |
1655 | poll_cb (...) |
1364 | PROTOTYPE: |
1656 | PROTOTYPE: |
1365 | CODE: |
1657 | CODE: |
1366 | RETVAL = poll_cb (); |
1658 | RETVAL = poll_cb (); |
1367 | OUTPUT: |
1659 | OUTPUT: |
1368 | RETVAL |
1660 | RETVAL |
1369 | |
1661 | |
1370 | void |
1662 | void |
1371 | poll_wait() |
1663 | poll_wait () |
1372 | PROTOTYPE: |
|
|
1373 | CODE: |
1664 | CODE: |
1374 | poll_wait (); |
1665 | poll_wait (); |
1375 | |
1666 | |
1376 | int |
1667 | int |
1377 | nreqs() |
1668 | nreqs () |
1378 | PROTOTYPE: |
|
|
1379 | CODE: |
1669 | CODE: |
1380 | RETVAL = eio_nreqs (); |
1670 | RETVAL = eio_nreqs (); |
1381 | OUTPUT: |
1671 | OUTPUT: |
1382 | RETVAL |
1672 | RETVAL |
1383 | |
1673 | |
1384 | int |
1674 | int |
1385 | nready() |
1675 | nready () |
1386 | PROTOTYPE: |
|
|
1387 | CODE: |
1676 | CODE: |
1388 | RETVAL = eio_nready (); |
1677 | RETVAL = eio_nready (); |
1389 | OUTPUT: |
1678 | OUTPUT: |
1390 | RETVAL |
1679 | RETVAL |
1391 | |
1680 | |
1392 | int |
1681 | int |
1393 | npending() |
1682 | npending () |
1394 | PROTOTYPE: |
|
|
1395 | CODE: |
1683 | CODE: |
1396 | RETVAL = eio_npending (); |
1684 | RETVAL = eio_npending (); |
1397 | OUTPUT: |
1685 | OUTPUT: |
1398 | RETVAL |
1686 | RETVAL |
1399 | |
1687 | |
1400 | int |
1688 | int |
1401 | nthreads() |
1689 | nthreads () |
1402 | PROTOTYPE: |
|
|
1403 | CODE: |
1690 | CODE: |
1404 | RETVAL = eio_nthreads (); |
1691 | RETVAL = eio_nthreads (); |
1405 | OUTPUT: |
1692 | OUTPUT: |
1406 | RETVAL |
1693 | RETVAL |
1407 | |
1694 | |
1408 | int |
1695 | int |
1409 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1696 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1410 | PROTOTYPE: $$$$ |
|
|
1411 | CODE: |
1697 | CODE: |
1412 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1698 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1413 | OUTPUT: |
1699 | OUTPUT: |
1414 | RETVAL |
1700 | RETVAL |
1415 | |
1701 | |
1416 | ssize_t |
1702 | IV |
1417 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1703 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1418 | PROTOTYPE: $$$$ |
|
|
1419 | CODE: |
1704 | CODE: |
1420 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1705 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1421 | OUTPUT: |
1706 | OUTPUT: |
1422 | RETVAL |
1707 | RETVAL |
1423 | |
1708 | |
1424 | void |
1709 | void |
1425 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) |
1710 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) |
1426 | PROTOTYPE: $$$$$;$ |
|
|
1427 | PPCODE: |
1711 | PPCODE: |
1428 | sv_unmagic (scalar, MMAP_MAGIC); |
1712 | sv_unmagic (scalar, MMAP_MAGIC); |
1429 | { |
1713 | { |
1430 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
1714 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
1431 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
1715 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
… | |
… | |
1454 | XSRETURN_YES; |
1738 | XSRETURN_YES; |
1455 | } |
1739 | } |
1456 | |
1740 | |
1457 | void |
1741 | void |
1458 | munmap (SV *scalar) |
1742 | munmap (SV *scalar) |
1459 | PROTOTYPE: $ |
|
|
1460 | CODE: |
1743 | CODE: |
1461 | sv_unmagic (scalar, MMAP_MAGIC); |
1744 | sv_unmagic (scalar, MMAP_MAGIC); |
1462 | |
1745 | |
1463 | int |
1746 | int |
1464 | madvise (SV *scalar, off_t offset, off_t length, IV advice_or_prot) |
1747 | madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
1465 | ALIAS: |
1748 | ALIAS: |
1466 | mprotect = 1 |
1749 | mprotect = 1 |
1467 | PROTOTYPE: $$$$ |
|
|
1468 | CODE: |
1750 | CODE: |
1469 | { |
1751 | { |
1470 | STRLEN cur; |
1752 | STRLEN svlen; |
1471 | char *addr = SvPVbyte (scalar, cur); |
1753 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1754 | size_t len = SvUV (length); |
1472 | |
1755 | |
1473 | if (offset > cur) |
1756 | if (offset < 0) |
1474 | RETVAL = errno = EFAULT; |
1757 | offset += svlen; |
1475 | else |
1758 | |
|
|
1759 | if (offset < 0 || offset > svlen) |
|
|
1760 | croak ("offset outside of scalar"); |
|
|
1761 | |
|
|
1762 | if (!SvOK (length) || len + offset > svlen) |
|
|
1763 | len = svlen - offset; |
|
|
1764 | |
|
|
1765 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1766 | eio_page_align (&addr, &len); |
|
|
1767 | |
|
|
1768 | switch (ix) |
1476 | { |
1769 | { |
1477 | if (!SvOK (ST (2))) |
|
|
1478 | length = cur - offset; |
|
|
1479 | |
|
|
1480 | if (offset + length > cur) |
|
|
1481 | RETVAL = errno = EFAULT; |
|
|
1482 | else |
|
|
1483 | switch (ix) |
|
|
1484 | { |
|
|
1485 | case 0: RETVAL = posix_madvise (addr + offset, length, advice_or_prot); break; |
1770 | case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break; |
1486 | case 1: RETVAL = mprotect (addr + offset, length, advice_or_prot); break; |
1771 | case 1: RETVAL = mprotect (addr, len, advice_or_prot); break; |
1487 | } |
|
|
1488 | } |
1772 | } |
1489 | } |
1773 | } |
1490 | OUTPUT: |
1774 | OUTPUT: |
1491 | RETVAL |
1775 | RETVAL |
1492 | |
1776 | |
1493 | int |
1777 | int |
1494 | mlockall (int flags) |
1778 | munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) |
1495 | PROTOTYPE: $ |
|
|
1496 | CODE: |
1779 | CODE: |
|
|
1780 | { |
|
|
1781 | STRLEN svlen; |
|
|
1782 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1783 | size_t len = SvUV (length); |
|
|
1784 | |
|
|
1785 | if (offset < 0) |
|
|
1786 | offset += svlen; |
|
|
1787 | |
|
|
1788 | if (offset < 0 || offset > svlen) |
|
|
1789 | croak ("offset outside of scalar"); |
|
|
1790 | |
|
|
1791 | if (!SvOK (length) || len + offset > svlen) |
|
|
1792 | len = svlen - offset; |
|
|
1793 | |
|
|
1794 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1795 | eio_page_align (&addr, &len); |
1497 | #if _POSIX_MEMLOCK |
1796 | #if _POSIX_MEMLOCK_RANGE |
1498 | #if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 |
1797 | RETVAL = munlock (addr, len); |
1499 | extern int mallopt (int, int); |
|
|
1500 | mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */ |
|
|
1501 | #endif |
|
|
1502 | mlockall (flags); |
|
|
1503 | #else |
1798 | #else |
1504 | RETVAL = -1; |
1799 | RETVAL = ((errno = ENOSYS), -1); |
1505 | errno = ENOSYS; |
|
|
1506 | #endif |
1800 | #endif |
|
|
1801 | } |
1507 | OUTPUT: |
1802 | OUTPUT: |
1508 | RETVAL |
1803 | RETVAL |
1509 | |
1804 | |
1510 | int |
1805 | int |
1511 | munlockall () |
1806 | munlockall () |
1512 | PROTOTYPE: |
|
|
1513 | CODE: |
1807 | CODE: |
1514 | #if _POSIX_MEMLOCK |
1808 | #if _POSIX_MEMLOCK |
1515 | munlockall (); |
1809 | munlockall (); |
1516 | #else |
1810 | #else |
1517 | RETVAL = -1; |
1811 | RETVAL = -1; |
… | |
… | |
1525 | SvREFCNT_dec (on_next_submit); |
1819 | SvREFCNT_dec (on_next_submit); |
1526 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1820 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1527 | |
1821 | |
1528 | PROTOTYPES: DISABLE |
1822 | PROTOTYPES: DISABLE |
1529 | |
1823 | |
|
|
1824 | MODULE = IO::AIO PACKAGE = IO::AIO::WD |
|
|
1825 | |
|
|
1826 | BOOT: |
|
|
1827 | { |
|
|
1828 | newCONSTSUB (aio_stash, "CWD" , newSVaio_wd (EIO_CWD )); |
|
|
1829 | newCONSTSUB (aio_stash, "INVALID_WD", newSVaio_wd (EIO_INVALID_WD)); |
|
|
1830 | } |
|
|
1831 | |
|
|
1832 | void |
|
|
1833 | DESTROY (SV *self) |
|
|
1834 | CODE: |
|
|
1835 | { |
|
|
1836 | aio_wd wd = SvAIO_WD (self); |
|
|
1837 | #if HAVE_AT |
|
|
1838 | { |
|
|
1839 | SV *callback = &PL_sv_undef; |
|
|
1840 | dREQ; /* clobbers next_pri :/ */ |
|
|
1841 | next_pri = req->pri; /* restore next_pri */ |
|
|
1842 | req->pri = EIO_PRI_MAX; /* better use max. priority to conserve fds */ |
|
|
1843 | req->type = EIO_WD_CLOSE; |
|
|
1844 | req->wd = wd; |
|
|
1845 | REQ_SEND; |
|
|
1846 | } |
|
|
1847 | #else |
|
|
1848 | eio_wd_close_sync (wd); |
|
|
1849 | #endif |
|
|
1850 | } |
|
|
1851 | |
1530 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1852 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1531 | |
1853 | |
1532 | void |
1854 | void |
1533 | cancel (aio_req_ornot req) |
1855 | cancel (aio_req_ornot req) |
1534 | CODE: |
1856 | CODE: |