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.181 by root, Tue Feb 15 03:21:41 2011 UTC vs.
Revision 1.187 by root, Sat Jul 16 16:46:10 2011 UTC

11#include <stddef.h> 11#include <stddef.h>
12#include <stdlib.h> 12#include <stdlib.h>
13#include <errno.h> 13#include <errno.h>
14#include <sys/types.h> 14#include <sys/types.h>
15#include <sys/stat.h> 15#include <sys/stat.h>
16#include <sys/statvfs.h>
17#include <limits.h> 16#include <limits.h>
18#include <fcntl.h> 17#include <fcntl.h>
19#include <sched.h> 18#include <sched.h>
20 19
21#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES 20#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES
22# include <sys/mman.h> 21# include <sys/mman.h>
23#endif 22#endif
24 23
25/* perl namespace pollution */ 24/* perl namespace pollution */
26#undef VERSION 25#undef VERSION
26
27/* perl stupidly overrides readdir and maybe others */
28/* with thread-unsafe versions, imagine that :( */
29#undef readdir
30#undef opendir
31#undef closedir
27 32
28#ifdef _WIN32 33#ifdef _WIN32
29 34
30# define EIO_STRUCT_DIRENT Direntry_t 35# define EIO_STRUCT_DIRENT Direntry_t
31# undef malloc 36# undef malloc
35# undef open 40# undef open
36# undef read 41# undef read
37# undef write 42# undef write
38# undef send 43# undef send
39# undef recv 44# undef recv
40# undef stat 45# undef lstat
41# undef fstat
42# define lstat stat
43# undef truncate 46# undef truncate
44# undef ftruncate 47# undef ftruncate
45# undef open 48# undef open
49# undef link
46# undef close 50# undef close
47# undef unlink 51# undef unlink
52# undef mkdir
48# undef rmdir 53# undef rmdir
49# undef rename 54# undef rename
50# undef lseek 55# undef lseek
56# undef opendir
57# undef readdir
58# undef closedir
59# undef chmod
60# undef fchmod
51 61
52# define chown(a,b,c) (errno = ENOSYS, -1)
53# define fchown(a,b,c) (errno = ENOSYS, -1)
54# define fchmod(a,b) (errno = ENOSYS, -1)
55# define symlink(a,b) (errno = ENOSYS, -1)
56# define readlink(a,b,c) (errno = ENOSYS, -1)
57# define mknod(a,b,c) (errno = ENOSYS, -1)
58# define truncate(a,b) (errno = ENOSYS, -1)
59# define ftruncate(fd,o) chsize ((fd), (o))
60# define fsync(fd) _commit (fd)
61# define opendir(fd) (errno = ENOSYS, 0) 62# define opendir(fd) EIO_ERRNO (ENOSYS, 0)
62# define readdir(fd) (errno = ENOSYS, -1) 63# define readdir(fd) EIO_ENOSYS ()
63# define closedir(fd) (errno = ENOSYS, -1) 64# define closedir(fd) EIO_ENOSYS ()
64# define mkdir(a,b) mkdir (a)
65 65
66#else 66#else
67 67
68# include <sys/time.h> 68# include <sys/time.h>
69# include <sys/select.h> 69# include <sys/select.h>
70# include <unistd.h> 70# include <unistd.h>
71# include <utime.h> 71# include <utime.h>
72# include <signal.h> 72# include <signal.h>
73# define EIO_STRUCT_DIRENT struct dirent
74 73
75#endif 74#endif
76
77/* perl stupidly overrides readdir and maybe others */
78/* with thread-unsafe versions, imagine that :( */
79#undef readdir
80#undef opendir
81#undef closedir
82 75
83#define EIO_STRUCT_STAT Stat_t 76#define EIO_STRUCT_STAT Stat_t
84 77
85/* use NV for 32 bit perls as it allows larger offsets */ 78/* use NV for 32 bit perls as it allows larger offsets */
86#if IVSIZE >= 8 79#if IVSIZE >= 8
121#define EIO_NO_WRAPPERS 1 114#define EIO_NO_WRAPPERS 1
122 115
123#include "libeio/config.h" 116#include "libeio/config.h"
124#include "libeio/eio.h" 117#include "libeio/eio.h"
125 118
119/* Linux/others */
120#ifndef O_ASYNC
121# define O_ASYNC 0
122#endif
123#ifndef O_DIRECT
124# define O_DIRECT 0
125#endif
126#ifndef O_NOATIME
127# define O_NOATIME 0
128#endif
129
130/* POSIX */
131#ifndef O_CLOEXEC
132# define O_CLOEXEC 0
133#endif
134#ifndef O_NOFOLLOW
135# define O_NOFOLLOW 0
136#endif
137#ifndef O_NOCTTY
138# define O_NOCTTY 0
139#endif
140#ifndef O_NONBLOCK
141# define O_NONBLOCK 0
142#endif
143#ifndef O_EXEC
144# define O_EXEC 0
145#endif
146#ifndef O_SEARCH
147# define O_SEARCH 0
148#endif
149#ifndef O_DIRECTORY
150# define O_DIRECTORY 0
151#endif
152#ifndef O_DSYNC
153# define O_DSYNC 0
154#endif
155#ifndef O_RSYNC
156# define O_RSYNC 0
157#endif
158#ifndef O_SYNC
159# define O_SYNC 0
160#endif
161#ifndef O_TTY_INIT
162# define O_TTY_INIT 0
163#endif
164
126#ifndef POSIX_FADV_NORMAL 165#ifndef POSIX_FADV_NORMAL
127# define POSIX_FADV_NORMAL 0 166# define POSIX_FADV_NORMAL 0
128#endif 167#endif
129#ifndef POSIX_FADV_SEQUENTIAL 168#ifndef POSIX_FADV_SEQUENTIAL
130# define POSIX_FADV_SEQUENTIAL 0 169# define POSIX_FADV_SEQUENTIAL 0
177#endif 216#endif
178#ifndef PROT_EXEC 217#ifndef PROT_EXEC
179# define PROT_EXEC 0 218# define PROT_EXEC 0
180#endif 219#endif
181 220
221#ifndef ST_RDONLY
222# define ST_RDONLY 0
223#endif
224#ifndef ST_NOSUID
225# define ST_NOSUID 0
226#endif
182#ifndef ST_NODEV 227#ifndef ST_NODEV
183# define ST_NODEV 0 228# define ST_NODEV 0
184#endif 229#endif
185#ifndef ST_NOEXEC 230#ifndef ST_NOEXEC
186# define ST_NOEXEC 0 231# define ST_NOEXEC 0
495 case EIO_STATVFS: 540 case EIO_STATVFS:
496 case EIO_FSTATVFS: 541 case EIO_FSTATVFS:
497 { 542 {
498 SV *rv = &PL_sv_undef; 543 SV *rv = &PL_sv_undef;
499 544
545#ifndef _WIN32
500 if (req->result >= 0) 546 if (req->result >= 0)
501 { 547 {
502 EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); 548 EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req);
503 HV *hv = newHV (); 549 HV *hv = newHV ();
504 550
514 hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); 560 hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0);
515 hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); 561 hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0);
516 hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); 562 hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0);
517 hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); 563 hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0);
518 } 564 }
565#endif
519 566
520 PUSHs (rv); 567 PUSHs (rv);
521 } 568 }
522 569
523 break; 570 break;
539 case EIO_NOP: 586 case EIO_NOP:
540 case EIO_BUSY: 587 case EIO_BUSY:
541 break; 588 break;
542 589
543 case EIO_READLINK: 590 case EIO_READLINK:
591 case EIO_REALPATH:
544 if (req->result > 0) 592 if (req->result > 0)
545 PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); 593 PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result)));
546 break; 594 break;
547 595
548 case EIO_STAT: 596 case EIO_STAT:
620 grp->sv2 = 0; 668 grp->sv2 = 0;
621 669
622 eio_grp_cancel (grp); 670 eio_grp_cancel (grp);
623} 671}
624 672
625static void
626create_respipe (void) 673static void create_respipe (void)
627{ 674{
628 if (s_epipe_renew (&respipe)) 675 if (s_epipe_renew (&respipe))
629 croak ("IO::AIO: unable to initialize result pipe"); 676 croak ("IO::AIO: unable to initialize result pipe");
630} 677}
631 678
685# define MAP_FIXED 0 732# define MAP_FIXED 0
686#endif 733#endif
687 734
688#define MMAP_MAGIC PERL_MAGIC_ext 735#define MMAP_MAGIC PERL_MAGIC_ext
689 736
690static int
691mmap_free (pTHX_ SV *sv, MAGIC *mg) 737static int mmap_free (pTHX_ SV *sv, MAGIC *mg)
692{ 738{
693 int old_errno = errno; 739 int old_errno = errno;
694 munmap (mg->mg_ptr, (size_t)mg->mg_obj); 740 munmap (mg->mg_ptr, (size_t)mg->mg_obj);
695 errno = old_errno; 741 errno = old_errno;
696 742
712 0, 0, 0, 0, mmap_free 758 0, 0, 0, 0, mmap_free
713}; 759};
714 760
715/*****************************************************************************/ 761/*****************************************************************************/
716 762
717static SV *
718get_cb (SV *cb_sv) 763static SV * get_cb (SV *cb_sv)
719{ 764{
720 SvGETMAGIC (cb_sv); 765 SvGETMAGIC (cb_sv);
721 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; 766 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0;
722} 767}
723 768
765 const_iv (O_CREAT) 810 const_iv (O_CREAT)
766 const_iv (O_TRUNC) 811 const_iv (O_TRUNC)
767 const_iv (O_EXCL) 812 const_iv (O_EXCL)
768 const_iv (O_APPEND) 813 const_iv (O_APPEND)
769 814
815 const_iv (O_ASYNC)
816 const_iv (O_DIRECT)
817 const_iv (O_NOATIME)
818
819 const_iv (O_CLOEXEC)
820 const_iv (O_NOCTTY)
821 const_iv (O_NOFOLLOW)
822 const_iv (O_NONBLOCK)
823 const_iv (O_EXEC)
824 const_iv (O_SEARCH)
825 const_iv (O_DIRECTORY)
826 const_iv (O_DSYNC)
827 const_iv (O_RSYNC)
828 const_iv (O_SYNC)
829 const_iv (O_TTY_INIT)
830
770 const_iv (S_IFIFO) 831 const_iv (S_IFIFO)
771 const_iv (S_IFCHR) 832 const_iv (S_IFCHR)
772 const_iv (S_IFBLK) 833 const_iv (S_IFBLK)
773 const_iv (S_IFLNK) 834 const_iv (S_IFLNK)
774 const_iv (S_IFREG) 835 const_iv (S_IFREG)
831 892
832 const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) 893 const_eio (SYNC_FILE_RANGE_WAIT_BEFORE)
833 const_eio (SYNC_FILE_RANGE_WRITE) 894 const_eio (SYNC_FILE_RANGE_WRITE)
834 const_eio (SYNC_FILE_RANGE_WAIT_AFTER) 895 const_eio (SYNC_FILE_RANGE_WAIT_AFTER)
835 896
897 const_eio (FALLOC_FL_KEEP_SIZE)
898
836 const_eio (READDIR_DENTS) 899 const_eio (READDIR_DENTS)
837 const_eio (READDIR_DIRS_FIRST) 900 const_eio (READDIR_DIRS_FIRST)
838 const_eio (READDIR_STAT_ORDER) 901 const_eio (READDIR_STAT_ORDER)
839 const_eio (READDIR_FOUND_UNKNOWN) 902 const_eio (READDIR_FOUND_UNKNOWN)
840 903
957 1020
958 REQ_SEND (req); 1021 REQ_SEND (req);
959} 1022}
960 1023
961void 1024void
1025aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef)
1026 PPCODE:
1027{
1028 int fd = s_fileno_croak (fh, 0);
1029 dREQ;
1030
1031 req->type = EIO_FALLOCATE;
1032 req->sv1 = newSVsv (fh);
1033 req->int1 = fd;
1034 req->int2 = mode;
1035 req->offs = offset;
1036 req->size = len;
1037
1038 REQ_SEND (req);
1039}
1040
1041void
962aio_close (SV *fh, SV *callback=&PL_sv_undef) 1042aio_close (SV *fh, SV *callback=&PL_sv_undef)
963 PPCODE: 1043 PPCODE:
964{ 1044{
965 static int close_pipe = -1; /* dummy fd to close fds via dup2 */ 1045 static int close_fd = -1; /* dummy fd to close fds via dup2 */
966 int fd = s_fileno_croak (fh, 0); 1046 int fd = s_fileno_croak (fh, 0);
967 dREQ; 1047 dREQ;
968 1048
969 if (close_pipe < 0) 1049 if (expect_false (close_fd < 0))
970 { 1050 {
1051#ifdef _WIN32
1052 close_fd = _open_osfhandle (socket (AF_INET, SOCK_STREAM, 0), 0);
1053#else
971 int pipefd [2]; 1054 int pipefd [2];
972 1055
973 if (pipe (pipefd) < 0 1056 if (pipe (pipefd) < 0
974 || close (pipefd [1]) < 0 1057 || close (pipefd [1]) < 0
975 || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) 1058 || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0)
976 abort (); /*D*/ 1059 abort (); /*D*/
977 1060
978 close_pipe = pipefd [0]; 1061 close_fd = pipefd [0];
1062#endif
979 } 1063 }
980 1064
981 req->type = EIO_DUP2; 1065 req->type = EIO_DUP2;
982 req->int1 = close_pipe; 1066 req->int1 = close_fd;
983 req->sv2 = newSVsv (fh); 1067 req->sv2 = newSVsv (fh);
984 req->int2 = fd; 1068 req->int2 = fd;
985 1069
986 REQ_SEND (req); 1070 REQ_SEND (req);
987} 1071}
1039 } 1123 }
1040} 1124}
1041 1125
1042void 1126void
1043aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) 1127aio_readlink (SV8 *path, SV *callback=&PL_sv_undef)
1128 ALIAS:
1129 aio_readlink = EIO_READLINK
1130 aio_realpath = EIO_REALPATH
1044 PPCODE: 1131 PPCODE:
1045{ 1132{
1046 SV *data; 1133 SV *data;
1047 dREQ; 1134 dREQ;
1048 1135
1049 req->type = EIO_READLINK; 1136 req->type = ix;
1050 req->sv1 = newSVsv (path); 1137 req->sv1 = newSVsv (path);
1051 req->ptr1 = SvPVbyte_nolen (req->sv1); 1138 req->ptr1 = SvPVbyte_nolen (req->sv1);
1052 1139
1053 REQ_SEND; 1140 REQ_SEND;
1054} 1141}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines