… | |
… | |
22 | #endif |
22 | #endif |
23 | |
23 | |
24 | /* perl namespace pollution */ |
24 | /* perl namespace pollution */ |
25 | #undef VERSION |
25 | #undef VERSION |
26 | |
26 | |
27 | #ifdef _WIN32 |
|
|
28 | |
|
|
29 | # define EIO_STRUCT_DIRENT Direntry_t |
|
|
30 | # undef malloc |
|
|
31 | # undef free |
|
|
32 | |
|
|
33 | // perl overrides all those nice win32 functions |
|
|
34 | # undef open |
|
|
35 | # undef read |
|
|
36 | # undef write |
|
|
37 | # undef send |
|
|
38 | # undef recv |
|
|
39 | # undef stat |
|
|
40 | # undef fstat |
|
|
41 | # define lstat stat |
|
|
42 | # undef truncate |
|
|
43 | # undef ftruncate |
|
|
44 | # undef open |
|
|
45 | # undef close |
|
|
46 | # undef unlink |
|
|
47 | # undef rmdir |
|
|
48 | # undef rename |
|
|
49 | # undef lseek |
|
|
50 | |
|
|
51 | # define opendir(fd) (errno = ENOSYS, 0) |
|
|
52 | # define readdir(fd) (errno = ENOSYS, -1) |
|
|
53 | # define closedir(fd) (errno = ENOSYS, -1) |
|
|
54 | |
|
|
55 | #else |
|
|
56 | |
|
|
57 | # include <sys/time.h> |
|
|
58 | # include <sys/select.h> |
|
|
59 | # include <unistd.h> |
|
|
60 | # include <utime.h> |
|
|
61 | # include <signal.h> |
|
|
62 | # define EIO_STRUCT_DIRENT struct dirent |
|
|
63 | |
|
|
64 | #endif |
|
|
65 | |
|
|
66 | /* perl stupidly overrides readdir and maybe others */ |
27 | /* perl stupidly overrides readdir and maybe others */ |
67 | /* with thread-unsafe versions, imagine that :( */ |
28 | /* with thread-unsafe versions, imagine that :( */ |
68 | #undef readdir |
29 | #undef readdir |
69 | #undef opendir |
30 | #undef opendir |
70 | #undef closedir |
31 | #undef closedir |
|
|
32 | |
|
|
33 | #ifdef _WIN32 |
|
|
34 | |
|
|
35 | #define EIO_STRUCT_DIRENT Direntry_t |
|
|
36 | #undef malloc |
|
|
37 | #undef free |
|
|
38 | |
|
|
39 | // perl overrides all those nice libc functions |
|
|
40 | #undef open |
|
|
41 | #undef read |
|
|
42 | #undef write |
|
|
43 | #undef send |
|
|
44 | #undef recv |
|
|
45 | #undef stat |
|
|
46 | #undef lstat |
|
|
47 | #undef fstat |
|
|
48 | #undef truncate |
|
|
49 | #undef ftruncate |
|
|
50 | #undef open |
|
|
51 | #undef link |
|
|
52 | #undef close |
|
|
53 | #undef unlink |
|
|
54 | #undef mkdir |
|
|
55 | #undef rmdir |
|
|
56 | #undef rename |
|
|
57 | #undef lseek |
|
|
58 | #undef opendir |
|
|
59 | #undef readdir |
|
|
60 | #undef closedir |
|
|
61 | #undef chmod |
|
|
62 | #undef fchmod |
|
|
63 | #undef dup |
|
|
64 | #undef dup2 |
|
|
65 | #undef abort |
|
|
66 | #undef pipe |
|
|
67 | |
|
|
68 | #else |
|
|
69 | |
|
|
70 | #include <sys/time.h> |
|
|
71 | #include <sys/select.h> |
|
|
72 | #include <unistd.h> |
|
|
73 | #include <utime.h> |
|
|
74 | #include <signal.h> |
|
|
75 | |
|
|
76 | #endif |
71 | |
77 | |
72 | #define EIO_STRUCT_STAT Stat_t |
78 | #define EIO_STRUCT_STAT Stat_t |
73 | |
79 | |
74 | /* use NV for 32 bit perls as it allows larger offsets */ |
80 | /* use NV for 32 bit perls as it allows larger offsets */ |
75 | #if IVSIZE >= 8 |
81 | #if IVSIZE >= 8 |
… | |
… | |
110 | #define EIO_NO_WRAPPERS 1 |
116 | #define EIO_NO_WRAPPERS 1 |
111 | |
117 | |
112 | #include "libeio/config.h" |
118 | #include "libeio/config.h" |
113 | #include "libeio/eio.h" |
119 | #include "libeio/eio.h" |
114 | |
120 | |
|
|
121 | static int req_invoke (eio_req *req); |
|
|
122 | #define EIO_FINISH(req) req_invoke (req) |
|
|
123 | static void req_destroy (eio_req *grp); |
|
|
124 | #define EIO_DESTROY(req) req_destroy (req) |
|
|
125 | |
|
|
126 | #include "libeio/eio.c" |
|
|
127 | |
115 | /* Linux/others */ |
128 | /* Linux/others */ |
116 | #ifndef O_ASYNC |
129 | #ifndef O_ASYNC |
117 | # define O_ASYNC 0 |
130 | # define O_ASYNC 0 |
118 | #endif |
131 | #endif |
119 | #ifndef O_DIRECT |
132 | #ifndef O_DIRECT |
… | |
… | |
212 | #endif |
225 | #endif |
213 | #ifndef PROT_EXEC |
226 | #ifndef PROT_EXEC |
214 | # define PROT_EXEC 0 |
227 | # define PROT_EXEC 0 |
215 | #endif |
228 | #endif |
216 | |
229 | |
|
|
230 | #ifndef ST_RDONLY |
|
|
231 | # define ST_RDONLY 0 |
|
|
232 | #endif |
|
|
233 | #ifndef ST_NOSUID |
|
|
234 | # define ST_NOSUID 0 |
|
|
235 | #endif |
217 | #ifndef ST_NODEV |
236 | #ifndef ST_NODEV |
218 | # define ST_NODEV 0 |
237 | # define ST_NODEV 0 |
219 | #endif |
238 | #endif |
220 | #ifndef ST_NOEXEC |
239 | #ifndef ST_NOEXEC |
221 | # define ST_NOEXEC 0 |
240 | # define ST_NOEXEC 0 |
… | |
… | |
305 | |
324 | |
306 | #ifndef PAGESIZE |
325 | #ifndef PAGESIZE |
307 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
326 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
308 | #endif |
327 | #endif |
309 | |
328 | |
310 | static int req_invoke (eio_req *req); |
|
|
311 | #define EIO_FINISH(req) req_invoke (req) |
|
|
312 | static void req_destroy (eio_req *grp); |
|
|
313 | #define EIO_DESTROY(req) req_destroy (req) |
|
|
314 | |
|
|
315 | enum { |
329 | enum { |
316 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
330 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
317 | }; |
331 | }; |
318 | |
|
|
319 | #include "libeio/eio.c" |
|
|
320 | |
332 | |
321 | typedef eio_req *aio_req; |
333 | typedef eio_req *aio_req; |
322 | typedef eio_req *aio_req_ornot; |
334 | typedef eio_req *aio_req_ornot; |
323 | |
335 | |
324 | static SV *on_next_submit; |
336 | static SV *on_next_submit; |
… | |
… | |
530 | case EIO_STATVFS: |
542 | case EIO_STATVFS: |
531 | case EIO_FSTATVFS: |
543 | case EIO_FSTATVFS: |
532 | { |
544 | { |
533 | SV *rv = &PL_sv_undef; |
545 | SV *rv = &PL_sv_undef; |
534 | |
546 | |
|
|
547 | #ifndef _WIN32 |
535 | if (req->result >= 0) |
548 | if (req->result >= 0) |
536 | { |
549 | { |
537 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
550 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
538 | HV *hv = newHV (); |
551 | HV *hv = newHV (); |
539 | |
552 | |
… | |
… | |
549 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
562 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
550 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
563 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
551 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
564 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
552 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
565 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
553 | } |
566 | } |
|
|
567 | #endif |
554 | |
568 | |
555 | PUSHs (rv); |
569 | PUSHs (rv); |
556 | } |
570 | } |
557 | |
571 | |
558 | break; |
572 | break; |
… | |
… | |
584 | case EIO_STAT: |
598 | case EIO_STAT: |
585 | case EIO_LSTAT: |
599 | case EIO_LSTAT: |
586 | case EIO_FSTAT: |
600 | case EIO_FSTAT: |
587 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
601 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
588 | PL_laststatval = req->result; |
602 | PL_laststatval = req->result; |
|
|
603 | /* if compilation fails here then perl's Stat_t is not struct _stati64 */ |
589 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
604 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
590 | PUSHs (sv_result); |
605 | PUSHs (sv_result); |
591 | break; |
606 | break; |
592 | |
607 | |
593 | case EIO_READ: |
608 | case EIO_READ: |
… | |
… | |
645 | Safefree (req); |
660 | Safefree (req); |
646 | } |
661 | } |
647 | |
662 | |
648 | static void req_cancel_subs (aio_req grp) |
663 | static void req_cancel_subs (aio_req grp) |
649 | { |
664 | { |
650 | aio_req sub; |
|
|
651 | |
|
|
652 | if (grp->type != EIO_GROUP) |
665 | if (grp->type != EIO_GROUP) |
653 | return; |
666 | return; |
654 | |
667 | |
655 | SvREFCNT_dec (grp->sv2); |
668 | SvREFCNT_dec (grp->sv2); |
656 | grp->sv2 = 0; |
669 | grp->sv2 = 0; |
… | |
… | |
1028 | |
1041 | |
1029 | void |
1042 | void |
1030 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1043 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1031 | PPCODE: |
1044 | PPCODE: |
1032 | { |
1045 | { |
1033 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
1046 | static int close_fd = -1; /* dummy fd to close fds via dup2 */ |
1034 | int fd = s_fileno_croak (fh, 0); |
1047 | int fd = s_fileno_croak (fh, 0); |
1035 | dREQ; |
1048 | dREQ; |
1036 | |
1049 | |
1037 | if (close_pipe < 0) |
1050 | if (expect_false (close_fd < 0)) |
1038 | { |
1051 | { |
1039 | int pipefd [2]; |
1052 | int pipefd [2]; |
1040 | |
1053 | |
|
|
1054 | if ( |
|
|
1055 | #ifdef _WIN32 |
|
|
1056 | _pipe (pipefd, 1, _O_BINARY) < 0 |
|
|
1057 | #else |
1041 | if (pipe (pipefd) < 0 |
1058 | pipe (pipefd) < 0 |
1042 | || close (pipefd [1]) < 0 |
|
|
1043 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) |
1059 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0 |
|
|
1060 | #endif |
|
|
1061 | || close (pipefd [1]) < 0 |
|
|
1062 | ) |
1044 | abort (); /*D*/ |
1063 | abort (); /*D*/ |
1045 | |
1064 | |
1046 | close_pipe = pipefd [0]; |
1065 | close_fd = pipefd [0]; |
1047 | } |
1066 | } |
1048 | |
1067 | |
1049 | req->type = EIO_DUP2; |
1068 | req->type = EIO_DUP2; |
1050 | req->int1 = close_pipe; |
1069 | req->int1 = close_fd; |
1051 | req->sv2 = newSVsv (fh); |
1070 | req->sv2 = newSVsv (fh); |
1052 | req->int2 = fd; |
1071 | req->int2 = fd; |
1053 | |
1072 | |
1054 | REQ_SEND (req); |
1073 | REQ_SEND (req); |
1055 | } |
1074 | } |
… | |
… | |
1112 | ALIAS: |
1131 | ALIAS: |
1113 | aio_readlink = EIO_READLINK |
1132 | aio_readlink = EIO_READLINK |
1114 | aio_realpath = EIO_REALPATH |
1133 | aio_realpath = EIO_REALPATH |
1115 | PPCODE: |
1134 | PPCODE: |
1116 | { |
1135 | { |
1117 | SV *data; |
|
|
1118 | dREQ; |
1136 | dREQ; |
1119 | |
1137 | |
1120 | req->type = ix; |
1138 | req->type = ix; |
1121 | req->sv1 = newSVsv (path); |
1139 | req->sv1 = newSVsv (path); |
1122 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1140 | req->ptr1 = SvPVbyte_nolen (req->sv1); |