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.187 by root, Sat Jul 16 16:46:10 2011 UTC vs.
Revision 1.192 by root, Sun Jul 24 03:32:52 2011 UTC

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
36# undef malloc
37# undef free
38
39// perl overrides all those nice win32 functions 35 // perl overrides all those nice libc functions
36
37 #undef malloc
38 #undef free
40# undef open 39 #undef open
41# undef read 40 #undef read
42# undef write 41 #undef write
43# undef send 42 #undef send
44# undef recv 43 #undef recv
44 #undef stat
45# undef lstat 45 #undef lstat
46 #undef fstat
46# undef truncate 47 #undef truncate
47# undef ftruncate 48 #undef ftruncate
48# undef open 49 #undef open
49# undef link 50 #undef link
50# undef close 51 #undef close
51# undef unlink 52 #undef unlink
52# undef mkdir 53 #undef mkdir
53# undef rmdir 54 #undef rmdir
54# undef rename 55 #undef rename
55# undef lseek 56 #undef lseek
56# undef opendir 57 #undef opendir
57# undef readdir 58 #undef readdir
58# undef closedir 59 #undef closedir
59# undef chmod 60 #undef chmod
60# undef fchmod 61 #undef fchmod
61 62 #undef dup
62# define opendir(fd) EIO_ERRNO (ENOSYS, 0) 63 #undef dup2
63# define readdir(fd) EIO_ENOSYS () 64 #undef abort
64# define closedir(fd) EIO_ENOSYS () 65 #undef pipe
65 66
66#else 67#else
67 68
68# include <sys/time.h> 69 #include <sys/time.h>
69# include <sys/select.h> 70 #include <sys/select.h>
70# include <unistd.h> 71 #include <unistd.h>
71# include <utime.h> 72 #include <utime.h>
72# include <signal.h> 73 #include <signal.h>
73 74
74#endif 75#endif
75 76
76#define EIO_STRUCT_STAT Stat_t 77#define EIO_STRUCT_STAT Stat_t
77 78
114#define EIO_NO_WRAPPERS 1 115#define EIO_NO_WRAPPERS 1
115 116
116#include "libeio/config.h" 117#include "libeio/config.h"
117#include "libeio/eio.h" 118#include "libeio/eio.h"
118 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
119/* Linux/others */ 127/* Linux/others */
120#ifndef O_ASYNC 128#ifndef O_ASYNC
121# define O_ASYNC 0 129# define O_ASYNC 0
122#endif 130#endif
123#ifndef O_DIRECT 131#ifndef O_DIRECT
315 323
316#ifndef PAGESIZE 324#ifndef PAGESIZE
317# define PAGESIZE sysconf (_SC_PAGESIZE) 325# define PAGESIZE sysconf (_SC_PAGESIZE)
318#endif 326#endif
319 327
320static int req_invoke (eio_req *req);
321#define EIO_FINISH(req) req_invoke (req)
322static void req_destroy (eio_req *grp);
323#define EIO_DESTROY(req) req_destroy (req)
324
325enum { 328enum {
326 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ 329 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */
327}; 330};
328
329#include "libeio/eio.c"
330 331
331typedef eio_req *aio_req; 332typedef eio_req *aio_req;
332typedef eio_req *aio_req_ornot; 333typedef eio_req *aio_req_ornot;
333 334
334static SV *on_next_submit; 335static SV *on_next_submit;
596 case EIO_STAT: 597 case EIO_STAT:
597 case EIO_LSTAT: 598 case EIO_LSTAT:
598 case EIO_FSTAT: 599 case EIO_FSTAT:
599 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; 600 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT;
600 PL_laststatval = req->result; 601 PL_laststatval = req->result;
602 /* if compilation fails here then perl's Stat_t is not struct _stati64 */
601 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); 603 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2);
602 PUSHs (sv_result); 604 PUSHs (sv_result);
603 break; 605 break;
604 606
605 case EIO_READ: 607 case EIO_READ:
657 Safefree (req); 659 Safefree (req);
658} 660}
659 661
660static void req_cancel_subs (aio_req grp) 662static void req_cancel_subs (aio_req grp)
661{ 663{
662 aio_req sub;
663
664 if (grp->type != EIO_GROUP) 664 if (grp->type != EIO_GROUP)
665 return; 665 return;
666 666
667 SvREFCNT_dec (grp->sv2); 667 SvREFCNT_dec (grp->sv2);
668 grp->sv2 = 0; 668 grp->sv2 = 0;
709 709
710 poll_wait (); 710 poll_wait ();
711 } 711 }
712} 712}
713 713
714static void atfork_child (void) 714static void ecb_cold
715reinit (void)
715{ 716{
716 create_respipe (); 717 create_respipe ();
718
719 if (eio_init (want_poll, done_poll) < 0)
720 croak ("IO::AIO: unable to initialise eio library");
717} 721}
718 722
719/*****************************************************************************/ 723/*****************************************************************************/
720 724
721#if !_POSIX_MAPPED_FILES 725#if !_POSIX_MAPPED_FILES
919 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; )
920 newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); 924 newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv));
921 925
922 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); 926 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE));
923 927
924 create_respipe (); 928 reinit ();
925
926 if (eio_init (want_poll, done_poll) < 0)
927 croak ("IO::AIO: unable to initialise eio library");
928
929 /* atfork child called in fifo order, so before eio's handler */
930 X_THREAD_ATFORK (0, 0, atfork_child);
931} 929}
930
931void
932reinit ()
933 PROTOTYPE:
934 CODE:
935 reinit ();
932 936
933void 937void
934max_poll_reqs (unsigned int nreqs) 938max_poll_reqs (unsigned int nreqs)
935 PROTOTYPE: $ 939 PROTOTYPE: $
936 CODE: 940 CODE:
990void 994void
991aio_fsync (SV *fh, SV *callback=&PL_sv_undef) 995aio_fsync (SV *fh, SV *callback=&PL_sv_undef)
992 ALIAS: 996 ALIAS:
993 aio_fsync = EIO_FSYNC 997 aio_fsync = EIO_FSYNC
994 aio_fdatasync = EIO_FDATASYNC 998 aio_fdatasync = EIO_FDATASYNC
999 aio_syncfs = EIO_SYNCFS
995 PPCODE: 1000 PPCODE:
996{ 1001{
997 int fd = s_fileno_croak (fh, 0); 1002 int fd = s_fileno_croak (fh, 0);
998 dREQ; 1003 dREQ;
999 1004
1046 int fd = s_fileno_croak (fh, 0); 1051 int fd = s_fileno_croak (fh, 0);
1047 dREQ; 1052 dREQ;
1048 1053
1049 if (expect_false (close_fd < 0)) 1054 if (expect_false (close_fd < 0))
1050 { 1055 {
1056 int pipefd [2];
1057
1058 if (
1051#ifdef _WIN32 1059#ifdef _WIN32
1052 close_fd = _open_osfhandle (socket (AF_INET, SOCK_STREAM, 0), 0); 1060 _pipe (pipefd, 1, _O_BINARY) < 0
1053#else 1061#else
1054 int pipefd [2];
1055
1056 if (pipe (pipefd) < 0 1062 pipe (pipefd) < 0
1057 || close (pipefd [1]) < 0
1058 || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) 1063 || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0
1064#endif
1065 || close (pipefd [1]) < 0
1066 )
1059 abort (); /*D*/ 1067 abort (); /*D*/
1060 1068
1061 close_fd = pipefd [0]; 1069 close_fd = pipefd [0];
1062#endif
1063 } 1070 }
1064 1071
1065 req->type = EIO_DUP2; 1072 req->type = EIO_DUP2;
1066 req->int1 = close_fd; 1073 req->int1 = close_fd;
1067 req->sv2 = newSVsv (fh); 1074 req->sv2 = newSVsv (fh);
1128 ALIAS: 1135 ALIAS:
1129 aio_readlink = EIO_READLINK 1136 aio_readlink = EIO_READLINK
1130 aio_realpath = EIO_REALPATH 1137 aio_realpath = EIO_REALPATH
1131 PPCODE: 1138 PPCODE:
1132{ 1139{
1133 SV *data;
1134 dREQ; 1140 dREQ;
1135 1141
1136 req->type = ix; 1142 req->type = ix;
1137 req->sv1 = newSVsv (path); 1143 req->sv1 = newSVsv (path);
1138 req->ptr1 = SvPVbyte_nolen (req->sv1); 1144 req->ptr1 = SvPVbyte_nolen (req->sv1);
1585 CODE: 1591 CODE:
1586 RETVAL = posix_fadvise (fh, offset, length, advice); 1592 RETVAL = posix_fadvise (fh, offset, length, advice);
1587 OUTPUT: 1593 OUTPUT:
1588 RETVAL 1594 RETVAL
1589 1595
1590ssize_t 1596IV
1591sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) 1597sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count)
1592 CODE: 1598 CODE:
1593 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); 1599 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count);
1594 OUTPUT: 1600 OUTPUT:
1595 RETVAL 1601 RETVAL

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines