… | |
… | |
30 | #undef opendir |
30 | #undef opendir |
31 | #undef closedir |
31 | #undef closedir |
32 | |
32 | |
33 | #ifdef _WIN32 |
33 | #ifdef _WIN32 |
34 | |
34 | |
35 | # define EIO_STRUCT_DIRENT Direntry_t |
35 | #define EIO_STRUCT_DIRENT Direntry_t |
36 | # undef malloc |
36 | #undef malloc |
37 | # undef free |
37 | #undef free |
38 | |
38 | |
39 | // perl overrides all those nice win32 functions |
39 | // perl overrides all those nice libc functions |
40 | # undef open |
40 | #undef open |
41 | # undef read |
41 | #undef read |
42 | # undef write |
42 | #undef write |
43 | # undef send |
43 | #undef send |
44 | # undef recv |
44 | #undef recv |
|
|
45 | #undef stat |
45 | # undef lstat |
46 | #undef lstat |
|
|
47 | #undef fstat |
46 | # undef truncate |
48 | #undef truncate |
47 | # undef ftruncate |
49 | #undef ftruncate |
48 | # undef open |
50 | #undef open |
49 | # undef link |
51 | #undef link |
50 | # undef close |
52 | #undef close |
51 | # undef unlink |
53 | #undef unlink |
52 | # undef mkdir |
54 | #undef mkdir |
53 | # undef rmdir |
55 | #undef rmdir |
54 | # undef rename |
56 | #undef rename |
55 | # undef lseek |
57 | #undef lseek |
56 | # undef opendir |
58 | #undef opendir |
57 | # undef readdir |
59 | #undef readdir |
58 | # undef closedir |
60 | #undef closedir |
59 | # undef chmod |
61 | #undef chmod |
60 | # undef fchmod |
62 | #undef fchmod |
61 | |
63 | #undef dup |
62 | # define opendir(fd) EIO_ERRNO (ENOSYS, 0) |
64 | #undef dup2 |
63 | # define readdir(fd) EIO_ENOSYS () |
65 | #undef abort |
64 | # define closedir(fd) EIO_ENOSYS () |
66 | #undef pipe |
65 | |
67 | |
66 | #else |
68 | #else |
67 | |
69 | |
68 | # include <sys/time.h> |
70 | #include <sys/time.h> |
69 | # include <sys/select.h> |
71 | #include <sys/select.h> |
70 | # include <unistd.h> |
72 | #include <unistd.h> |
71 | # include <utime.h> |
73 | #include <utime.h> |
72 | # include <signal.h> |
74 | #include <signal.h> |
73 | |
75 | |
74 | #endif |
76 | #endif |
75 | |
77 | |
76 | #define EIO_STRUCT_STAT Stat_t |
78 | #define EIO_STRUCT_STAT Stat_t |
77 | |
79 | |
… | |
… | |
114 | #define EIO_NO_WRAPPERS 1 |
116 | #define EIO_NO_WRAPPERS 1 |
115 | |
117 | |
116 | #include "libeio/config.h" |
118 | #include "libeio/config.h" |
117 | #include "libeio/eio.h" |
119 | #include "libeio/eio.h" |
118 | |
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 | |
119 | /* Linux/others */ |
128 | /* Linux/others */ |
120 | #ifndef O_ASYNC |
129 | #ifndef O_ASYNC |
121 | # define O_ASYNC 0 |
130 | # define O_ASYNC 0 |
122 | #endif |
131 | #endif |
123 | #ifndef O_DIRECT |
132 | #ifndef O_DIRECT |
… | |
… | |
315 | |
324 | |
316 | #ifndef PAGESIZE |
325 | #ifndef PAGESIZE |
317 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
326 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
318 | #endif |
327 | #endif |
319 | |
328 | |
320 | static int req_invoke (eio_req *req); |
|
|
321 | #define EIO_FINISH(req) req_invoke (req) |
|
|
322 | static void req_destroy (eio_req *grp); |
|
|
323 | #define EIO_DESTROY(req) req_destroy (req) |
|
|
324 | |
|
|
325 | enum { |
329 | enum { |
326 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
330 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
327 | }; |
331 | }; |
328 | |
|
|
329 | #include "libeio/eio.c" |
|
|
330 | |
332 | |
331 | typedef eio_req *aio_req; |
333 | typedef eio_req *aio_req; |
332 | typedef eio_req *aio_req_ornot; |
334 | typedef eio_req *aio_req_ornot; |
333 | |
335 | |
334 | static SV *on_next_submit; |
336 | static SV *on_next_submit; |
… | |
… | |
596 | case EIO_STAT: |
598 | case EIO_STAT: |
597 | case EIO_LSTAT: |
599 | case EIO_LSTAT: |
598 | case EIO_FSTAT: |
600 | case EIO_FSTAT: |
599 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
601 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
600 | PL_laststatval = req->result; |
602 | PL_laststatval = req->result; |
|
|
603 | /* if compilation fails here then perl's Stat_t is not struct _stati64 */ |
601 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
604 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
602 | PUSHs (sv_result); |
605 | PUSHs (sv_result); |
603 | break; |
606 | break; |
604 | |
607 | |
605 | case EIO_READ: |
608 | case EIO_READ: |
… | |
… | |
657 | Safefree (req); |
660 | Safefree (req); |
658 | } |
661 | } |
659 | |
662 | |
660 | static void req_cancel_subs (aio_req grp) |
663 | static void req_cancel_subs (aio_req grp) |
661 | { |
664 | { |
662 | aio_req sub; |
|
|
663 | |
|
|
664 | if (grp->type != EIO_GROUP) |
665 | if (grp->type != EIO_GROUP) |
665 | return; |
666 | return; |
666 | |
667 | |
667 | SvREFCNT_dec (grp->sv2); |
668 | SvREFCNT_dec (grp->sv2); |
668 | grp->sv2 = 0; |
669 | grp->sv2 = 0; |
… | |
… | |
1046 | int fd = s_fileno_croak (fh, 0); |
1047 | int fd = s_fileno_croak (fh, 0); |
1047 | dREQ; |
1048 | dREQ; |
1048 | |
1049 | |
1049 | if (expect_false (close_fd < 0)) |
1050 | if (expect_false (close_fd < 0)) |
1050 | { |
1051 | { |
|
|
1052 | int pipefd [2]; |
|
|
1053 | |
|
|
1054 | if ( |
1051 | #ifdef _WIN32 |
1055 | #ifdef _WIN32 |
1052 | close_fd = _open_osfhandle (socket (AF_INET, SOCK_STREAM, 0), 0); |
1056 | _pipe (pipefd, 1, _O_BINARY) < 0 |
1053 | #else |
1057 | #else |
1054 | int pipefd [2]; |
|
|
1055 | |
|
|
1056 | if (pipe (pipefd) < 0 |
1058 | pipe (pipefd) < 0 |
1057 | || close (pipefd [1]) < 0 |
|
|
1058 | || 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 | ) |
1059 | abort (); /*D*/ |
1063 | abort (); /*D*/ |
1060 | |
1064 | |
1061 | close_fd = pipefd [0]; |
1065 | close_fd = pipefd [0]; |
1062 | #endif |
|
|
1063 | } |
1066 | } |
1064 | |
1067 | |
1065 | req->type = EIO_DUP2; |
1068 | req->type = EIO_DUP2; |
1066 | req->int1 = close_fd; |
1069 | req->int1 = close_fd; |
1067 | req->sv2 = newSVsv (fh); |
1070 | req->sv2 = newSVsv (fh); |
… | |
… | |
1128 | ALIAS: |
1131 | ALIAS: |
1129 | aio_readlink = EIO_READLINK |
1132 | aio_readlink = EIO_READLINK |
1130 | aio_realpath = EIO_REALPATH |
1133 | aio_realpath = EIO_REALPATH |
1131 | PPCODE: |
1134 | PPCODE: |
1132 | { |
1135 | { |
1133 | SV *data; |
|
|
1134 | dREQ; |
1136 | dREQ; |
1135 | |
1137 | |
1136 | req->type = ix; |
1138 | req->type = ix; |
1137 | req->sv1 = newSVsv (path); |
1139 | req->sv1 = newSVsv (path); |
1138 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1140 | req->ptr1 = SvPVbyte_nolen (req->sv1); |