ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.xs
(Generate patch)

Comparing IO-AIO/AIO.xs (file contents):
Revision 1.186 by root, Thu Jul 14 22:36:17 2011 UTC vs.
Revision 1.193 by root, Mon Jul 25 16:51:07 2011 UTC

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 // perl overrides all those nice libc functions
36
37 #undef malloc
38 #undef free
39 #undef open
40 #undef read
41 #undef write
42 #undef send
43 #undef recv
44 #undef stat
45 #undef lstat
46 #undef fstat
47 #undef truncate
48 #undef ftruncate
49 #undef open
50 #undef link
51 #undef close
52 #undef unlink
53 #undef mkdir
54 #undef rmdir
55 #undef rename
56 #undef lseek
57 #undef opendir
58 #undef readdir
59 #undef closedir
60 #undef chmod
61 #undef fchmod
62 #undef dup
63 #undef dup2
64 #undef abort
65 #undef pipe
66
67#else
68
69 #include <sys/time.h>
70 #include <sys/select.h>
71 #include <unistd.h>
72 #include <utime.h>
73 #include <signal.h>
74
75#endif
71 76
72#define EIO_STRUCT_STAT Stat_t 77#define EIO_STRUCT_STAT Stat_t
73 78
74/* use NV for 32 bit perls as it allows larger offsets */ 79/* use NV for 32 bit perls as it allows larger offsets */
75#if IVSIZE >= 8 80#if IVSIZE >= 8
110#define EIO_NO_WRAPPERS 1 115#define EIO_NO_WRAPPERS 1
111 116
112#include "libeio/config.h" 117#include "libeio/config.h"
113#include "libeio/eio.h" 118#include "libeio/eio.h"
114 119
120static int req_invoke (eio_req *req);
121#define EIO_FINISH(req) req_invoke (req)
122static void req_destroy (eio_req *grp);
123#define EIO_DESTROY(req) req_destroy (req)
124
125#include "libeio/eio.c"
126
115/* Linux/others */ 127/* Linux/others */
116#ifndef O_ASYNC 128#ifndef O_ASYNC
117# define O_ASYNC 0 129# define O_ASYNC 0
118#endif 130#endif
119#ifndef O_DIRECT 131#ifndef O_DIRECT
212#endif 224#endif
213#ifndef PROT_EXEC 225#ifndef PROT_EXEC
214# define PROT_EXEC 0 226# define PROT_EXEC 0
215#endif 227#endif
216 228
229#ifndef ST_RDONLY
230# define ST_RDONLY 0
231#endif
232#ifndef ST_NOSUID
233# define ST_NOSUID 0
234#endif
217#ifndef ST_NODEV 235#ifndef ST_NODEV
218# define ST_NODEV 0 236# define ST_NODEV 0
219#endif 237#endif
220#ifndef ST_NOEXEC 238#ifndef ST_NOEXEC
221# define ST_NOEXEC 0 239# define ST_NOEXEC 0
305 323
306#ifndef PAGESIZE 324#ifndef PAGESIZE
307# define PAGESIZE sysconf (_SC_PAGESIZE) 325# define PAGESIZE sysconf (_SC_PAGESIZE)
308#endif 326#endif
309 327
310static int req_invoke (eio_req *req);
311#define EIO_FINISH(req) req_invoke (req)
312static void req_destroy (eio_req *grp);
313#define EIO_DESTROY(req) req_destroy (req)
314
315enum { 328enum {
316 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ 329 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */
317}; 330};
318
319#include "libeio/eio.c"
320 331
321typedef eio_req *aio_req; 332typedef eio_req *aio_req;
322typedef eio_req *aio_req_ornot; 333typedef eio_req *aio_req_ornot;
323 334
324static SV *on_next_submit; 335static SV *on_next_submit;
530 case EIO_STATVFS: 541 case EIO_STATVFS:
531 case EIO_FSTATVFS: 542 case EIO_FSTATVFS:
532 { 543 {
533 SV *rv = &PL_sv_undef; 544 SV *rv = &PL_sv_undef;
534 545
546#ifndef _WIN32
535 if (req->result >= 0) 547 if (req->result >= 0)
536 { 548 {
537 EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); 549 EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req);
538 HV *hv = newHV (); 550 HV *hv = newHV ();
539 551
549 hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); 561 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); 562 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); 563 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); 564 hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0);
553 } 565 }
566#endif
554 567
555 PUSHs (rv); 568 PUSHs (rv);
556 } 569 }
557 570
558 break; 571 break;
584 case EIO_STAT: 597 case EIO_STAT:
585 case EIO_LSTAT: 598 case EIO_LSTAT:
586 case EIO_FSTAT: 599 case EIO_FSTAT:
587 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; 600 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT;
588 PL_laststatval = req->result; 601 PL_laststatval = req->result;
602 /* if compilation fails here then perl's Stat_t is not struct _stati64 */
589 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); 603 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2);
590 PUSHs (sv_result); 604 PUSHs (sv_result);
591 break; 605 break;
592 606
593 case EIO_READ: 607 case EIO_READ:
645 Safefree (req); 659 Safefree (req);
646} 660}
647 661
648static void req_cancel_subs (aio_req grp) 662static void req_cancel_subs (aio_req grp)
649{ 663{
650 aio_req sub;
651
652 if (grp->type != EIO_GROUP) 664 if (grp->type != EIO_GROUP)
653 return; 665 return;
654 666
655 SvREFCNT_dec (grp->sv2); 667 SvREFCNT_dec (grp->sv2);
656 grp->sv2 = 0; 668 grp->sv2 = 0;
697 709
698 poll_wait (); 710 poll_wait ();
699 } 711 }
700} 712}
701 713
702static void atfork_child (void) 714static void ecb_cold
715reinit (void)
703{ 716{
704 create_respipe (); 717 create_respipe ();
718
719 if (eio_init (want_poll, done_poll) < 0)
720 croak ("IO::AIO: unable to initialise eio library");
705} 721}
706 722
707/*****************************************************************************/ 723/*****************************************************************************/
708 724
709#if !_POSIX_MAPPED_FILES 725#if !_POSIX_MAPPED_FILES
907 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 923 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
908 newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); 924 newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv));
909 925
910 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); 926 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE));
911 927
912 create_respipe (); 928 reinit ();
913
914 if (eio_init (want_poll, done_poll) < 0)
915 croak ("IO::AIO: unable to initialise eio library");
916
917 /* atfork child called in fifo order, so before eio's handler */
918 X_THREAD_ATFORK (0, 0, atfork_child);
919} 929}
930
931void
932reinit ()
933 PROTOTYPE:
920 934
921void 935void
922max_poll_reqs (unsigned int nreqs) 936max_poll_reqs (unsigned int nreqs)
923 PROTOTYPE: $ 937 PROTOTYPE: $
924 CODE: 938 CODE:
978void 992void
979aio_fsync (SV *fh, SV *callback=&PL_sv_undef) 993aio_fsync (SV *fh, SV *callback=&PL_sv_undef)
980 ALIAS: 994 ALIAS:
981 aio_fsync = EIO_FSYNC 995 aio_fsync = EIO_FSYNC
982 aio_fdatasync = EIO_FDATASYNC 996 aio_fdatasync = EIO_FDATASYNC
997 aio_syncfs = EIO_SYNCFS
983 PPCODE: 998 PPCODE:
984{ 999{
985 int fd = s_fileno_croak (fh, 0); 1000 int fd = s_fileno_croak (fh, 0);
986 dREQ; 1001 dREQ;
987 1002
1028 1043
1029void 1044void
1030aio_close (SV *fh, SV *callback=&PL_sv_undef) 1045aio_close (SV *fh, SV *callback=&PL_sv_undef)
1031 PPCODE: 1046 PPCODE:
1032{ 1047{
1033 static int close_pipe = -1; /* dummy fd to close fds via dup2 */ 1048 static int close_fd = -1; /* dummy fd to close fds via dup2 */
1034 int fd = s_fileno_croak (fh, 0); 1049 int fd = s_fileno_croak (fh, 0);
1035 dREQ; 1050 dREQ;
1036 1051
1037 if (close_pipe < 0) 1052 if (expect_false (close_fd < 0))
1038 { 1053 {
1039 int pipefd [2]; 1054 int pipefd [2];
1040 1055
1056 if (
1057#ifdef _WIN32
1058 _pipe (pipefd, 1, _O_BINARY) < 0
1059#else
1041 if (pipe (pipefd) < 0 1060 pipe (pipefd) < 0
1042 || close (pipefd [1]) < 0
1043 || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) 1061 || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0
1062#endif
1063 || close (pipefd [1]) < 0
1064 )
1044 abort (); /*D*/ 1065 abort (); /*D*/
1045 1066
1046 close_pipe = pipefd [0]; 1067 close_fd = pipefd [0];
1047 } 1068 }
1048 1069
1049 req->type = EIO_DUP2; 1070 req->type = EIO_DUP2;
1050 req->int1 = close_pipe; 1071 req->int1 = close_fd;
1051 req->sv2 = newSVsv (fh); 1072 req->sv2 = newSVsv (fh);
1052 req->int2 = fd; 1073 req->int2 = fd;
1053 1074
1054 REQ_SEND (req); 1075 REQ_SEND (req);
1055} 1076}
1112 ALIAS: 1133 ALIAS:
1113 aio_readlink = EIO_READLINK 1134 aio_readlink = EIO_READLINK
1114 aio_realpath = EIO_REALPATH 1135 aio_realpath = EIO_REALPATH
1115 PPCODE: 1136 PPCODE:
1116{ 1137{
1117 SV *data;
1118 dREQ; 1138 dREQ;
1119 1139
1120 req->type = ix; 1140 req->type = ix;
1121 req->sv1 = newSVsv (path); 1141 req->sv1 = newSVsv (path);
1122 req->ptr1 = SvPVbyte_nolen (req->sv1); 1142 req->ptr1 = SvPVbyte_nolen (req->sv1);
1569 CODE: 1589 CODE:
1570 RETVAL = posix_fadvise (fh, offset, length, advice); 1590 RETVAL = posix_fadvise (fh, offset, length, advice);
1571 OUTPUT: 1591 OUTPUT:
1572 RETVAL 1592 RETVAL
1573 1593
1574ssize_t 1594IV
1575sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) 1595sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count)
1576 CODE: 1596 CODE:
1577 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); 1597 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count);
1578 OUTPUT: 1598 OUTPUT:
1579 RETVAL 1599 RETVAL

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines