… | |
… | |
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 | #if __linux__ |
|
|
25 | # include <linux/fs.h> |
|
|
26 | # ifdef FS_IOC_FIEMAP |
|
|
27 | # include <linux/types.h> |
|
|
28 | # include <linux/fiemap.h> |
|
|
29 | # define HAVE_FIEMAP 1 |
|
|
30 | # endif |
|
|
31 | #endif |
|
|
32 | |
18 | /* perl namespace pollution */ |
33 | /* perl namespace pollution */ |
19 | #undef VERSION |
34 | #undef VERSION |
20 | |
|
|
21 | #ifdef _WIN32 |
|
|
22 | |
|
|
23 | # define EIO_STRUCT_DIRENT Direntry_t |
|
|
24 | # undef malloc |
|
|
25 | # undef free |
|
|
26 | |
|
|
27 | // perl overrides all those nice win32 functions |
|
|
28 | # undef open |
|
|
29 | # undef read |
|
|
30 | # undef write |
|
|
31 | # undef send |
|
|
32 | # undef recv |
|
|
33 | # undef stat |
|
|
34 | # undef fstat |
|
|
35 | # define lstat stat |
|
|
36 | # undef truncate |
|
|
37 | # undef ftruncate |
|
|
38 | # undef open |
|
|
39 | # undef close |
|
|
40 | # undef unlink |
|
|
41 | # undef rmdir |
|
|
42 | # undef rename |
|
|
43 | # undef lseek |
|
|
44 | |
|
|
45 | # define chown(a,b,c) (errno = ENOSYS, -1) |
|
|
46 | # define fchown(a,b,c) (errno = ENOSYS, -1) |
|
|
47 | # define fchmod(a,b) (errno = ENOSYS, -1) |
|
|
48 | # define symlink(a,b) (errno = ENOSYS, -1) |
|
|
49 | # define readlink(a,b,c) (errno = ENOSYS, -1) |
|
|
50 | # define mknod(a,b,c) (errno = ENOSYS, -1) |
|
|
51 | # define truncate(a,b) (errno = ENOSYS, -1) |
|
|
52 | # define ftruncate(fd,o) chsize ((fd), (o)) |
|
|
53 | # define fsync(fd) _commit (fd) |
|
|
54 | # define opendir(fd) (errno = ENOSYS, 0) |
|
|
55 | # define readdir(fd) (errno = ENOSYS, -1) |
|
|
56 | # define closedir(fd) (errno = ENOSYS, -1) |
|
|
57 | # define mkdir(a,b) mkdir (a) |
|
|
58 | |
|
|
59 | #else |
|
|
60 | |
|
|
61 | # include <sys/time.h> |
|
|
62 | # include <sys/select.h> |
|
|
63 | # include <unistd.h> |
|
|
64 | # include <utime.h> |
|
|
65 | # include <signal.h> |
|
|
66 | # define EIO_STRUCT_DIRENT struct dirent |
|
|
67 | |
|
|
68 | #endif |
|
|
69 | |
35 | |
70 | /* perl stupidly overrides readdir and maybe others */ |
36 | /* perl stupidly overrides readdir and maybe others */ |
71 | /* with thread-unsafe versions, imagine that :( */ |
37 | /* with thread-unsafe versions, imagine that :( */ |
72 | #undef readdir |
38 | #undef readdir |
73 | #undef opendir |
39 | #undef opendir |
74 | #undef closedir |
40 | #undef closedir |
75 | |
41 | |
|
|
42 | #ifdef _WIN32 |
|
|
43 | |
|
|
44 | // perl overrides all those nice libc functions |
|
|
45 | |
|
|
46 | #undef malloc |
|
|
47 | #undef free |
|
|
48 | #undef open |
|
|
49 | #undef read |
|
|
50 | #undef write |
|
|
51 | #undef send |
|
|
52 | #undef recv |
|
|
53 | #undef stat |
|
|
54 | #undef lstat |
|
|
55 | #undef fstat |
|
|
56 | #undef truncate |
|
|
57 | #undef ftruncate |
|
|
58 | #undef open |
|
|
59 | #undef link |
|
|
60 | #undef close |
|
|
61 | #undef unlink |
|
|
62 | #undef mkdir |
|
|
63 | #undef rmdir |
|
|
64 | #undef rename |
|
|
65 | #undef lseek |
|
|
66 | #undef opendir |
|
|
67 | #undef readdir |
|
|
68 | #undef closedir |
|
|
69 | #undef chmod |
|
|
70 | #undef fchmod |
|
|
71 | #undef dup |
|
|
72 | #undef dup2 |
|
|
73 | #undef abort |
|
|
74 | #undef pipe |
|
|
75 | |
|
|
76 | #define EIO_STRUCT_STAT struct _stati64 |
76 | #define EIO_STRUCT_STAT Stat_t |
77 | #define EIO_STRUCT_STATI64 |
77 | |
78 | |
78 | /* use NV for 32 bit perls as it allows larger offsets */ |
|
|
79 | #if IVSIZE >= 8 |
|
|
80 | # define VAL64 IV |
|
|
81 | # define SvVAL64 SvIV |
|
|
82 | # define newSVval64 newSViv |
|
|
83 | #else |
79 | #else |
84 | # define VAL64 NV |
80 | |
85 | # define SvVAL64 SvNV |
81 | #include <sys/time.h> |
86 | # define newSVval64 newSVnv |
82 | #include <sys/select.h> |
|
|
83 | #include <unistd.h> |
|
|
84 | #include <utime.h> |
|
|
85 | #include <signal.h> |
|
|
86 | |
|
|
87 | #define EIO_STRUCT_STAT Stat_t |
|
|
88 | |
87 | #endif |
89 | #endif |
88 | |
90 | |
89 | /*****************************************************************************/ |
91 | /*****************************************************************************/ |
90 | |
92 | |
91 | #if __GNUC__ >= 3 |
93 | #if __GNUC__ >= 3 |
… | |
… | |
97 | #define expect_false(expr) expect ((expr) != 0, 0) |
99 | #define expect_false(expr) expect ((expr) != 0, 0) |
98 | #define expect_true(expr) expect ((expr) != 0, 1) |
100 | #define expect_true(expr) expect ((expr) != 0, 1) |
99 | |
101 | |
100 | /*****************************************************************************/ |
102 | /*****************************************************************************/ |
101 | |
103 | |
102 | static HV *stash; |
|
|
103 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
104 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
104 | typedef int aio_rfd; /* read file desriptor */ |
105 | typedef int aio_rfd; /* read file desriptor */ |
105 | typedef int aio_wfd; /* write file descriptor */ |
106 | typedef int aio_wfd; /* write file descriptor */ |
106 | |
107 | |
107 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
108 | static HV *aio_stash, *aio_req_stash, *aio_grp_stash, *aio_wd_stash; |
108 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
|
|
109 | |
109 | |
110 | #define EIO_REQ_MEMBERS \ |
110 | #define EIO_REQ_MEMBERS \ |
111 | SV *callback; \ |
111 | SV *callback; \ |
112 | SV *sv1, *sv2; \ |
112 | SV *sv1, *sv2; \ |
|
|
113 | SV *sv3, *sv4; \ |
113 | STRLEN stroffset; \ |
114 | STRLEN stroffset; \ |
114 | SV *self; |
115 | SV *self; |
115 | |
116 | |
116 | #define EIO_NO_WRAPPERS 1 |
117 | #define EIO_NO_WRAPPERS 1 |
117 | |
118 | |
|
|
119 | #include "libeio/config.h" |
118 | #include "libeio/eio.h" |
120 | #include "libeio/eio.h" |
119 | |
|
|
120 | #ifndef POSIX_FADV_NORMAL |
|
|
121 | # define POSIX_FADV_NORMAL 0 |
|
|
122 | #endif |
|
|
123 | |
|
|
124 | #ifndef POSIX_FADV_SEQUENTIAL |
|
|
125 | # define POSIX_FADV_SEQUENTIAL 0 |
|
|
126 | #endif |
|
|
127 | |
|
|
128 | #ifndef POSIX_FADV_RANDOM |
|
|
129 | # define POSIX_FADV_RANDOM 0 |
|
|
130 | #endif |
|
|
131 | |
|
|
132 | #ifndef POSIX_FADV_NOREUSE |
|
|
133 | # define POSIX_FADV_NOREUSE 0 |
|
|
134 | #endif |
|
|
135 | |
|
|
136 | #ifndef POSIX_FADV_WILLNEED |
|
|
137 | # define POSIX_FADV_WILLNEED 0 |
|
|
138 | #endif |
|
|
139 | |
|
|
140 | #ifndef POSIX_FADV_DONTNEED |
|
|
141 | # define POSIX_FADV_DONTNEED 0 |
|
|
142 | #endif |
|
|
143 | |
121 | |
144 | static int req_invoke (eio_req *req); |
122 | static int req_invoke (eio_req *req); |
145 | #define EIO_FINISH(req) req_invoke (req) |
123 | #define EIO_FINISH(req) req_invoke (req) |
146 | static void req_destroy (eio_req *grp); |
124 | static void req_destroy (eio_req *grp); |
147 | #define EIO_DESTROY(req) req_destroy (req) |
125 | #define EIO_DESTROY(req) req_destroy (req) |
148 | |
126 | |
|
|
127 | #include "libeio/eio.c" |
|
|
128 | |
|
|
129 | #if !HAVE_POSIX_FADVISE |
|
|
130 | # define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */ |
|
|
131 | #endif |
|
|
132 | |
|
|
133 | #if !HAVE_POSIX_MADVISE |
|
|
134 | # define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ |
|
|
135 | #endif |
|
|
136 | |
|
|
137 | #ifndef MAP_ANONYMOUS |
|
|
138 | # ifdef MAP_ANON |
|
|
139 | # define MAP_ANONYMOUS MAP_ANON |
|
|
140 | # else |
|
|
141 | # define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ |
|
|
142 | # endif |
|
|
143 | #endif |
|
|
144 | |
|
|
145 | /* defines all sorts of constants to 0 unless they are already defined */ |
|
|
146 | #include "def0.h" |
|
|
147 | |
|
|
148 | #ifndef makedev |
|
|
149 | # define makedev(maj,min) (((maj) << 8) | (min)) |
|
|
150 | #endif |
|
|
151 | #ifndef major |
|
|
152 | # define major(dev) ((dev) >> 8) |
|
|
153 | #endif |
|
|
154 | #ifndef minor |
|
|
155 | # define minor(dev) ((dev) & 0xff) |
|
|
156 | #endif |
|
|
157 | |
|
|
158 | #if PAGESIZE <= 0 |
|
|
159 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
|
|
160 | #endif |
|
|
161 | |
|
|
162 | /*****************************************************************************/ |
|
|
163 | |
|
|
164 | static void |
|
|
165 | fiemap (eio_req *req) |
|
|
166 | { |
|
|
167 | req->result = -1; |
|
|
168 | |
|
|
169 | #if HAVE_FIEMAP |
|
|
170 | /* assume some c99 */ |
|
|
171 | struct fiemap *fiemap = 0; |
|
|
172 | size_t end_offset; |
|
|
173 | int count = req->int3; |
|
|
174 | |
|
|
175 | req->flags |= EIO_FLAG_PTR1_FREE; |
|
|
176 | |
|
|
177 | /* heuristic: start with 512 bytes (8 extents), and if that isn't enough, */ |
|
|
178 | /* increase in 3.5kb steps */ |
|
|
179 | if (count < 0) |
|
|
180 | count = 8; |
|
|
181 | |
|
|
182 | fiemap = malloc (sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); |
|
|
183 | errno = ENOMEM; |
|
|
184 | if (!fiemap) |
|
|
185 | return; |
|
|
186 | |
|
|
187 | req->ptr1 = fiemap; |
|
|
188 | |
|
|
189 | fiemap->fm_start = req->offs; |
|
|
190 | fiemap->fm_length = req->size; |
|
|
191 | fiemap->fm_flags = req->int2; |
|
|
192 | fiemap->fm_extent_count = count; |
|
|
193 | |
|
|
194 | if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap) < 0) |
|
|
195 | return; |
|
|
196 | |
|
|
197 | if (req->int3 >= 0 /* not autosizing */ |
|
|
198 | || !fiemap->fm_mapped_extents /* no more extents */ |
|
|
199 | || fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST /* hit eof */) |
|
|
200 | goto done; |
|
|
201 | |
|
|
202 | /* else we have to loop - |
|
|
203 | * it would be tempting (atcually I tried that first) to just query the |
|
|
204 | * number of extents needed, but linux often feels like not returning all |
|
|
205 | * extents, without telling us it left any out. this complicates |
|
|
206 | * this quite a bit. |
|
|
207 | */ |
|
|
208 | |
|
|
209 | end_offset = fiemap->fm_length + (fiemap->fm_length == FIEMAP_MAX_OFFSET ? 0 : fiemap->fm_start); |
|
|
210 | |
|
|
211 | for (;;) |
|
|
212 | { |
|
|
213 | /* we go in 54 extent steps - 3kb, in the hope that this fits nicely on the eio stack (normally 16+ kb) */ |
|
|
214 | char scratch[3072]; |
|
|
215 | struct fiemap *incmap = (struct fiemap *)scratch; |
|
|
216 | |
|
|
217 | incmap->fm_start = fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_logical |
|
|
218 | + fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_length; |
|
|
219 | incmap->fm_length = fiemap->fm_length - (incmap->fm_start - fiemap->fm_start); |
|
|
220 | incmap->fm_flags = fiemap->fm_flags; |
|
|
221 | incmap->fm_extent_count = (sizeof (scratch) - sizeof (struct fiemap)) / sizeof (struct fiemap_extent); |
|
|
222 | |
|
|
223 | if (ioctl (req->int1, FS_IOC_FIEMAP, incmap) < 0) |
|
|
224 | return; |
|
|
225 | |
|
|
226 | count = fiemap->fm_mapped_extents + incmap->fm_mapped_extents; |
|
|
227 | fiemap = realloc (fiemap, sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); |
|
|
228 | errno = ENOMEM; |
|
|
229 | if (!fiemap) |
|
|
230 | return; |
|
|
231 | |
|
|
232 | req->ptr1 = fiemap; |
|
|
233 | |
|
|
234 | for (count = 0; count < incmap->fm_mapped_extents; ++count) |
|
|
235 | { |
|
|
236 | struct fiemap_extent *e = incmap->fm_extents + count; |
|
|
237 | |
|
|
238 | if (e->fe_logical + e->fe_length >= end_offset) |
|
|
239 | goto done; |
|
|
240 | |
|
|
241 | fiemap->fm_extents [fiemap->fm_mapped_extents++] = *e; |
|
|
242 | |
|
|
243 | if (e->fe_flags & FIEMAP_EXTENT_LAST) |
|
|
244 | goto done; |
|
|
245 | |
|
|
246 | } |
|
|
247 | } |
|
|
248 | |
|
|
249 | done: |
|
|
250 | req->result = 0; |
|
|
251 | |
|
|
252 | #else |
|
|
253 | errno = ENOSYS; |
|
|
254 | #endif |
|
|
255 | } |
|
|
256 | |
|
|
257 | /*****************************************************************************/ |
|
|
258 | |
149 | enum { |
259 | enum { |
150 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
260 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
151 | }; |
261 | }; |
152 | |
262 | |
153 | #include "libeio/eio.c" |
|
|
154 | |
|
|
155 | typedef eio_req *aio_req; |
263 | typedef eio_req *aio_req; |
156 | typedef eio_req *aio_req_ornot; |
264 | typedef eio_req *aio_req_ornot; |
|
|
265 | typedef eio_wd aio_wd; |
157 | |
266 | |
158 | static SV *on_next_submit; |
267 | static SV *on_next_submit; |
159 | static int next_pri = EIO_PRI_DEFAULT; |
268 | static int next_pri = EIO_PRI_DEFAULT; |
160 | static int max_outstanding; |
269 | static int max_outstanding; |
161 | |
270 | |
162 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
271 | static s_epipe respipe; |
163 | |
272 | |
164 | static void req_destroy (aio_req req); |
273 | static void req_destroy (aio_req req); |
165 | static void req_cancel (aio_req req); |
274 | static void req_cancel (aio_req req); |
166 | |
275 | |
167 | static void want_poll (void) |
276 | static void |
|
|
277 | want_poll (void) |
168 | { |
278 | { |
169 | /* write a dummy byte to the pipe so fh becomes ready */ |
279 | /* write a dummy byte to the pipe so fh becomes ready */ |
170 | respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); |
280 | s_epipe_signal (&respipe); |
171 | } |
281 | } |
172 | |
282 | |
173 | static void done_poll (void) |
283 | static void |
|
|
284 | done_poll (void) |
174 | { |
285 | { |
175 | /* read any signals sent by the worker threads */ |
286 | /* read any signals sent by the worker threads */ |
176 | char buf [4]; |
287 | s_epipe_drain (&respipe); |
177 | while (respipe_read (respipe [0], buf, 4) == 4) |
|
|
178 | ; |
|
|
179 | } |
288 | } |
180 | |
289 | |
181 | /* must be called at most once */ |
290 | /* must be called at most once */ |
182 | static SV *req_sv (aio_req req, const char *klass) |
291 | static SV * |
|
|
292 | req_sv (aio_req req, HV *stash) |
183 | { |
293 | { |
184 | if (!req->self) |
294 | if (!req->self) |
185 | { |
295 | { |
186 | req->self = (SV *)newHV (); |
296 | req->self = (SV *)newHV (); |
187 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
297 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
188 | } |
298 | } |
189 | |
299 | |
190 | return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1))); |
300 | return sv_2mortal (sv_bless (newRV_inc (req->self), stash)); |
191 | } |
301 | } |
192 | |
302 | |
193 | static aio_req SvAIO_REQ (SV *sv) |
303 | static SV * |
|
|
304 | newSVaio_wd (aio_wd wd) |
|
|
305 | { |
|
|
306 | return sv_bless (newRV_noinc (newSViv ((IV)wd)), aio_wd_stash); |
|
|
307 | } |
|
|
308 | |
|
|
309 | static aio_req |
|
|
310 | SvAIO_REQ (SV *sv) |
194 | { |
311 | { |
195 | MAGIC *mg; |
312 | MAGIC *mg; |
196 | |
313 | |
197 | if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv)) |
314 | if (!SvROK (sv) |
|
|
315 | /* for speed reasons, we do not verify that SvROK actually has a stash ptr */ |
|
|
316 | || (SvSTASH (SvRV (sv)) != aio_grp_stash |
|
|
317 | && SvSTASH (SvRV (sv)) != aio_req_stash |
|
|
318 | && !sv_derived_from (sv, "IO::AIO::REQ"))) |
198 | croak ("object of class " AIO_REQ_KLASS " expected"); |
319 | croak ("object of class IO::AIO::REQ expected"); |
199 | |
320 | |
200 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
321 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
201 | |
322 | |
202 | return mg ? (aio_req)mg->mg_ptr : 0; |
323 | return mg ? (aio_req)mg->mg_ptr : 0; |
203 | } |
324 | } |
204 | |
325 | |
|
|
326 | static aio_wd |
|
|
327 | SvAIO_WD (SV *sv) |
|
|
328 | { |
|
|
329 | if (!SvROK (sv) |
|
|
330 | || SvTYPE (SvRV (sv)) != SVt_PVMG |
|
|
331 | || SvSTASH (SvRV (sv)) != aio_wd_stash) |
|
|
332 | croak ("IO::AIO: expected a working directory object as returned by aio_wd"); |
|
|
333 | |
|
|
334 | return (aio_wd)(long)SvIVX (SvRV (sv)); |
|
|
335 | } |
|
|
336 | |
|
|
337 | static void |
205 | static void aio_grp_feed (aio_req grp) |
338 | aio_grp_feed (aio_req grp) |
206 | { |
339 | { |
207 | if (grp->sv2 && SvOK (grp->sv2)) |
340 | if (grp->sv2 && SvOK (grp->sv2)) |
208 | { |
341 | { |
209 | dSP; |
342 | dSP; |
210 | |
343 | |
211 | ENTER; |
344 | ENTER; |
212 | SAVETMPS; |
345 | SAVETMPS; |
213 | PUSHMARK (SP); |
346 | PUSHMARK (SP); |
214 | XPUSHs (req_sv (grp, AIO_GRP_KLASS)); |
347 | XPUSHs (req_sv (grp, aio_grp_stash)); |
215 | PUTBACK; |
348 | PUTBACK; |
216 | call_sv (grp->sv2, G_VOID | G_EVAL | G_KEEPERR); |
349 | call_sv (grp->sv2, G_VOID | G_EVAL | G_KEEPERR); |
217 | SPAGAIN; |
350 | SPAGAIN; |
218 | FREETMPS; |
351 | FREETMPS; |
219 | LEAVE; |
352 | LEAVE; |
220 | } |
353 | } |
221 | } |
354 | } |
222 | |
355 | |
|
|
356 | static void |
223 | static void req_submit (eio_req *req) |
357 | req_submit (eio_req *req) |
224 | { |
358 | { |
225 | eio_submit (req); |
359 | eio_submit (req); |
226 | |
360 | |
227 | if (expect_false (on_next_submit)) |
361 | if (expect_false (on_next_submit)) |
228 | { |
362 | { |
… | |
… | |
235 | PUTBACK; |
369 | PUTBACK; |
236 | call_sv (cb, G_DISCARD | G_EVAL); |
370 | call_sv (cb, G_DISCARD | G_EVAL); |
237 | } |
371 | } |
238 | } |
372 | } |
239 | |
373 | |
|
|
374 | static int |
240 | static int req_invoke (eio_req *req) |
375 | req_invoke (eio_req *req) |
241 | { |
376 | { |
242 | dSP; |
|
|
243 | |
|
|
244 | if (req->flags & FLAG_SV2_RO_OFF) |
377 | if (req->flags & FLAG_SV2_RO_OFF) |
245 | SvREADONLY_off (req->sv2); |
378 | SvREADONLY_off (req->sv2); |
246 | |
379 | |
247 | if (!EIO_CANCELLED (req) && req->callback) |
380 | if (!EIO_CANCELLED (req) && req->callback) |
248 | { |
381 | { |
|
|
382 | dSP; |
|
|
383 | static SV *sv_result_cache; /* caches the result integer SV */ |
|
|
384 | SV *sv_result; |
|
|
385 | |
249 | ENTER; |
386 | ENTER; |
250 | SAVETMPS; |
387 | SAVETMPS; |
251 | PUSHMARK (SP); |
388 | PUSHMARK (SP); |
252 | EXTEND (SP, 1); |
389 | EXTEND (SP, 1); |
253 | |
390 | |
|
|
391 | /* do not recreate the result IV from scratch each time */ |
|
|
392 | if (expect_true (sv_result_cache)) |
|
|
393 | { |
|
|
394 | sv_result = sv_result_cache; sv_result_cache = 0; |
|
|
395 | SvIV_set (sv_result, req->result); |
|
|
396 | SvIOK_only (sv_result); |
|
|
397 | } |
|
|
398 | else |
|
|
399 | { |
|
|
400 | sv_result = newSViv (req->result); |
|
|
401 | SvREADONLY_on (sv_result); |
|
|
402 | } |
|
|
403 | |
254 | switch (req->type) |
404 | switch (req->type) |
255 | { |
405 | { |
|
|
406 | case EIO_WD_OPEN: |
|
|
407 | PUSHs (req->result ? &PL_sv_undef : sv_2mortal (newSVaio_wd (req->wd))); |
|
|
408 | break; |
|
|
409 | |
256 | case EIO_READDIR: |
410 | case EIO_READDIR: |
257 | { |
411 | { |
258 | SV *rv = &PL_sv_undef; |
412 | SV *rv = &PL_sv_undef; |
259 | |
413 | |
260 | if (req->result >= 0) |
414 | if (req->result >= 0) |
… | |
… | |
325 | int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR); |
479 | int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR); |
326 | char sym [64]; |
480 | char sym [64]; |
327 | int symlen; |
481 | int symlen; |
328 | |
482 | |
329 | symlen = snprintf (sym, sizeof (sym), "fd#%d", (int)req->result); |
483 | symlen = snprintf (sym, sizeof (sym), "fd#%d", (int)req->result); |
330 | gv_init (gv, stash, sym, symlen, 0); |
484 | gv_init (gv, aio_stash, sym, symlen, 0); |
331 | |
485 | |
332 | symlen = snprintf ( |
486 | symlen = snprintf ( |
333 | sym, |
487 | sym, |
334 | sizeof (sym), |
488 | sizeof (sym), |
335 | "%s&=%d", |
489 | "%s&=%d", |
… | |
… | |
343 | |
497 | |
344 | PUSHs (fh); |
498 | PUSHs (fh); |
345 | } |
499 | } |
346 | break; |
500 | break; |
347 | |
501 | |
|
|
502 | case EIO_STATVFS: |
|
|
503 | case EIO_FSTATVFS: |
|
|
504 | { |
|
|
505 | SV *rv = &PL_sv_undef; |
|
|
506 | |
|
|
507 | #ifndef _WIN32 |
|
|
508 | if (req->result >= 0) |
|
|
509 | { |
|
|
510 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
|
|
511 | HV *hv = newHV (); |
|
|
512 | /* POSIX requires fsid to be unsigned long, but AIX in its infinite wisdom |
|
|
513 | * chooses to make it a struct. |
|
|
514 | */ |
|
|
515 | unsigned long fsid = 0; |
|
|
516 | memcpy (&fsid, &f->f_fsid, sizeof (unsigned long) < sizeof (f->f_fsid) ? sizeof (unsigned long) : sizeof (f->f_fsid)); |
|
|
517 | |
|
|
518 | rv = sv_2mortal (newRV_noinc ((SV *)hv)); |
|
|
519 | |
|
|
520 | hv_store (hv, "bsize" , sizeof ("bsize" ) - 1, newSVval64 (f->f_bsize ), 0); |
|
|
521 | hv_store (hv, "frsize" , sizeof ("frsize" ) - 1, newSVval64 (f->f_frsize ), 0); |
|
|
522 | hv_store (hv, "blocks" , sizeof ("blocks" ) - 1, newSVval64 (f->f_blocks ), 0); |
|
|
523 | hv_store (hv, "bfree" , sizeof ("bfree" ) - 1, newSVval64 (f->f_bfree ), 0); |
|
|
524 | hv_store (hv, "bavail" , sizeof ("bavail" ) - 1, newSVval64 (f->f_bavail ), 0); |
|
|
525 | hv_store (hv, "files" , sizeof ("files" ) - 1, newSVval64 (f->f_files ), 0); |
|
|
526 | hv_store (hv, "ffree" , sizeof ("ffree" ) - 1, newSVval64 (f->f_ffree ), 0); |
|
|
527 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
|
|
528 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (fsid ), 0); |
|
|
529 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
|
|
530 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
|
|
531 | } |
|
|
532 | #endif |
|
|
533 | |
|
|
534 | PUSHs (rv); |
|
|
535 | } |
|
|
536 | |
|
|
537 | break; |
|
|
538 | |
348 | case EIO_GROUP: |
539 | case EIO_GROUP: |
349 | req->int1 = 2; /* mark group as finished */ |
540 | req->int1 = 2; /* mark group as finished */ |
350 | |
541 | |
351 | if (req->sv1) |
542 | if (req->sv1) |
352 | { |
543 | { |
… | |
… | |
362 | case EIO_NOP: |
553 | case EIO_NOP: |
363 | case EIO_BUSY: |
554 | case EIO_BUSY: |
364 | break; |
555 | break; |
365 | |
556 | |
366 | case EIO_READLINK: |
557 | case EIO_READLINK: |
|
|
558 | case EIO_REALPATH: |
367 | if (req->result > 0) |
559 | if (req->result > 0) |
368 | PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); |
560 | PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); |
369 | break; |
561 | break; |
370 | |
562 | |
371 | case EIO_STAT: |
563 | case EIO_STAT: |
372 | case EIO_LSTAT: |
564 | case EIO_LSTAT: |
373 | case EIO_FSTAT: |
565 | case EIO_FSTAT: |
374 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
566 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
|
|
567 | |
375 | PL_laststatval = req->result; |
568 | if (!(PL_laststatval = req->result)) |
|
|
569 | /* if compilation fails here then perl's Stat_t is not struct _stati64 */ |
376 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
570 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
377 | PUSHs (sv_2mortal (newSViv (req->result))); |
571 | |
|
|
572 | PUSHs (sv_result); |
|
|
573 | break; |
|
|
574 | |
|
|
575 | case EIO_SEEK: |
|
|
576 | PUSHs (req->result ? sv_result : sv_2mortal (newSVval64 (req->offs))); |
378 | break; |
577 | break; |
379 | |
578 | |
380 | case EIO_READ: |
579 | case EIO_READ: |
381 | { |
580 | { |
382 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
581 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
383 | *SvEND (req->sv2) = 0; |
582 | *SvEND (req->sv2) = 0; |
384 | SvPOK_only (req->sv2); |
583 | SvPOK_only (req->sv2); |
385 | SvSETMAGIC (req->sv2); |
584 | SvSETMAGIC (req->sv2); |
386 | PUSHs (sv_2mortal (newSViv (req->result))); |
585 | PUSHs (sv_result); |
387 | } |
586 | } |
388 | break; |
587 | break; |
389 | |
588 | |
390 | case EIO_DUP2: |
589 | case EIO_CUSTOM: |
|
|
590 | if (req->feed == fiemap) |
|
|
591 | { |
|
|
592 | #if HAVE_FIEMAP |
|
|
593 | if (!req->result) |
|
|
594 | { |
|
|
595 | struct fiemap *fiemap = (struct fiemap *)req->ptr1; |
|
|
596 | |
|
|
597 | if (fiemap->fm_extent_count) |
|
|
598 | { |
|
|
599 | AV *av = newAV (); |
|
|
600 | int i; |
|
|
601 | |
|
|
602 | while (fiemap->fm_mapped_extents) |
|
|
603 | { |
|
|
604 | struct fiemap_extent *extent = &fiemap->fm_extents [--fiemap->fm_mapped_extents]; |
|
|
605 | AV *ext_av = newAV (); |
|
|
606 | |
|
|
607 | av_store (ext_av, 3, newSVuv (extent->fe_flags)); |
|
|
608 | av_store (ext_av, 2, newSVval64 (extent->fe_length)); |
|
|
609 | av_store (ext_av, 1, newSVval64 (extent->fe_physical)); |
|
|
610 | av_store (ext_av, 0, newSVval64 (extent->fe_logical)); |
|
|
611 | |
|
|
612 | av_store (av, fiemap->fm_mapped_extents, newRV_noinc ((SV *)ext_av)); |
|
|
613 | } |
|
|
614 | |
|
|
615 | PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
|
|
616 | } |
|
|
617 | else |
|
|
618 | { |
|
|
619 | SvIV_set (sv_result, fiemap->fm_mapped_extents); |
|
|
620 | PUSHs (sv_result); |
|
|
621 | } |
|
|
622 | } |
|
|
623 | #endif |
|
|
624 | } |
|
|
625 | else |
|
|
626 | PUSHs (sv_result); |
|
|
627 | break; |
|
|
628 | |
|
|
629 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), so fudge result value */ |
391 | if (req->result > 0) |
630 | if (req->result > 0) |
392 | req->result = 0; |
631 | SvIV_set (sv_result, 0); |
393 | /* FALLTHROUGH */ |
632 | /* FALLTHROUGH */ |
394 | |
633 | |
395 | default: |
634 | default: |
396 | PUSHs (sv_2mortal (newSViv (req->result))); |
635 | PUSHs (sv_result); |
397 | break; |
636 | break; |
398 | } |
637 | } |
399 | |
638 | |
400 | errno = req->errorno; |
639 | errno = req->errorno; |
401 | |
640 | |
402 | PUTBACK; |
641 | PUTBACK; |
403 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
642 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
404 | SPAGAIN; |
643 | SPAGAIN; |
405 | |
644 | |
|
|
645 | if (expect_false (SvREFCNT (sv_result) != 1 || sv_result_cache)) |
|
|
646 | SvREFCNT_dec (sv_result); |
|
|
647 | else |
|
|
648 | sv_result_cache = sv_result; |
|
|
649 | |
406 | FREETMPS; |
650 | FREETMPS; |
407 | LEAVE; |
651 | LEAVE; |
408 | |
652 | |
409 | PUTBACK; |
653 | PUTBACK; |
410 | } |
654 | } |
411 | |
655 | |
412 | return !!SvTRUE (ERRSV); |
656 | return !!SvTRUE (ERRSV); |
413 | } |
657 | } |
414 | |
658 | |
|
|
659 | static void |
415 | static void req_destroy (aio_req req) |
660 | req_destroy (aio_req req) |
416 | { |
661 | { |
417 | if (req->self) |
662 | if (req->self) |
418 | { |
663 | { |
419 | sv_unmagic (req->self, PERL_MAGIC_ext); |
664 | sv_unmagic (req->self, PERL_MAGIC_ext); |
420 | SvREFCNT_dec (req->self); |
665 | SvREFCNT_dec (req->self); |
421 | } |
666 | } |
422 | |
667 | |
423 | SvREFCNT_dec (req->sv1); |
668 | SvREFCNT_dec (req->sv1); |
424 | SvREFCNT_dec (req->sv2); |
669 | SvREFCNT_dec (req->sv2); |
|
|
670 | SvREFCNT_dec (req->sv3); |
|
|
671 | SvREFCNT_dec (req->sv4); |
425 | SvREFCNT_dec (req->callback); |
672 | SvREFCNT_dec (req->callback); |
426 | |
673 | |
427 | Safefree (req); |
674 | free (req); |
428 | } |
675 | } |
429 | |
676 | |
|
|
677 | static void |
430 | static void req_cancel_subs (aio_req grp) |
678 | req_cancel_subs (aio_req grp) |
431 | { |
679 | { |
432 | aio_req sub; |
|
|
433 | |
|
|
434 | if (grp->type != EIO_GROUP) |
680 | if (grp->type != EIO_GROUP) |
435 | return; |
681 | return; |
436 | |
682 | |
437 | SvREFCNT_dec (grp->sv2); |
683 | SvREFCNT_dec (grp->sv2); |
438 | grp->sv2 = 0; |
684 | grp->sv2 = 0; |
439 | |
685 | |
440 | eio_grp_cancel (grp); |
686 | eio_grp_cancel (grp); |
441 | } |
687 | } |
442 | |
688 | |
443 | #ifdef USE_SOCKETS_AS_HANDLES |
689 | static void ecb_cold |
444 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
690 | create_respipe (void) |
445 | #else |
691 | { |
446 | # define TO_SOCKET(x) (x) |
692 | if (s_epipe_renew (&respipe)) |
447 | #endif |
693 | croak ("IO::AIO: unable to initialize result pipe"); |
|
|
694 | } |
448 | |
695 | |
449 | static void |
696 | static void |
450 | create_respipe (void) |
697 | poll_wait (void) |
451 | { |
698 | { |
452 | int old_readfd = respipe [0]; |
|
|
453 | |
|
|
454 | if (respipe [1] >= 0) |
|
|
455 | respipe_close (TO_SOCKET (respipe [1])); |
|
|
456 | |
|
|
457 | #ifdef _WIN32 |
|
|
458 | if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe)) |
|
|
459 | #else |
|
|
460 | if (pipe (respipe)) |
|
|
461 | #endif |
|
|
462 | croak ("unable to initialize result pipe"); |
|
|
463 | |
|
|
464 | if (old_readfd >= 0) |
|
|
465 | { |
|
|
466 | if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) |
|
|
467 | croak ("unable to initialize result pipe(2)"); |
|
|
468 | |
|
|
469 | respipe_close (respipe [0]); |
|
|
470 | respipe [0] = old_readfd; |
|
|
471 | } |
|
|
472 | |
|
|
473 | #ifdef _WIN32 |
|
|
474 | int arg = 1; |
|
|
475 | if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) |
|
|
476 | || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) |
|
|
477 | #else |
|
|
478 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) |
|
|
479 | || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
480 | #endif |
|
|
481 | croak ("unable to initialize result pipe(3)"); |
|
|
482 | |
|
|
483 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
|
|
484 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
|
|
485 | } |
|
|
486 | |
|
|
487 | static void poll_wait (void) |
|
|
488 | { |
|
|
489 | fd_set rfd; |
|
|
490 | |
|
|
491 | while (eio_nreqs ()) |
699 | while (eio_nreqs ()) |
492 | { |
700 | { |
493 | int size; |
701 | int size; |
494 | |
702 | |
495 | X_LOCK (reslock); |
703 | X_LOCK (reslock); |
… | |
… | |
499 | if (size) |
707 | if (size) |
500 | return; |
708 | return; |
501 | |
709 | |
502 | etp_maybe_start_thread (); |
710 | etp_maybe_start_thread (); |
503 | |
711 | |
504 | FD_ZERO (&rfd); |
712 | s_epipe_wait (&respipe); |
505 | FD_SET (respipe [0], &rfd); |
|
|
506 | |
|
|
507 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
508 | } |
713 | } |
509 | } |
714 | } |
510 | |
715 | |
511 | static int poll_cb (void) |
716 | static int |
|
|
717 | poll_cb (void) |
512 | { |
718 | { |
513 | for (;;) |
719 | for (;;) |
514 | { |
720 | { |
515 | int res = eio_poll (); |
721 | int res = eio_poll (); |
516 | |
722 | |
… | |
… | |
522 | |
728 | |
523 | poll_wait (); |
729 | poll_wait (); |
524 | } |
730 | } |
525 | } |
731 | } |
526 | |
732 | |
527 | static void atfork_child (void) |
733 | static void ecb_cold |
|
|
734 | reinit (void) |
528 | { |
735 | { |
529 | create_respipe (); |
736 | create_respipe (); |
|
|
737 | |
|
|
738 | if (eio_init (want_poll, done_poll) < 0) |
|
|
739 | croak ("IO::AIO: unable to initialise eio library"); |
530 | } |
740 | } |
|
|
741 | |
|
|
742 | /*****************************************************************************/ |
|
|
743 | |
|
|
744 | #if !_POSIX_MAPPED_FILES |
|
|
745 | # define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS () |
|
|
746 | # define munmap(addr,length) EIO_ENOSYS () |
|
|
747 | #endif |
|
|
748 | |
|
|
749 | #if !_POSIX_MEMORY_PROTECTION |
|
|
750 | # define mprotect(addr,len,prot) EIO_ENOSYS () |
|
|
751 | # define PROT_NONE 0 |
|
|
752 | # define PROT_WRITE 0 |
|
|
753 | # define MAP_PRIVATE 0 |
|
|
754 | # define MAP_SHARED 0 |
|
|
755 | # define MAP_FIXED 0 |
|
|
756 | #endif |
|
|
757 | |
|
|
758 | #define MMAP_MAGIC PERL_MAGIC_ext |
|
|
759 | |
|
|
760 | static int ecb_cold |
|
|
761 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
|
|
762 | { |
|
|
763 | int old_errno = errno; |
|
|
764 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
|
|
765 | errno = old_errno; |
|
|
766 | |
|
|
767 | mg->mg_obj = 0; /* just in case */ |
|
|
768 | |
|
|
769 | SvREADONLY_off (sv); |
|
|
770 | |
|
|
771 | if (SvPVX (sv) != mg->mg_ptr) |
|
|
772 | croak ("ERROR: IO::AIO::mmap-mapped scalar changed location, detected"); |
|
|
773 | |
|
|
774 | SvCUR_set (sv, 0); |
|
|
775 | SvPVX (sv) = 0; |
|
|
776 | SvOK_off (sv); |
|
|
777 | |
|
|
778 | return 0; |
|
|
779 | } |
|
|
780 | |
|
|
781 | static MGVTBL mmap_vtbl = { |
|
|
782 | 0, 0, 0, 0, mmap_free |
|
|
783 | }; |
|
|
784 | |
|
|
785 | /*****************************************************************************/ |
531 | |
786 | |
532 | static SV * |
787 | static SV * |
533 | get_cb (SV *cb_sv) |
788 | get_cb (SV *cb_sv) |
534 | { |
789 | { |
535 | HV *st; |
790 | SvGETMAGIC (cb_sv); |
536 | GV *gvp; |
791 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
|
|
792 | } |
|
|
793 | |
|
|
794 | static aio_req ecb_noinline |
|
|
795 | dreq (SV *callback) |
|
|
796 | { |
537 | CV *cv; |
797 | SV *cb_cv; |
|
|
798 | aio_req req; |
|
|
799 | int req_pri = next_pri; |
|
|
800 | next_pri = EIO_PRI_DEFAULT; |
538 | |
801 | |
539 | if (!SvOK (cb_sv)) |
802 | cb_cv = get_cb (callback); |
|
|
803 | |
|
|
804 | req = calloc (sizeof (*req), 1); |
|
|
805 | if (!req) |
|
|
806 | croak ("out of memory during eio_req allocation"); |
|
|
807 | |
|
|
808 | req->callback = SvREFCNT_inc (cb_cv); |
|
|
809 | req->pri = req_pri; |
|
|
810 | |
540 | return 0; |
811 | return req; |
541 | |
|
|
542 | cv = sv_2cv (cb_sv, &st, &gvp, 0); |
|
|
543 | |
|
|
544 | if (!cv) |
|
|
545 | croak ("IO::AIO callback must be undef or a CODE reference"); |
|
|
546 | |
|
|
547 | return (SV *)cv; |
|
|
548 | } |
812 | } |
549 | |
813 | |
550 | #define dREQ \ |
814 | #define dREQ \ |
551 | SV *cb_cv; \ |
815 | aio_req req = dreq (callback); \ |
552 | aio_req req; \ |
|
|
553 | int req_pri = next_pri; \ |
|
|
554 | next_pri = EIO_PRI_DEFAULT; \ |
|
|
555 | \ |
|
|
556 | cb_cv = get_cb (callback); \ |
|
|
557 | \ |
|
|
558 | Newz (0, req, 1, eio_req); \ |
|
|
559 | if (!req) \ |
|
|
560 | croak ("out of memory during eio_req allocation"); \ |
|
|
561 | \ |
|
|
562 | req->callback = SvREFCNT_inc (cb_cv); \ |
|
|
563 | req->pri = req_pri |
|
|
564 | |
816 | |
565 | #define REQ_SEND \ |
817 | #define REQ_SEND \ |
566 | PUTBACK; \ |
818 | PUTBACK; \ |
567 | req_submit (req); \ |
819 | req_submit (req); \ |
568 | SPAGAIN; \ |
820 | SPAGAIN; \ |
569 | \ |
821 | \ |
570 | if (GIMME_V != G_VOID) \ |
822 | if (GIMME_V != G_VOID) \ |
571 | XPUSHs (req_sv (req, AIO_REQ_KLASS)); |
823 | XPUSHs (req_sv (req, aio_req_stash)); |
572 | |
824 | |
573 | static int |
825 | ecb_inline void |
574 | extract_fd (SV *fh, int wr) |
826 | req_set_path (aio_req req, SV *path, SV **wdsv, SV **pathsv, eio_wd *wd, void **ptr) |
575 | { |
827 | { |
576 | int fd = PerlIO_fileno (wr ? IoOFP (sv_2io (fh)) : IoIFP (sv_2io (fh))); |
828 | if (expect_false (SvROK (path))) |
|
|
829 | { |
|
|
830 | SV *rv = SvRV (path); |
|
|
831 | SV *wdob; |
577 | |
832 | |
578 | if (fd < 0) |
833 | if (SvTYPE (rv) == SVt_PVAV && AvFILLp (rv) == 1) |
579 | croak ("illegal fh argument, either not an OS file or read/write mode mismatch"); |
834 | { |
|
|
835 | path = AvARRAY (rv)[1]; |
|
|
836 | wdob = AvARRAY (rv)[0]; |
580 | |
837 | |
581 | return fd; |
838 | if (SvOK (wdob)) |
|
|
839 | { |
|
|
840 | *wd = SvAIO_WD (wdob); |
|
|
841 | *wdsv = SvREFCNT_inc_NN (SvRV (wdob)); |
|
|
842 | } |
|
|
843 | else |
|
|
844 | *wd = EIO_INVALID_WD; |
|
|
845 | } |
|
|
846 | else if (SvTYPE (rv) == SVt_PVMG && SvSTASH (rv) == aio_wd_stash) |
|
|
847 | { |
|
|
848 | *wd = (aio_wd)(long)SvIVX (rv); |
|
|
849 | *wdsv = SvREFCNT_inc_NN (rv); |
|
|
850 | *ptr = "."; |
|
|
851 | return; /* path set to "." */ |
|
|
852 | } |
|
|
853 | else |
|
|
854 | croak ("IO::AIO: pathname arguments must be specified as a string, an IO::AIO::WD object or a [IO::AIO::WD, path] pair"); |
|
|
855 | } |
|
|
856 | |
|
|
857 | *pathsv = newSVsv (path); |
|
|
858 | *ptr = SvPVbyte_nolen (*pathsv); |
582 | } |
859 | } |
|
|
860 | |
|
|
861 | static void ecb_noinline |
|
|
862 | req_set_path1 (aio_req req, SV *path) |
|
|
863 | { |
|
|
864 | req_set_path (req, path, &req->sv1, &req->sv3, &req->wd, &req->ptr1); |
|
|
865 | } |
|
|
866 | |
|
|
867 | static void ecb_noinline |
|
|
868 | req_set_fh_or_path (aio_req req, int type_path, int type_fh, SV *fh_or_path) |
|
|
869 | { |
|
|
870 | SV *rv = SvROK (fh_or_path) ? SvRV (fh_or_path) : fh_or_path; |
|
|
871 | |
|
|
872 | switch (SvTYPE (rv)) |
|
|
873 | { |
|
|
874 | case SVt_PVIO: |
|
|
875 | case SVt_PVLV: |
|
|
876 | case SVt_PVGV: |
|
|
877 | req->type = type_fh; |
|
|
878 | req->sv1 = newSVsv (fh_or_path); |
|
|
879 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
880 | break; |
|
|
881 | |
|
|
882 | default: |
|
|
883 | req->type = type_path; |
|
|
884 | req_set_path1 (req, fh_or_path); |
|
|
885 | break; |
|
|
886 | } |
|
|
887 | } |
|
|
888 | |
|
|
889 | XS(boot_IO__AIO) ecb_cold; |
583 | |
890 | |
584 | MODULE = IO::AIO PACKAGE = IO::AIO |
891 | MODULE = IO::AIO PACKAGE = IO::AIO |
585 | |
892 | |
586 | PROTOTYPES: ENABLE |
893 | PROTOTYPES: ENABLE |
587 | |
894 | |
… | |
… | |
589 | { |
896 | { |
590 | static const struct { |
897 | static const struct { |
591 | const char *name; |
898 | const char *name; |
592 | IV iv; |
899 | IV iv; |
593 | } *civ, const_iv[] = { |
900 | } *civ, const_iv[] = { |
594 | # define const_iv(name, value) { # name, (IV) value }, |
901 | # define const_niv(name, value) { # name, (IV) value }, |
|
|
902 | # define const_iv(name) { # name, (IV) name }, |
595 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
903 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
596 | const_iv (EXDEV , EXDEV) |
904 | |
|
|
905 | /* you have to re-run ./gendef0 after adding/Removing any constants here */ |
|
|
906 | |
597 | const_iv (ENOSYS , ENOSYS) |
907 | const_iv (ENOSYS) |
|
|
908 | const_iv (EXDEV) |
|
|
909 | const_iv (EBADR) |
|
|
910 | |
598 | const_iv (O_RDONLY, O_RDONLY) |
911 | const_iv (O_RDONLY) |
599 | const_iv (O_WRONLY, O_WRONLY) |
912 | const_iv (O_WRONLY) |
|
|
913 | const_iv (O_RDWR) |
600 | const_iv (O_CREAT , O_CREAT) |
914 | const_iv (O_CREAT) |
601 | const_iv (O_TRUNC , O_TRUNC) |
915 | const_iv (O_TRUNC) |
602 | #ifndef _WIN32 |
916 | const_iv (O_EXCL) |
|
|
917 | const_iv (O_APPEND) |
|
|
918 | |
|
|
919 | const_iv (O_ASYNC) |
|
|
920 | const_iv (O_DIRECT) |
|
|
921 | const_iv (O_NOATIME) |
|
|
922 | |
|
|
923 | const_iv (O_CLOEXEC) |
|
|
924 | const_iv (O_NOCTTY) |
|
|
925 | const_iv (O_NOFOLLOW) |
|
|
926 | const_iv (O_NONBLOCK) |
|
|
927 | const_iv (O_EXEC) |
|
|
928 | const_iv (O_SEARCH) |
|
|
929 | const_iv (O_DIRECTORY) |
|
|
930 | const_iv (O_DSYNC) |
|
|
931 | const_iv (O_RSYNC) |
|
|
932 | const_iv (O_SYNC) |
|
|
933 | const_iv (O_TTY_INIT) |
|
|
934 | |
603 | const_iv (S_IFIFO , S_IFIFO) |
935 | const_iv (S_IFIFO) |
604 | #endif |
936 | const_iv (S_IFCHR) |
|
|
937 | const_iv (S_IFBLK) |
|
|
938 | const_iv (S_IFLNK) |
|
|
939 | const_iv (S_IFREG) |
|
|
940 | const_iv (S_IFDIR) |
|
|
941 | const_iv (S_IFWHT) |
|
|
942 | const_iv (S_IFSOCK) |
|
|
943 | const_iv (S_IFMT) |
|
|
944 | |
605 | const_iv (FADV_NORMAL , POSIX_FADV_NORMAL) |
945 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
606 | const_iv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
946 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
607 | const_iv (FADV_RANDOM , POSIX_FADV_RANDOM) |
947 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
608 | const_iv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
948 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
609 | const_iv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
949 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
610 | const_iv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
950 | const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
|
|
951 | |
|
|
952 | const_niv (MADV_NORMAL , POSIX_MADV_NORMAL) |
|
|
953 | const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL) |
|
|
954 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
|
|
955 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
|
|
956 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
|
|
957 | |
|
|
958 | const_iv (ST_RDONLY) |
|
|
959 | const_iv (ST_NOSUID) |
|
|
960 | const_iv (ST_NODEV) |
|
|
961 | const_iv (ST_NOEXEC) |
|
|
962 | const_iv (ST_SYNCHRONOUS) |
|
|
963 | const_iv (ST_MANDLOCK) |
|
|
964 | const_iv (ST_WRITE) |
|
|
965 | const_iv (ST_APPEND) |
|
|
966 | const_iv (ST_IMMUTABLE) |
|
|
967 | const_iv (ST_NOATIME) |
|
|
968 | const_iv (ST_NODIRATIME) |
|
|
969 | const_iv (ST_RELATIME) |
|
|
970 | |
|
|
971 | const_iv (PROT_NONE) |
|
|
972 | const_iv (PROT_EXEC) |
|
|
973 | const_iv (PROT_READ) |
|
|
974 | const_iv (PROT_WRITE) |
|
|
975 | |
|
|
976 | /*const_iv (MAP_FIXED)*/ |
|
|
977 | const_iv (MAP_PRIVATE) |
|
|
978 | const_iv (MAP_SHARED) |
|
|
979 | const_iv (MAP_ANONYMOUS) |
|
|
980 | |
|
|
981 | /* linuxish */ |
|
|
982 | const_iv (MAP_HUGETLB) |
|
|
983 | const_iv (MAP_LOCKED) |
|
|
984 | const_iv (MAP_NORESERVE) |
|
|
985 | const_iv (MAP_POPULATE) |
|
|
986 | const_iv (MAP_NONBLOCK) |
|
|
987 | |
|
|
988 | const_iv (FIEMAP_FLAG_SYNC) |
|
|
989 | const_iv (FIEMAP_FLAG_XATTR) |
|
|
990 | const_iv (FIEMAP_FLAGS_COMPAT) |
|
|
991 | const_iv (FIEMAP_EXTENT_LAST) |
|
|
992 | const_iv (FIEMAP_EXTENT_UNKNOWN) |
|
|
993 | const_iv (FIEMAP_EXTENT_DELALLOC) |
|
|
994 | const_iv (FIEMAP_EXTENT_ENCODED) |
|
|
995 | const_iv (FIEMAP_EXTENT_DATA_ENCRYPTED) |
|
|
996 | const_iv (FIEMAP_EXTENT_NOT_ALIGNED) |
|
|
997 | const_iv (FIEMAP_EXTENT_DATA_INLINE) |
|
|
998 | const_iv (FIEMAP_EXTENT_DATA_TAIL) |
|
|
999 | const_iv (FIEMAP_EXTENT_UNWRITTEN) |
|
|
1000 | const_iv (FIEMAP_EXTENT_MERGED) |
|
|
1001 | const_iv (FIEMAP_EXTENT_SHARED) |
|
|
1002 | |
|
|
1003 | const_iv (SPLICE_F_MOVE) |
|
|
1004 | const_iv (SPLICE_F_NONBLOCK) |
|
|
1005 | const_iv (SPLICE_F_MORE) |
|
|
1006 | const_iv (SPLICE_F_GIFT) |
|
|
1007 | |
|
|
1008 | const_iv (SEEK_DATA) |
|
|
1009 | const_iv (SEEK_HOLE) |
|
|
1010 | |
|
|
1011 | /* libeio constants */ |
|
|
1012 | const_eio (SEEK_SET) |
|
|
1013 | const_eio (SEEK_CUR) |
|
|
1014 | const_eio (SEEK_END) |
|
|
1015 | |
|
|
1016 | const_eio (MCL_FUTURE) |
|
|
1017 | const_eio (MCL_CURRENT) |
|
|
1018 | |
|
|
1019 | const_eio (MS_ASYNC) |
|
|
1020 | const_eio (MS_INVALIDATE) |
|
|
1021 | const_eio (MS_SYNC) |
|
|
1022 | |
|
|
1023 | const_eio (MT_MODIFY) |
611 | |
1024 | |
612 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
1025 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
613 | const_eio (SYNC_FILE_RANGE_WRITE) |
1026 | const_eio (SYNC_FILE_RANGE_WRITE) |
614 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
1027 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
|
|
1028 | |
|
|
1029 | const_eio (FALLOC_FL_KEEP_SIZE) |
|
|
1030 | const_eio (FALLOC_FL_PUNCH_HOLE) |
615 | |
1031 | |
616 | const_eio (READDIR_DENTS) |
1032 | const_eio (READDIR_DENTS) |
617 | const_eio (READDIR_DIRS_FIRST) |
1033 | const_eio (READDIR_DIRS_FIRST) |
618 | const_eio (READDIR_STAT_ORDER) |
1034 | const_eio (READDIR_STAT_ORDER) |
619 | const_eio (READDIR_FOUND_UNKNOWN) |
1035 | const_eio (READDIR_FOUND_UNKNOWN) |
… | |
… | |
627 | const_eio (DT_LNK) |
1043 | const_eio (DT_LNK) |
628 | const_eio (DT_SOCK) |
1044 | const_eio (DT_SOCK) |
629 | const_eio (DT_WHT) |
1045 | const_eio (DT_WHT) |
630 | }; |
1046 | }; |
631 | |
1047 | |
632 | stash = gv_stashpv ("IO::AIO", 1); |
1048 | aio_stash = gv_stashpv ("IO::AIO" , 1); |
|
|
1049 | aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); |
|
|
1050 | aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); |
|
|
1051 | aio_wd_stash = gv_stashpv ("IO::AIO::WD" , 1); |
633 | |
1052 | |
634 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1053 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
635 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1054 | newCONSTSUB (aio_stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
636 | |
1055 | |
637 | create_respipe (); |
1056 | newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); |
638 | |
1057 | |
639 | if (eio_init (want_poll, done_poll) < 0) |
1058 | reinit (); |
640 | croak ("IO::AIO: unable to initialise eio library"); |
|
|
641 | |
|
|
642 | /* atfork child called in fifo order, so before eio's handler */ |
|
|
643 | X_THREAD_ATFORK (0, 0, atfork_child); |
|
|
644 | } |
1059 | } |
645 | |
1060 | |
646 | void |
1061 | void |
|
|
1062 | reinit () |
|
|
1063 | PROTOTYPE: |
|
|
1064 | |
|
|
1065 | void |
647 | max_poll_reqs (int nreqs) |
1066 | max_poll_reqs (unsigned int nreqs) |
648 | PROTOTYPE: $ |
1067 | PROTOTYPE: $ |
649 | CODE: |
1068 | CODE: |
650 | eio_set_max_poll_reqs (nreqs); |
1069 | eio_set_max_poll_reqs (nreqs); |
651 | |
1070 | |
652 | void |
1071 | void |
… | |
… | |
654 | PROTOTYPE: $ |
1073 | PROTOTYPE: $ |
655 | CODE: |
1074 | CODE: |
656 | eio_set_max_poll_time (nseconds); |
1075 | eio_set_max_poll_time (nseconds); |
657 | |
1076 | |
658 | void |
1077 | void |
659 | min_parallel (int nthreads) |
1078 | min_parallel (unsigned int nthreads) |
660 | PROTOTYPE: $ |
1079 | PROTOTYPE: $ |
661 | CODE: |
1080 | CODE: |
662 | eio_set_min_parallel (nthreads); |
1081 | eio_set_min_parallel (nthreads); |
663 | |
1082 | |
664 | void |
1083 | void |
665 | max_parallel (int nthreads) |
1084 | max_parallel (unsigned int nthreads) |
666 | PROTOTYPE: $ |
1085 | PROTOTYPE: $ |
667 | CODE: |
1086 | CODE: |
668 | eio_set_max_parallel (nthreads); |
1087 | eio_set_max_parallel (nthreads); |
669 | |
1088 | |
670 | void |
1089 | void |
671 | max_idle (int nthreads) |
1090 | max_idle (unsigned int nthreads) |
672 | PROTOTYPE: $ |
1091 | PROTOTYPE: $ |
673 | CODE: |
1092 | CODE: |
674 | eio_set_max_idle (nthreads); |
1093 | eio_set_max_idle (nthreads); |
675 | |
1094 | |
676 | void |
1095 | void |
|
|
1096 | idle_timeout (unsigned int seconds) |
|
|
1097 | PROTOTYPE: $ |
|
|
1098 | CODE: |
|
|
1099 | eio_set_idle_timeout (seconds); |
|
|
1100 | |
|
|
1101 | void |
677 | max_outstanding (int maxreqs) |
1102 | max_outstanding (unsigned int maxreqs) |
678 | PROTOTYPE: $ |
1103 | PROTOTYPE: $ |
679 | CODE: |
1104 | CODE: |
680 | max_outstanding = maxreqs; |
1105 | max_outstanding = maxreqs; |
681 | |
1106 | |
682 | void |
1107 | void |
|
|
1108 | aio_wd (SV8 *pathname, SV *callback=&PL_sv_undef) |
|
|
1109 | PPCODE: |
|
|
1110 | { |
|
|
1111 | dREQ; |
|
|
1112 | |
|
|
1113 | req->type = EIO_WD_OPEN; |
|
|
1114 | req_set_path1 (req, pathname); |
|
|
1115 | |
|
|
1116 | REQ_SEND; |
|
|
1117 | } |
|
|
1118 | |
|
|
1119 | void |
683 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
1120 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
684 | PROTOTYPE: $$$;$ |
|
|
685 | PPCODE: |
1121 | PPCODE: |
686 | { |
1122 | { |
687 | dREQ; |
1123 | dREQ; |
688 | |
1124 | |
689 | req->type = EIO_OPEN; |
1125 | req->type = EIO_OPEN; |
690 | req->sv1 = newSVsv (pathname); |
1126 | req_set_path1 (req, pathname); |
691 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
692 | req->int1 = flags; |
1127 | req->int1 = flags; |
693 | req->int2 = mode; |
1128 | req->int2 = mode; |
694 | |
1129 | |
695 | REQ_SEND; |
1130 | REQ_SEND; |
696 | } |
1131 | } |
697 | |
1132 | |
698 | void |
1133 | void |
699 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
1134 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
700 | PROTOTYPE: $;$ |
|
|
701 | ALIAS: |
1135 | ALIAS: |
702 | aio_fsync = EIO_FSYNC |
1136 | aio_fsync = EIO_FSYNC |
703 | aio_fdatasync = EIO_FDATASYNC |
1137 | aio_fdatasync = EIO_FDATASYNC |
|
|
1138 | aio_syncfs = EIO_SYNCFS |
704 | PPCODE: |
1139 | PPCODE: |
705 | { |
1140 | { |
706 | int fd = extract_fd (fh, 0); |
1141 | int fd = s_fileno_croak (fh, 0); |
707 | dREQ; |
1142 | dREQ; |
708 | |
1143 | |
709 | req->type = ix; |
1144 | req->type = ix; |
710 | req->sv1 = newSVsv (fh); |
1145 | req->sv1 = newSVsv (fh); |
711 | req->int1 = fd; |
1146 | req->int1 = fd; |
712 | |
1147 | |
713 | REQ_SEND (req); |
1148 | REQ_SEND; |
714 | } |
1149 | } |
715 | |
1150 | |
716 | void |
1151 | void |
717 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
1152 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
718 | PROTOTYPE: $$$$;$ |
|
|
719 | PPCODE: |
1153 | PPCODE: |
720 | { |
1154 | { |
721 | int fd = extract_fd (fh, 0); |
1155 | int fd = s_fileno_croak (fh, 0); |
722 | dREQ; |
1156 | dREQ; |
723 | |
1157 | |
724 | req->type = EIO_SYNC_FILE_RANGE; |
1158 | req->type = EIO_SYNC_FILE_RANGE; |
725 | req->sv1 = newSVsv (fh); |
1159 | req->sv1 = newSVsv (fh); |
726 | req->int1 = fd; |
1160 | req->int1 = fd; |
727 | req->offs = offset; |
1161 | req->offs = offset; |
728 | req->size = nbytes; |
1162 | req->size = nbytes; |
729 | req->int2 = flags; |
1163 | req->int2 = flags; |
730 | |
1164 | |
731 | REQ_SEND (req); |
1165 | REQ_SEND; |
|
|
1166 | } |
|
|
1167 | |
|
|
1168 | void |
|
|
1169 | aio_allocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) |
|
|
1170 | PPCODE: |
|
|
1171 | { |
|
|
1172 | int fd = s_fileno_croak (fh, 0); |
|
|
1173 | dREQ; |
|
|
1174 | |
|
|
1175 | req->type = EIO_FALLOCATE; |
|
|
1176 | req->sv1 = newSVsv (fh); |
|
|
1177 | req->int1 = fd; |
|
|
1178 | req->int2 = mode; |
|
|
1179 | req->offs = offset; |
|
|
1180 | req->size = len; |
|
|
1181 | |
|
|
1182 | REQ_SEND; |
732 | } |
1183 | } |
733 | |
1184 | |
734 | void |
1185 | void |
735 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1186 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
736 | PROTOTYPE: $;$ |
|
|
737 | PPCODE: |
1187 | PPCODE: |
738 | { |
1188 | { |
739 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
1189 | static int close_fd = -1; /* dummy fd to close fds via dup2 */ |
740 | int fd = extract_fd (fh, 0); |
1190 | int fd = s_fileno_croak (fh, 0); |
741 | dREQ; |
1191 | dREQ; |
742 | |
1192 | |
743 | if (close_pipe < 0) |
1193 | if (expect_false (close_fd < 0)) |
744 | { |
1194 | { |
745 | int pipefd [2]; |
1195 | int pipefd [2]; |
746 | |
1196 | |
|
|
1197 | if ( |
|
|
1198 | #ifdef _WIN32 |
|
|
1199 | _pipe (pipefd, 1, _O_BINARY) < 0 |
|
|
1200 | #else |
747 | if (pipe (pipefd) < 0 |
1201 | pipe (pipefd) < 0 |
748 | || close (pipefd [1]) < 0 |
|
|
749 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) |
1202 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0 |
|
|
1203 | #endif |
|
|
1204 | || close (pipefd [1]) < 0 |
|
|
1205 | ) |
750 | abort (); /*D*/ |
1206 | abort (); /*D*/ |
751 | |
1207 | |
752 | close_pipe = pipefd [0]; |
1208 | close_fd = pipefd [0]; |
753 | } |
1209 | } |
754 | |
1210 | |
755 | req->type = EIO_DUP2; |
1211 | req->type = EIO_DUP2; |
756 | req->int1 = close_pipe; |
1212 | req->int1 = close_fd; |
757 | req->sv2 = newSVsv (fh); |
1213 | req->sv2 = newSVsv (fh); |
758 | req->int2 = fd; |
1214 | req->int2 = fd; |
759 | |
1215 | |
760 | REQ_SEND (req); |
1216 | REQ_SEND; |
|
|
1217 | } |
|
|
1218 | |
|
|
1219 | void |
|
|
1220 | aio_seek (SV *fh, SV *offset, int whence, SV *callback=&PL_sv_undef) |
|
|
1221 | PPCODE: |
|
|
1222 | { |
|
|
1223 | int fd = s_fileno_croak (fh, 0); |
|
|
1224 | dREQ; |
|
|
1225 | |
|
|
1226 | req->type = EIO_SEEK; |
|
|
1227 | req->sv1 = newSVsv (fh); |
|
|
1228 | req->int1 = fd; |
|
|
1229 | req->offs = SvVAL64 (offset); |
|
|
1230 | req->int2 = whence; |
|
|
1231 | |
|
|
1232 | REQ_SEND; |
761 | } |
1233 | } |
762 | |
1234 | |
763 | void |
1235 | void |
764 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
1236 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
765 | ALIAS: |
1237 | ALIAS: |
766 | aio_read = EIO_READ |
1238 | aio_read = EIO_READ |
767 | aio_write = EIO_WRITE |
1239 | aio_write = EIO_WRITE |
768 | PROTOTYPE: $$$$$;$ |
|
|
769 | PPCODE: |
1240 | PPCODE: |
770 | { |
1241 | { |
771 | STRLEN svlen; |
1242 | STRLEN svlen; |
772 | int fd = extract_fd (fh, ix == EIO_WRITE); |
1243 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
773 | char *svptr = SvPVbyte (data, svlen); |
1244 | char *svptr = SvPVbyte (data, svlen); |
774 | UV len = SvUV (length); |
1245 | UV len = SvUV (length); |
775 | |
1246 | |
776 | if (dataoffset < 0) |
1247 | if (dataoffset < 0) |
777 | dataoffset += svlen; |
1248 | dataoffset += svlen; |
… | |
… | |
787 | } |
1258 | } |
788 | else |
1259 | else |
789 | { |
1260 | { |
790 | /* read: check type and grow scalar as necessary */ |
1261 | /* read: check type and grow scalar as necessary */ |
791 | SvUPGRADE (data, SVt_PV); |
1262 | SvUPGRADE (data, SVt_PV); |
|
|
1263 | if (SvLEN (data) >= SvCUR (data)) |
792 | svptr = SvGROW (data, len + dataoffset + 1); |
1264 | svptr = SvGROW (data, len + dataoffset + 1); |
|
|
1265 | else if (SvCUR (data) < len + dataoffset) |
|
|
1266 | croak ("length + dataoffset outside of scalar, and cannot grow"); |
793 | } |
1267 | } |
794 | |
1268 | |
795 | { |
1269 | { |
796 | dREQ; |
1270 | dREQ; |
797 | |
1271 | |
… | |
… | |
813 | REQ_SEND; |
1287 | REQ_SEND; |
814 | } |
1288 | } |
815 | } |
1289 | } |
816 | |
1290 | |
817 | void |
1291 | void |
818 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
1292 | aio_readlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
819 | PROTOTYPE: $$;$ |
1293 | ALIAS: |
|
|
1294 | aio_readlink = EIO_READLINK |
|
|
1295 | aio_realpath = EIO_REALPATH |
820 | PPCODE: |
1296 | PPCODE: |
821 | { |
1297 | { |
822 | SV *data; |
|
|
823 | dREQ; |
1298 | dREQ; |
824 | |
1299 | |
825 | req->type = EIO_READLINK; |
1300 | req->type = ix; |
826 | req->sv1 = newSVsv (path); |
1301 | req_set_path1 (req, pathname); |
827 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
828 | |
1302 | |
829 | REQ_SEND; |
1303 | REQ_SEND; |
830 | } |
1304 | } |
831 | |
1305 | |
832 | void |
1306 | void |
833 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
1307 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
834 | PROTOTYPE: $$$$;$ |
|
|
835 | PPCODE: |
1308 | PPCODE: |
836 | { |
1309 | { |
837 | int ifd = extract_fd (in_fh , 0); |
1310 | int ifd = s_fileno_croak (in_fh , 0); |
838 | int ofd = extract_fd (out_fh, 0); |
1311 | int ofd = s_fileno_croak (out_fh, 1); |
839 | dREQ; |
1312 | dREQ; |
840 | |
1313 | |
841 | req->type = EIO_SENDFILE; |
1314 | req->type = EIO_SENDFILE; |
842 | req->sv1 = newSVsv (out_fh); |
1315 | req->sv1 = newSVsv (out_fh); |
843 | req->int1 = ofd; |
1316 | req->int1 = ofd; |
… | |
… | |
849 | REQ_SEND; |
1322 | REQ_SEND; |
850 | } |
1323 | } |
851 | |
1324 | |
852 | void |
1325 | void |
853 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
1326 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
854 | PROTOTYPE: $$$;$ |
|
|
855 | PPCODE: |
1327 | PPCODE: |
856 | { |
1328 | { |
857 | int fd = extract_fd (fh, 0); |
1329 | int fd = s_fileno_croak (fh, 0); |
858 | dREQ; |
1330 | dREQ; |
859 | |
1331 | |
860 | req->type = EIO_READAHEAD; |
1332 | req->type = EIO_READAHEAD; |
861 | req->sv1 = newSVsv (fh); |
1333 | req->sv1 = newSVsv (fh); |
862 | req->int1 = fd; |
1334 | req->int1 = fd; |
… | |
… | |
867 | } |
1339 | } |
868 | |
1340 | |
869 | void |
1341 | void |
870 | aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) |
1342 | aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) |
871 | ALIAS: |
1343 | ALIAS: |
872 | aio_stat = EIO_STAT |
1344 | aio_stat = EIO_STAT |
873 | aio_lstat = EIO_LSTAT |
1345 | aio_lstat = EIO_LSTAT |
|
|
1346 | aio_statvfs = EIO_STATVFS |
874 | PPCODE: |
1347 | PPCODE: |
875 | { |
1348 | { |
876 | dREQ; |
1349 | dREQ; |
877 | |
1350 | |
878 | req->sv1 = newSVsv (fh_or_path); |
1351 | req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path); |
879 | |
|
|
880 | if (SvPOK (req->sv1)) |
|
|
881 | { |
|
|
882 | req->type = ix; |
|
|
883 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
884 | } |
|
|
885 | else |
|
|
886 | { |
|
|
887 | req->type = EIO_FSTAT; |
|
|
888 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
889 | } |
|
|
890 | |
1352 | |
891 | REQ_SEND; |
1353 | REQ_SEND; |
892 | } |
1354 | } |
|
|
1355 | |
|
|
1356 | UV |
|
|
1357 | major (UV dev) |
|
|
1358 | ALIAS: |
|
|
1359 | minor = 1 |
|
|
1360 | CODE: |
|
|
1361 | RETVAL = ix ? major (dev) : minor (dev); |
|
|
1362 | OUTPUT: |
|
|
1363 | RETVAL |
|
|
1364 | |
|
|
1365 | UV |
|
|
1366 | makedev (UV maj, UV min) |
|
|
1367 | CODE: |
|
|
1368 | RETVAL = makedev (maj, min); |
|
|
1369 | OUTPUT: |
|
|
1370 | RETVAL |
893 | |
1371 | |
894 | void |
1372 | void |
895 | aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
1373 | aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
896 | PPCODE: |
1374 | PPCODE: |
897 | { |
1375 | { |
898 | dREQ; |
1376 | dREQ; |
899 | |
1377 | |
900 | req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; |
1378 | req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; |
901 | req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; |
1379 | req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; |
902 | req->sv1 = newSVsv (fh_or_path); |
1380 | req_set_fh_or_path (req, EIO_UTIME, EIO_FUTIME, fh_or_path); |
903 | |
|
|
904 | if (SvPOK (req->sv1)) |
|
|
905 | { |
|
|
906 | req->type = EIO_UTIME; |
|
|
907 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
908 | } |
|
|
909 | else |
|
|
910 | { |
|
|
911 | req->type = EIO_FUTIME; |
|
|
912 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
913 | } |
|
|
914 | |
1381 | |
915 | REQ_SEND; |
1382 | REQ_SEND; |
916 | } |
1383 | } |
917 | |
1384 | |
918 | void |
1385 | void |
919 | aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) |
1386 | aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) |
920 | PPCODE: |
1387 | PPCODE: |
921 | { |
1388 | { |
922 | dREQ; |
1389 | dREQ; |
923 | |
1390 | |
924 | req->sv1 = newSVsv (fh_or_path); |
|
|
925 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
1391 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
926 | |
1392 | req_set_fh_or_path (req, EIO_TRUNCATE, EIO_FTRUNCATE, fh_or_path); |
927 | if (SvPOK (req->sv1)) |
|
|
928 | { |
|
|
929 | req->type = EIO_TRUNCATE; |
|
|
930 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
931 | } |
|
|
932 | else |
|
|
933 | { |
|
|
934 | req->type = EIO_FTRUNCATE; |
|
|
935 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
936 | } |
|
|
937 | |
1393 | |
938 | REQ_SEND; |
1394 | REQ_SEND; |
939 | } |
1395 | } |
940 | |
1396 | |
941 | void |
1397 | void |
942 | aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) |
1398 | aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) |
943 | ALIAS: |
|
|
944 | aio_chmod = EIO_CHMOD |
|
|
945 | aio_mkdir = EIO_MKDIR |
|
|
946 | PPCODE: |
1399 | PPCODE: |
947 | { |
1400 | { |
948 | dREQ; |
1401 | dREQ; |
949 | |
1402 | |
950 | req->int2 = mode; |
1403 | req->int2 = mode; |
951 | req->sv1 = newSVsv (fh_or_path); |
1404 | req_set_fh_or_path (req, EIO_CHMOD, EIO_FCHMOD, fh_or_path); |
952 | |
|
|
953 | if (SvPOK (req->sv1)) |
|
|
954 | { |
|
|
955 | req->type = ix; |
|
|
956 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
957 | } |
|
|
958 | else |
|
|
959 | { |
|
|
960 | req->type = EIO_FCHMOD; |
|
|
961 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
962 | } |
|
|
963 | |
1405 | |
964 | REQ_SEND; |
1406 | REQ_SEND; |
965 | } |
1407 | } |
966 | |
1408 | |
967 | void |
1409 | void |
… | |
… | |
970 | { |
1412 | { |
971 | dREQ; |
1413 | dREQ; |
972 | |
1414 | |
973 | req->int2 = SvOK (uid) ? SvIV (uid) : -1; |
1415 | req->int2 = SvOK (uid) ? SvIV (uid) : -1; |
974 | req->int3 = SvOK (gid) ? SvIV (gid) : -1; |
1416 | req->int3 = SvOK (gid) ? SvIV (gid) : -1; |
975 | req->sv1 = newSVsv (fh_or_path); |
1417 | req_set_fh_or_path (req, EIO_CHOWN, EIO_FCHOWN, fh_or_path); |
976 | |
|
|
977 | if (SvPOK (req->sv1)) |
|
|
978 | { |
|
|
979 | req->type = EIO_CHOWN; |
|
|
980 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
981 | } |
|
|
982 | else |
|
|
983 | { |
|
|
984 | req->type = EIO_FCHOWN; |
|
|
985 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
986 | } |
|
|
987 | |
1418 | |
988 | REQ_SEND; |
1419 | REQ_SEND; |
989 | } |
1420 | } |
990 | |
1421 | |
991 | void |
1422 | void |
… | |
… | |
993 | PPCODE: |
1424 | PPCODE: |
994 | { |
1425 | { |
995 | dREQ; |
1426 | dREQ; |
996 | |
1427 | |
997 | req->type = EIO_READDIR; |
1428 | req->type = EIO_READDIR; |
998 | req->sv1 = newSVsv (pathname); |
|
|
999 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1000 | req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; |
1429 | req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; |
1001 | |
1430 | |
1002 | if (flags & EIO_READDIR_DENTS) |
1431 | if (flags & EIO_READDIR_DENTS) |
1003 | req->int1 |= EIO_READDIR_CUSTOM2; |
1432 | req->int1 |= EIO_READDIR_CUSTOM2; |
1004 | |
1433 | |
|
|
1434 | req_set_path1 (req, pathname); |
|
|
1435 | |
1005 | REQ_SEND; |
1436 | REQ_SEND; |
|
|
1437 | } |
|
|
1438 | |
|
|
1439 | void |
|
|
1440 | aio_mkdir (SV8 *pathname, int mode, SV *callback=&PL_sv_undef) |
|
|
1441 | PPCODE: |
|
|
1442 | { |
|
|
1443 | dREQ; |
|
|
1444 | |
|
|
1445 | req->type = EIO_MKDIR; |
|
|
1446 | req->int2 = mode; |
|
|
1447 | req_set_path1 (req, pathname); |
|
|
1448 | |
|
|
1449 | REQ_SEND; |
1006 | } |
1450 | } |
1007 | |
1451 | |
1008 | void |
1452 | void |
1009 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
1453 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
1010 | ALIAS: |
1454 | ALIAS: |
… | |
… | |
1014 | PPCODE: |
1458 | PPCODE: |
1015 | { |
1459 | { |
1016 | dREQ; |
1460 | dREQ; |
1017 | |
1461 | |
1018 | req->type = ix; |
1462 | req->type = ix; |
1019 | req->sv1 = newSVsv (pathname); |
1463 | req_set_path1 (req, pathname); |
1020 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1021 | |
1464 | |
1022 | REQ_SEND; |
1465 | REQ_SEND; |
1023 | } |
1466 | } |
1024 | |
1467 | |
1025 | void |
1468 | void |
… | |
… | |
1028 | aio_link = EIO_LINK |
1471 | aio_link = EIO_LINK |
1029 | aio_symlink = EIO_SYMLINK |
1472 | aio_symlink = EIO_SYMLINK |
1030 | aio_rename = EIO_RENAME |
1473 | aio_rename = EIO_RENAME |
1031 | PPCODE: |
1474 | PPCODE: |
1032 | { |
1475 | { |
|
|
1476 | eio_wd wd2 = 0; |
1033 | dREQ; |
1477 | dREQ; |
1034 | |
1478 | |
1035 | req->type = ix; |
1479 | req->type = ix; |
1036 | req->sv1 = newSVsv (oldpath); |
1480 | req_set_path1 (req, oldpath); |
1037 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1481 | req_set_path (req, newpath, &req->sv2, &req->sv4, &wd2, &req->ptr2); |
1038 | req->sv2 = newSVsv (newpath); |
1482 | req->int3 = (long)wd2; |
1039 | req->ptr2 = SvPVbyte_nolen (req->sv2); |
|
|
1040 | |
1483 | |
1041 | REQ_SEND; |
1484 | REQ_SEND; |
1042 | } |
1485 | } |
1043 | |
1486 | |
1044 | void |
1487 | void |
… | |
… | |
1046 | PPCODE: |
1489 | PPCODE: |
1047 | { |
1490 | { |
1048 | dREQ; |
1491 | dREQ; |
1049 | |
1492 | |
1050 | req->type = EIO_MKNOD; |
1493 | req->type = EIO_MKNOD; |
1051 | req->sv1 = newSVsv (pathname); |
|
|
1052 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1053 | req->int2 = (mode_t)mode; |
1494 | req->int2 = (mode_t)mode; |
1054 | req->offs = dev; |
1495 | req->offs = dev; |
|
|
1496 | req_set_path1 (req, pathname); |
1055 | |
1497 | |
1056 | REQ_SEND; |
1498 | REQ_SEND; |
1057 | } |
1499 | } |
1058 | |
1500 | |
1059 | void |
1501 | void |
|
|
1502 | aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) |
|
|
1503 | ALIAS: |
|
|
1504 | aio_mtouch = EIO_MTOUCH |
|
|
1505 | aio_msync = EIO_MSYNC |
|
|
1506 | PPCODE: |
|
|
1507 | { |
|
|
1508 | STRLEN svlen; |
|
|
1509 | char *svptr = SvPVbyte (data, svlen); |
|
|
1510 | UV len = SvUV (length); |
|
|
1511 | |
|
|
1512 | if (offset < 0) |
|
|
1513 | offset += svlen; |
|
|
1514 | |
|
|
1515 | if (offset < 0 || offset > svlen) |
|
|
1516 | croak ("offset outside of scalar"); |
|
|
1517 | |
|
|
1518 | if (!SvOK (length) || len + offset > svlen) |
|
|
1519 | len = svlen - offset; |
|
|
1520 | |
|
|
1521 | { |
|
|
1522 | dREQ; |
|
|
1523 | |
|
|
1524 | req->type = ix; |
|
|
1525 | req->sv2 = SvREFCNT_inc (data); |
|
|
1526 | req->ptr2 = (char *)svptr + offset; |
|
|
1527 | req->size = len; |
|
|
1528 | req->int1 = flags; |
|
|
1529 | |
|
|
1530 | REQ_SEND; |
|
|
1531 | } |
|
|
1532 | } |
|
|
1533 | |
|
|
1534 | void |
|
|
1535 | aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef) |
|
|
1536 | PPCODE: |
|
|
1537 | { |
|
|
1538 | STRLEN svlen; |
|
|
1539 | char *svptr = SvPVbyte (data, svlen); |
|
|
1540 | UV len = SvUV (length); |
|
|
1541 | |
|
|
1542 | if (offset < 0) |
|
|
1543 | offset += svlen; |
|
|
1544 | |
|
|
1545 | if (offset < 0 || offset > svlen) |
|
|
1546 | croak ("offset outside of scalar"); |
|
|
1547 | |
|
|
1548 | if (!SvOK (length) || len + offset > svlen) |
|
|
1549 | len = svlen - offset; |
|
|
1550 | |
|
|
1551 | { |
|
|
1552 | dREQ; |
|
|
1553 | |
|
|
1554 | req->type = EIO_MLOCK; |
|
|
1555 | req->sv2 = SvREFCNT_inc (data); |
|
|
1556 | req->ptr2 = (char *)svptr + offset; |
|
|
1557 | req->size = len; |
|
|
1558 | |
|
|
1559 | REQ_SEND; |
|
|
1560 | } |
|
|
1561 | } |
|
|
1562 | |
|
|
1563 | void |
|
|
1564 | aio_mlockall (IV flags, SV *callback=&PL_sv_undef) |
|
|
1565 | PPCODE: |
|
|
1566 | { |
|
|
1567 | dREQ; |
|
|
1568 | |
|
|
1569 | req->type = EIO_MLOCKALL; |
|
|
1570 | req->int1 = flags; |
|
|
1571 | |
|
|
1572 | REQ_SEND; |
|
|
1573 | } |
|
|
1574 | |
|
|
1575 | void |
|
|
1576 | aio_fiemap (SV *fh, off_t start, SV *length, U32 flags, SV *count, SV *callback=&PL_sv_undef) |
|
|
1577 | PPCODE: |
|
|
1578 | { |
|
|
1579 | int fd = s_fileno_croak (fh, 0); |
|
|
1580 | dREQ; |
|
|
1581 | |
|
|
1582 | req->type = EIO_CUSTOM; |
|
|
1583 | req->sv1 = newSVsv (fh); |
|
|
1584 | req->int1 = fd; |
|
|
1585 | |
|
|
1586 | req->feed = fiemap; |
|
|
1587 | #if HAVE_FIEMAP |
|
|
1588 | /* keep our fingers crossed that the next two types are 64 bit */ |
|
|
1589 | req->offs = start; |
|
|
1590 | req->size = SvOK (length) ? SvVAL64 (length) : ~0ULL; |
|
|
1591 | req->int2 = flags; |
|
|
1592 | req->int3 = SvOK (count) ? SvIV (count) : -1; |
|
|
1593 | #endif |
|
|
1594 | |
|
|
1595 | REQ_SEND; |
|
|
1596 | } |
|
|
1597 | |
|
|
1598 | void |
1060 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1599 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1061 | PPCODE: |
1600 | PPCODE: |
1062 | { |
1601 | { |
1063 | dREQ; |
1602 | dREQ; |
1064 | |
1603 | |
… | |
… | |
1068 | REQ_SEND; |
1607 | REQ_SEND; |
1069 | } |
1608 | } |
1070 | |
1609 | |
1071 | void |
1610 | void |
1072 | aio_group (SV *callback=&PL_sv_undef) |
1611 | aio_group (SV *callback=&PL_sv_undef) |
1073 | PROTOTYPE: ;$ |
|
|
1074 | PPCODE: |
1612 | PPCODE: |
1075 | { |
1613 | { |
1076 | dREQ; |
1614 | dREQ; |
1077 | |
1615 | |
1078 | req->type = EIO_GROUP; |
1616 | req->type = EIO_GROUP; |
1079 | |
1617 | |
1080 | req_submit (req); |
1618 | req_submit (req); |
1081 | XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
1619 | XPUSHs (req_sv (req, aio_grp_stash)); |
1082 | } |
1620 | } |
1083 | |
1621 | |
1084 | void |
1622 | void |
1085 | aio_nop (SV *callback=&PL_sv_undef) |
1623 | aio_nop (SV *callback=&PL_sv_undef) |
1086 | ALIAS: |
1624 | ALIAS: |
… | |
… | |
1095 | REQ_SEND; |
1633 | REQ_SEND; |
1096 | } |
1634 | } |
1097 | |
1635 | |
1098 | int |
1636 | int |
1099 | aioreq_pri (int pri = 0) |
1637 | aioreq_pri (int pri = 0) |
1100 | PROTOTYPE: ;$ |
|
|
1101 | CODE: |
1638 | CODE: |
1102 | RETVAL = next_pri; |
1639 | RETVAL = next_pri; |
1103 | if (items > 0) |
1640 | if (items > 0) |
1104 | { |
1641 | { |
1105 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
1642 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
… | |
… | |
1117 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1654 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1118 | next_pri = nice; |
1655 | next_pri = nice; |
1119 | |
1656 | |
1120 | void |
1657 | void |
1121 | flush () |
1658 | flush () |
1122 | PROTOTYPE: |
|
|
1123 | CODE: |
1659 | CODE: |
1124 | while (eio_nreqs ()) |
1660 | while (eio_nreqs ()) |
1125 | { |
1661 | { |
1126 | poll_wait (); |
1662 | poll_wait (); |
1127 | poll_cb (); |
1663 | poll_cb (); |
1128 | } |
1664 | } |
1129 | |
1665 | |
1130 | int |
1666 | int |
1131 | poll() |
1667 | poll () |
1132 | PROTOTYPE: |
|
|
1133 | CODE: |
1668 | CODE: |
1134 | poll_wait (); |
1669 | poll_wait (); |
1135 | RETVAL = poll_cb (); |
1670 | RETVAL = poll_cb (); |
1136 | OUTPUT: |
1671 | OUTPUT: |
1137 | RETVAL |
1672 | RETVAL |
1138 | |
1673 | |
1139 | int |
1674 | int |
1140 | poll_fileno() |
1675 | poll_fileno () |
1141 | PROTOTYPE: |
|
|
1142 | CODE: |
1676 | CODE: |
1143 | RETVAL = respipe [0]; |
1677 | RETVAL = s_epipe_fd (&respipe); |
1144 | OUTPUT: |
1678 | OUTPUT: |
1145 | RETVAL |
1679 | RETVAL |
1146 | |
1680 | |
1147 | int |
1681 | int |
1148 | poll_cb(...) |
1682 | poll_cb (...) |
1149 | PROTOTYPE: |
1683 | PROTOTYPE: |
1150 | CODE: |
1684 | CODE: |
1151 | RETVAL = poll_cb (); |
1685 | RETVAL = poll_cb (); |
1152 | OUTPUT: |
1686 | OUTPUT: |
1153 | RETVAL |
1687 | RETVAL |
1154 | |
1688 | |
1155 | void |
1689 | void |
1156 | poll_wait() |
1690 | poll_wait () |
1157 | PROTOTYPE: |
|
|
1158 | CODE: |
1691 | CODE: |
1159 | poll_wait (); |
1692 | poll_wait (); |
1160 | |
1693 | |
1161 | int |
1694 | int |
1162 | nreqs() |
1695 | nreqs () |
1163 | PROTOTYPE: |
|
|
1164 | CODE: |
1696 | CODE: |
1165 | RETVAL = eio_nreqs (); |
1697 | RETVAL = eio_nreqs (); |
1166 | OUTPUT: |
1698 | OUTPUT: |
1167 | RETVAL |
1699 | RETVAL |
1168 | |
1700 | |
1169 | int |
1701 | int |
1170 | nready() |
1702 | nready () |
1171 | PROTOTYPE: |
|
|
1172 | CODE: |
1703 | CODE: |
1173 | RETVAL = eio_nready (); |
1704 | RETVAL = eio_nready (); |
1174 | OUTPUT: |
1705 | OUTPUT: |
1175 | RETVAL |
1706 | RETVAL |
1176 | |
1707 | |
1177 | int |
1708 | int |
1178 | npending() |
1709 | npending () |
1179 | PROTOTYPE: |
|
|
1180 | CODE: |
1710 | CODE: |
1181 | RETVAL = eio_npending (); |
1711 | RETVAL = eio_npending (); |
1182 | OUTPUT: |
1712 | OUTPUT: |
1183 | RETVAL |
1713 | RETVAL |
1184 | |
1714 | |
1185 | int |
1715 | int |
1186 | nthreads() |
1716 | nthreads () |
1187 | PROTOTYPE: |
|
|
1188 | CODE: |
1717 | CODE: |
1189 | RETVAL = eio_nthreads (); |
1718 | RETVAL = eio_nthreads (); |
1190 | OUTPUT: |
1719 | OUTPUT: |
1191 | RETVAL |
1720 | RETVAL |
1192 | |
1721 | |
1193 | int |
1722 | int |
1194 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1723 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1195 | PROTOTYPE: $$$$ |
|
|
1196 | CODE: |
1724 | CODE: |
1197 | { |
|
|
1198 | #if _XOPEN_SOURCE >= 600 |
|
|
1199 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1725 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1200 | #else |
|
|
1201 | RETVAL = errno = ENOSYS; |
|
|
1202 | #endif |
|
|
1203 | } |
|
|
1204 | OUTPUT: |
1726 | OUTPUT: |
1205 | RETVAL |
1727 | RETVAL |
1206 | |
1728 | |
1207 | ssize_t |
1729 | IV |
1208 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1730 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1209 | PROTOTYPE: $$$$ |
|
|
1210 | CODE: |
1731 | CODE: |
1211 | eio_sendfile_sync (ofh, ifh, offset, count); |
1732 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
|
|
1733 | OUTPUT: |
|
|
1734 | RETVAL |
|
|
1735 | |
|
|
1736 | void |
|
|
1737 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh = &PL_sv_undef, off_t offset = 0) |
|
|
1738 | PPCODE: |
|
|
1739 | sv_unmagic (scalar, MMAP_MAGIC); |
|
|
1740 | { |
|
|
1741 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
|
|
1742 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
|
|
1743 | if (addr == (void *)-1) |
|
|
1744 | XSRETURN_NO; |
|
|
1745 | |
|
|
1746 | sv_force_normal (scalar); |
|
|
1747 | |
|
|
1748 | /* we store the length in mg_obj, as namlen is I32 :/ */ |
|
|
1749 | sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0) |
|
|
1750 | ->mg_obj = (SV *)length; |
|
|
1751 | |
|
|
1752 | SvUPGRADE (scalar, SVt_PV); /* nop... */ |
|
|
1753 | |
|
|
1754 | if (!(prot & PROT_WRITE)) |
|
|
1755 | SvREADONLY_on (scalar); |
|
|
1756 | |
|
|
1757 | if (SvLEN (scalar)) |
|
|
1758 | Safefree (SvPVX (scalar)); |
|
|
1759 | |
|
|
1760 | SvPVX (scalar) = (char *)addr; |
|
|
1761 | SvCUR_set (scalar, length); |
|
|
1762 | SvLEN_set (scalar, 0); |
|
|
1763 | SvPOK_only (scalar); |
|
|
1764 | |
|
|
1765 | XSRETURN_YES; |
|
|
1766 | } |
|
|
1767 | |
|
|
1768 | void |
|
|
1769 | munmap (SV *scalar) |
|
|
1770 | CODE: |
|
|
1771 | sv_unmagic (scalar, MMAP_MAGIC); |
|
|
1772 | |
|
|
1773 | int |
|
|
1774 | madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
|
|
1775 | ALIAS: |
|
|
1776 | mprotect = 1 |
|
|
1777 | CODE: |
|
|
1778 | { |
|
|
1779 | STRLEN svlen; |
|
|
1780 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1781 | size_t len = SvUV (length); |
|
|
1782 | |
|
|
1783 | if (offset < 0) |
|
|
1784 | offset += svlen; |
|
|
1785 | |
|
|
1786 | if (offset < 0 || offset > svlen) |
|
|
1787 | croak ("offset outside of scalar"); |
|
|
1788 | |
|
|
1789 | if (!SvOK (length) || len + offset > svlen) |
|
|
1790 | len = svlen - offset; |
|
|
1791 | |
|
|
1792 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1793 | eio_page_align (&addr, &len); |
|
|
1794 | |
|
|
1795 | switch (ix) |
|
|
1796 | { |
|
|
1797 | case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break; |
|
|
1798 | case 1: RETVAL = mprotect (addr, len, advice_or_prot); break; |
|
|
1799 | } |
|
|
1800 | } |
|
|
1801 | OUTPUT: |
|
|
1802 | RETVAL |
|
|
1803 | |
|
|
1804 | int |
|
|
1805 | munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) |
|
|
1806 | CODE: |
|
|
1807 | { |
|
|
1808 | STRLEN svlen; |
|
|
1809 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1810 | size_t len = SvUV (length); |
|
|
1811 | |
|
|
1812 | if (offset < 0) |
|
|
1813 | offset += svlen; |
|
|
1814 | |
|
|
1815 | if (offset < 0 || offset > svlen) |
|
|
1816 | croak ("offset outside of scalar"); |
|
|
1817 | |
|
|
1818 | if (!SvOK (length) || len + offset > svlen) |
|
|
1819 | len = svlen - offset; |
|
|
1820 | |
|
|
1821 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1822 | eio_page_align (&addr, &len); |
|
|
1823 | #if _POSIX_MEMLOCK_RANGE |
|
|
1824 | RETVAL = munlock (addr, len); |
|
|
1825 | #else |
|
|
1826 | RETVAL = EIO_ENOSYS (); |
|
|
1827 | #endif |
|
|
1828 | } |
|
|
1829 | OUTPUT: |
|
|
1830 | RETVAL |
|
|
1831 | |
|
|
1832 | int |
|
|
1833 | munlockall () |
|
|
1834 | CODE: |
|
|
1835 | #if _POSIX_MEMLOCK |
|
|
1836 | munlockall (); |
|
|
1837 | #else |
|
|
1838 | RETVAL = EIO_ENOSYS (); |
|
|
1839 | #endif |
|
|
1840 | OUTPUT: |
|
|
1841 | RETVAL |
|
|
1842 | |
|
|
1843 | int |
|
|
1844 | splice (aio_rfd rfh, SV *off_in, aio_wfd wfh, SV *off_out, size_t length, unsigned int flags) |
|
|
1845 | CODE: |
|
|
1846 | { |
|
|
1847 | #if HAVE_LINUX_SPLICE |
|
|
1848 | loff_t off_in_, off_out_; |
|
|
1849 | RETVAL = splice ( |
|
|
1850 | rfh, SvOK (off_in ) ? (off_in_ = SvVAL64 (off_in )), &off_in_ : 0, |
|
|
1851 | wfh, SvOK (off_out) ? (off_out_ = SvVAL64 (off_out)), &off_out_ : 0, |
|
|
1852 | length, flags |
|
|
1853 | ); |
|
|
1854 | #else |
|
|
1855 | RETVAL = EIO_ENOSYS (); |
|
|
1856 | #endif |
|
|
1857 | } |
|
|
1858 | OUTPUT: |
|
|
1859 | RETVAL |
|
|
1860 | |
|
|
1861 | int |
|
|
1862 | tee (aio_rfd rfh, aio_wfd wfh, size_t length, unsigned int flags) |
|
|
1863 | CODE: |
|
|
1864 | #if HAVE_LINUX_SPLICE |
|
|
1865 | RETVAL = tee (rfh, wfh, length, flags); |
|
|
1866 | #else |
|
|
1867 | RETVAL = EIO_ENOSYS (); |
|
|
1868 | #endif |
|
|
1869 | OUTPUT: |
|
|
1870 | RETVAL |
1212 | |
1871 | |
1213 | void _on_next_submit (SV *cb) |
1872 | void _on_next_submit (SV *cb) |
1214 | CODE: |
1873 | CODE: |
1215 | SvREFCNT_dec (on_next_submit); |
1874 | SvREFCNT_dec (on_next_submit); |
1216 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1875 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1217 | |
1876 | |
1218 | PROTOTYPES: DISABLE |
1877 | PROTOTYPES: DISABLE |
1219 | |
1878 | |
|
|
1879 | MODULE = IO::AIO PACKAGE = IO::AIO::WD |
|
|
1880 | |
|
|
1881 | BOOT: |
|
|
1882 | { |
|
|
1883 | newCONSTSUB (aio_stash, "CWD" , newSVaio_wd (EIO_CWD )); |
|
|
1884 | newCONSTSUB (aio_stash, "INVALID_WD", newSVaio_wd (EIO_INVALID_WD)); |
|
|
1885 | } |
|
|
1886 | |
|
|
1887 | void |
|
|
1888 | DESTROY (SV *self) |
|
|
1889 | CODE: |
|
|
1890 | { |
|
|
1891 | aio_wd wd = SvAIO_WD (self); |
|
|
1892 | #if HAVE_AT |
|
|
1893 | { |
|
|
1894 | SV *callback = &PL_sv_undef; |
|
|
1895 | dREQ; /* clobbers next_pri :/ */ |
|
|
1896 | next_pri = req->pri; /* restore next_pri */ |
|
|
1897 | req->pri = EIO_PRI_MAX; /* better use max. priority to conserve fds */ |
|
|
1898 | req->type = EIO_WD_CLOSE; |
|
|
1899 | req->wd = wd; |
|
|
1900 | REQ_SEND; |
|
|
1901 | } |
|
|
1902 | #else |
|
|
1903 | eio_wd_close_sync (wd); |
|
|
1904 | #endif |
|
|
1905 | } |
|
|
1906 | |
1220 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1907 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1221 | |
1908 | |
1222 | void |
1909 | void |
1223 | cancel (aio_req_ornot req) |
1910 | cancel (aio_req_ornot req) |
1224 | CODE: |
1911 | CODE: |
… | |
… | |
1231 | if (GIMME_V != G_VOID) |
1918 | if (GIMME_V != G_VOID) |
1232 | XPUSHs (req->callback ? sv_2mortal (newRV_inc (req->callback)) : &PL_sv_undef); |
1919 | XPUSHs (req->callback ? sv_2mortal (newRV_inc (req->callback)) : &PL_sv_undef); |
1233 | |
1920 | |
1234 | if (items > 1) |
1921 | if (items > 1) |
1235 | { |
1922 | { |
1236 | SV *cb_cv = get_cb (callback); |
1923 | SV *cb_cv =get_cb (callback); |
1237 | |
1924 | |
1238 | SvREFCNT_dec (req->callback); |
1925 | SvREFCNT_dec (req->callback); |
1239 | req->callback = SvREFCNT_inc (cb_cv); |
1926 | req->callback = SvREFCNT_inc (cb_cv); |
1240 | } |
1927 | } |
1241 | } |
1928 | } |