… | |
… | |
8 | #include <errno.h> |
8 | #include <errno.h> |
9 | #include <sys/types.h> |
9 | #include <sys/types.h> |
10 | #include <sys/stat.h> |
10 | #include <sys/stat.h> |
11 | #include <limits.h> |
11 | #include <limits.h> |
12 | #include <fcntl.h> |
12 | #include <fcntl.h> |
13 | #include <sched.h> |
13 | #include <assert.h> |
14 | |
14 | |
15 | #ifndef EIO_FINISH |
15 | #ifndef EIO_FINISH |
16 | # define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0 |
16 | # define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0 |
17 | #endif |
17 | #endif |
18 | |
18 | |
… | |
… | |
41 | # ifndef EIO_STRUCT_DIRENT |
41 | # ifndef EIO_STRUCT_DIRENT |
42 | # define EIO_STRUCT_DIRENT struct dirent |
42 | # define EIO_STRUCT_DIRENT struct dirent |
43 | # endif |
43 | # endif |
44 | |
44 | |
45 | #endif |
45 | #endif |
46 | |
|
|
47 | # ifndef EIO_STRUCT_STAT |
|
|
48 | # define EIO_STRUCT_STAT struct stat |
|
|
49 | # endif |
|
|
50 | |
46 | |
51 | #if HAVE_SENDFILE |
47 | #if HAVE_SENDFILE |
52 | # if __linux |
48 | # if __linux |
53 | # include <sys/sendfile.h> |
49 | # include <sys/sendfile.h> |
54 | # elif __freebsd |
50 | # elif __freebsd |
… | |
… | |
77 | #define dBUF \ |
73 | #define dBUF \ |
78 | char *eio_buf; \ |
74 | char *eio_buf; \ |
79 | X_LOCK (wrklock); \ |
75 | X_LOCK (wrklock); \ |
80 | self->dbuf = eio_buf = malloc (EIO_BUFSIZE); \ |
76 | self->dbuf = eio_buf = malloc (EIO_BUFSIZE); \ |
81 | X_UNLOCK (wrklock); \ |
77 | X_UNLOCK (wrklock); \ |
|
|
78 | errno = ENOMEM; \ |
82 | if (!eio_buf) \ |
79 | if (!eio_buf) \ |
83 | return -1; |
80 | return -1; |
84 | |
81 | |
85 | #define EIO_TICKS ((1000000 + 1023) >> 10) |
82 | #define EIO_TICKS ((1000000 + 1023) >> 10) |
86 | |
83 | |
… | |
… | |
95 | { |
92 | { |
96 | return (tv2->tv_sec - tv1->tv_sec ) * EIO_TICKS |
93 | return (tv2->tv_sec - tv1->tv_sec ) * EIO_TICKS |
97 | + ((tv2->tv_usec - tv1->tv_usec) >> 10); |
94 | + ((tv2->tv_usec - tv1->tv_usec) >> 10); |
98 | } |
95 | } |
99 | |
96 | |
100 | static unsigned int started, idle, wanted; |
97 | static unsigned int started, idle, wanted = 4; |
101 | |
98 | |
102 | /* worker threads management */ |
99 | /* worker threads management */ |
103 | static mutex_t wrklock = X_MUTEX_INIT; |
100 | static mutex_t wrklock = X_MUTEX_INIT; |
104 | |
101 | |
105 | typedef struct worker { |
102 | typedef struct worker |
|
|
103 | { |
106 | /* locked by wrklock */ |
104 | /* locked by wrklock */ |
107 | struct worker *prev, *next; |
105 | struct worker *prev, *next; |
108 | |
106 | |
109 | thread_t tid; |
107 | thread_t tid; |
110 | |
108 | |
… | |
… | |
325 | |
323 | |
326 | static void start_thread (void) |
324 | static void start_thread (void) |
327 | { |
325 | { |
328 | worker *wrk = calloc (1, sizeof (worker)); |
326 | worker *wrk = calloc (1, sizeof (worker)); |
329 | |
327 | |
330 | if (!wrk) |
328 | /*TODO*/ |
331 | croak ("unable to allocate worker thread data"); |
329 | assert (("unable to allocate worker thread data", wrk)); |
332 | |
330 | |
333 | X_LOCK (wrklock); |
331 | X_LOCK (wrklock); |
334 | |
332 | |
335 | if (thread_create (&wrk->tid, eio_proc, (void *)wrk)) |
333 | if (thread_create (&wrk->tid, eio_proc, (void *)wrk)) |
336 | { |
334 | { |
… | |
… | |
358 | start_thread (); |
356 | start_thread (); |
359 | } |
357 | } |
360 | |
358 | |
361 | void eio_submit (eio_req *req) |
359 | void eio_submit (eio_req *req) |
362 | { |
360 | { |
|
|
361 | req->pri += EIO_PRI_BIAS; |
|
|
362 | |
|
|
363 | if (req->pri < EIO_PRI_MIN + EIO_PRI_BIAS) req->pri = EIO_PRI_MIN + EIO_PRI_BIAS; |
|
|
364 | if (req->pri > EIO_PRI_MAX + EIO_PRI_BIAS) req->pri = EIO_PRI_MAX + EIO_PRI_BIAS; |
|
|
365 | |
363 | ++nreqs; |
366 | ++nreqs; |
364 | |
367 | |
365 | X_LOCK (reqlock); |
368 | X_LOCK (reqlock); |
366 | ++nready; |
369 | ++nready; |
367 | reqq_push (&req_queue, req); |
370 | reqq_push (&req_queue, req); |
… | |
… | |
485 | |
488 | |
486 | /*****************************************************************************/ |
489 | /*****************************************************************************/ |
487 | /* work around various missing functions */ |
490 | /* work around various missing functions */ |
488 | |
491 | |
489 | #if !HAVE_PREADWRITE |
492 | #if !HAVE_PREADWRITE |
490 | # define pread aio_pread |
493 | # define pread eio__pread |
491 | # define pwrite aio_pwrite |
494 | # define pwrite eio__pwrite |
492 | |
495 | |
493 | /* |
496 | /* |
494 | * make our pread/pwrite safe against themselves, but not against |
497 | * make our pread/pwrite safe against themselves, but not against |
495 | * normal read/write by using a mutex. slows down execution a lot, |
498 | * normal read/write by using a mutex. slows down execution a lot, |
496 | * but that's your problem, not mine. |
499 | * but that's your problem, not mine. |
497 | */ |
500 | */ |
498 | static mutex_t preadwritelock = X_MUTEX_INIT; |
501 | static mutex_t preadwritelock = X_MUTEX_INIT; |
499 | |
502 | |
500 | static ssize_t pread (int fd, void *buf, size_t count, off_t offset) |
503 | static ssize_t |
|
|
504 | eio__pread (int fd, void *buf, size_t count, off_t offset) |
501 | { |
505 | { |
502 | ssize_t res; |
506 | ssize_t res; |
503 | off_t ooffset; |
507 | off_t ooffset; |
504 | |
508 | |
505 | X_LOCK (preadwritelock); |
509 | X_LOCK (preadwritelock); |
… | |
… | |
510 | X_UNLOCK (preadwritelock); |
514 | X_UNLOCK (preadwritelock); |
511 | |
515 | |
512 | return res; |
516 | return res; |
513 | } |
517 | } |
514 | |
518 | |
515 | static ssize_t pwrite (int fd, void *buf, size_t count, off_t offset) |
519 | static ssize_t |
|
|
520 | eio__pwrite (int fd, void *buf, size_t count, off_t offset) |
516 | { |
521 | { |
517 | ssize_t res; |
522 | ssize_t res; |
518 | off_t ooffset; |
523 | off_t ooffset; |
519 | |
524 | |
520 | X_LOCK (preadwritelock); |
525 | X_LOCK (preadwritelock); |
… | |
… | |
528 | } |
533 | } |
529 | #endif |
534 | #endif |
530 | |
535 | |
531 | #ifndef HAVE_FUTIMES |
536 | #ifndef HAVE_FUTIMES |
532 | |
537 | |
533 | # define utimes(path,times) aio_utimes (path, times) |
538 | # define utimes(path,times) eio__utimes (path, times) |
534 | # define futimes(fd,times) aio_futimes (fd, times) |
539 | # define futimes(fd,times) eio__futimes (fd, times) |
535 | |
540 | |
|
|
541 | static int |
536 | static int aio_utimes (const char *filename, const struct timeval times[2]) |
542 | eio__utimes (const char *filename, const struct timeval times[2]) |
537 | { |
543 | { |
538 | if (times) |
544 | if (times) |
539 | { |
545 | { |
540 | struct utimbuf buf; |
546 | struct utimbuf buf; |
541 | |
547 | |
… | |
… | |
546 | } |
552 | } |
547 | else |
553 | else |
548 | return utime (filename, 0); |
554 | return utime (filename, 0); |
549 | } |
555 | } |
550 | |
556 | |
551 | static int aio_futimes (int fd, const struct timeval tv[2]) |
557 | static int eio__futimes (int fd, const struct timeval tv[2]) |
552 | { |
558 | { |
553 | errno = ENOSYS; |
559 | errno = ENOSYS; |
554 | return -1; |
560 | return -1; |
555 | } |
561 | } |
556 | |
562 | |
… | |
… | |
559 | #if !HAVE_FDATASYNC |
565 | #if !HAVE_FDATASYNC |
560 | # define fdatasync fsync |
566 | # define fdatasync fsync |
561 | #endif |
567 | #endif |
562 | |
568 | |
563 | #if !HAVE_READAHEAD |
569 | #if !HAVE_READAHEAD |
564 | # define readahead(fd,offset,count) aio_readahead (fd, offset, count, self) |
570 | # define readahead(fd,offset,count) eio__readahead (fd, offset, count, self) |
565 | |
571 | |
|
|
572 | static ssize_t |
566 | static ssize_t aio_readahead (int fd, off_t offset, size_t count, worker *self) |
573 | eio__readahead (int fd, off_t offset, size_t count, worker *self) |
567 | { |
574 | { |
568 | size_t todo = count; |
575 | size_t todo = count; |
569 | dBUF; |
576 | dBUF; |
570 | |
577 | |
571 | while (todo > 0) |
578 | while (todo > 0) |
… | |
… | |
582 | } |
589 | } |
583 | |
590 | |
584 | #endif |
591 | #endif |
585 | |
592 | |
586 | #if !HAVE_READDIR_R |
593 | #if !HAVE_READDIR_R |
587 | # define readdir_r aio_readdir_r |
594 | # define readdir_r eio__readdir_r |
588 | |
595 | |
589 | static mutex_t readdirlock = X_MUTEX_INIT; |
596 | static mutex_t readdirlock = X_MUTEX_INIT; |
590 | |
597 | |
|
|
598 | static int |
591 | static int readdir_r (DIR *dirp, EIO_STRUCT_DIRENT *ent, EIO_STRUCT_DIRENT **res) |
599 | eio__readdir_r (DIR *dirp, EIO_STRUCT_DIRENT *ent, EIO_STRUCT_DIRENT **res) |
592 | { |
600 | { |
593 | EIO_STRUCT_DIRENT *e; |
601 | EIO_STRUCT_DIRENT *e; |
594 | int errorno; |
602 | int errorno; |
595 | |
603 | |
596 | X_LOCK (readdirlock); |
604 | X_LOCK (readdirlock); |
… | |
… | |
612 | return e ? 0 : -1; |
620 | return e ? 0 : -1; |
613 | } |
621 | } |
614 | #endif |
622 | #endif |
615 | |
623 | |
616 | /* sendfile always needs emulation */ |
624 | /* sendfile always needs emulation */ |
|
|
625 | static ssize_t |
617 | static ssize_t sendfile_ (int ofd, int ifd, off_t offset, size_t count, worker *self) |
626 | eio__sendfile (int ofd, int ifd, off_t offset, size_t count, worker *self) |
618 | { |
627 | { |
619 | ssize_t res; |
628 | ssize_t res; |
620 | |
629 | |
621 | if (!count) |
630 | if (!count) |
622 | return 0; |
631 | return 0; |
… | |
… | |
705 | |
714 | |
706 | return res; |
715 | return res; |
707 | } |
716 | } |
708 | |
717 | |
709 | /* read a full directory */ |
718 | /* read a full directory */ |
|
|
719 | static void |
710 | static void scandir_ (eio_req *req, worker *self) |
720 | eio__scandir (eio_req *req, worker *self) |
711 | { |
721 | { |
712 | DIR *dirp; |
722 | DIR *dirp; |
713 | union |
723 | union |
714 | { |
724 | { |
715 | EIO_STRUCT_DIRENT d; |
725 | EIO_STRUCT_DIRENT d; |
… | |
… | |
768 | } |
778 | } |
769 | |
779 | |
770 | /*****************************************************************************/ |
780 | /*****************************************************************************/ |
771 | |
781 | |
772 | #define ALLOC(len) \ |
782 | #define ALLOC(len) \ |
773 | X_LOCK (wrklock); \ |
|
|
774 | req->flags |= EIO_FLAG_PTR2_FREE; \ |
|
|
775 | X_UNLOCK (wrklock); \ |
|
|
776 | req->ptr2 = malloc (len); \ |
|
|
777 | if (!req->ptr2) \ |
783 | if (!req->ptr2) \ |
778 | { \ |
784 | { \ |
|
|
785 | X_LOCK (wrklock); \ |
|
|
786 | req->flags |= EIO_FLAG_PTR2_FREE; \ |
|
|
787 | X_UNLOCK (wrklock); \ |
|
|
788 | req->ptr2 = malloc (len); \ |
|
|
789 | if (!req->ptr2) \ |
|
|
790 | { \ |
779 | errno = ENOMEM; \ |
791 | errno = ENOMEM; \ |
780 | req->result = -1; \ |
792 | req->result = -1; \ |
781 | break; \ |
793 | break; \ |
|
|
794 | } \ |
782 | } |
795 | } |
783 | |
796 | |
784 | X_THREAD_PROC (eio_proc) |
797 | X_THREAD_PROC (eio_proc) |
785 | { |
798 | { |
786 | eio_req *req; |
799 | eio_req *req; |
… | |
… | |
832 | errno = 0; /* strictly unnecessary */ |
845 | errno = 0; /* strictly unnecessary */ |
833 | |
846 | |
834 | if (!EIO_CANCELLED (req)) |
847 | if (!EIO_CANCELLED (req)) |
835 | switch (req->type) |
848 | switch (req->type) |
836 | { |
849 | { |
|
|
850 | case EIO_READ: ALLOC (req->size); |
837 | case EIO_READ: req->result = req->offs >= 0 |
851 | req->result = req->offs >= 0 |
838 | ? pread (req->int1, req->ptr2, req->size, req->offs) |
852 | ? pread (req->int1, req->ptr2, req->size, req->offs) |
839 | : read (req->int1, req->ptr2, req->size); break; |
853 | : read (req->int1, req->ptr2, req->size); break; |
840 | case EIO_WRITE: req->result = req->offs >= 0 |
854 | case EIO_WRITE: req->result = req->offs >= 0 |
841 | ? pwrite (req->int1, req->ptr2, req->size, req->offs) |
855 | ? pwrite (req->int1, req->ptr2, req->size, req->offs) |
842 | : write (req->int1, req->ptr2, req->size); break; |
856 | : write (req->int1, req->ptr2, req->size); break; |
843 | |
857 | |
844 | case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break; |
858 | case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break; |
845 | case EIO_SENDFILE: req->result = sendfile_ (req->int1, req->int2, req->offs, req->size, self); break; |
859 | case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size, self); break; |
846 | |
860 | |
847 | case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
861 | case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
848 | req->result = stat (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break; |
862 | req->result = stat (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break; |
849 | case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
863 | case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
850 | req->result = lstat (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break; |
864 | req->result = lstat (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break; |
… | |
… | |
866 | case EIO_MKDIR: req->result = mkdir (req->ptr1, (mode_t)req->int2); break; |
880 | case EIO_MKDIR: req->result = mkdir (req->ptr1, (mode_t)req->int2); break; |
867 | case EIO_RENAME: req->result = rename (req->ptr1, req->ptr2); break; |
881 | case EIO_RENAME: req->result = rename (req->ptr1, req->ptr2); break; |
868 | case EIO_LINK: req->result = link (req->ptr1, req->ptr2); break; |
882 | case EIO_LINK: req->result = link (req->ptr1, req->ptr2); break; |
869 | case EIO_SYMLINK: req->result = symlink (req->ptr1, req->ptr2); break; |
883 | case EIO_SYMLINK: req->result = symlink (req->ptr1, req->ptr2); break; |
870 | case EIO_MKNOD: req->result = mknod (req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; |
884 | case EIO_MKNOD: req->result = mknod (req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; |
|
|
885 | |
871 | case EIO_READLINK: ALLOC (NAME_MAX); |
886 | case EIO_READLINK: ALLOC (NAME_MAX); |
872 | req->result = readlink (req->ptr1, req->ptr2, NAME_MAX); break; |
887 | req->result = readlink (req->ptr1, req->ptr2, NAME_MAX); break; |
873 | |
888 | |
874 | case EIO_SYNC: req->result = 0; sync (); break; |
889 | case EIO_SYNC: req->result = 0; sync (); break; |
875 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
890 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
876 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
891 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
877 | |
892 | |
878 | case EIO_READDIR: scandir_ (req, self); break; |
893 | case EIO_READDIR: eio__scandir (req, self); break; |
879 | |
894 | |
880 | case EIO_BUSY: |
895 | case EIO_BUSY: |
881 | #ifdef _WIN32 |
896 | #ifdef _WIN32 |
882 | Sleep (req->nv1 * 1000.); |
897 | Sleep (req->nv1 * 1000.); |
883 | #else |
898 | #else |
… | |
… | |
916 | : utimes (req->ptr1, times); |
931 | : utimes (req->ptr1, times); |
917 | } |
932 | } |
918 | |
933 | |
919 | case EIO_GROUP: |
934 | case EIO_GROUP: |
920 | case EIO_NOP: |
935 | case EIO_NOP: |
|
|
936 | req->result = 0; |
921 | break; |
937 | break; |
922 | |
938 | |
923 | case EIO_QUIT: |
939 | case EIO_QUIT: |
924 | goto quit; |
940 | goto quit; |
925 | |
941 | |
… | |
… | |
1038 | \ |
1054 | \ |
1039 | req = (eio_req *)calloc (1, sizeof *req); \ |
1055 | req = (eio_req *)calloc (1, sizeof *req); \ |
1040 | if (!req) \ |
1056 | if (!req) \ |
1041 | return 0; \ |
1057 | return 0; \ |
1042 | \ |
1058 | \ |
1043 | req->type = EIO_ ## rtype; \ |
1059 | req->type = rtype; \ |
1044 | req->pri = EIO_DEFAULT_PRI + EIO_PRI_BIAS; \ |
1060 | req->pri = pri; \ |
1045 | req->finish = cb; \ |
1061 | req->finish = cb; \ |
|
|
1062 | req->data = data; \ |
1046 | req->destroy = eio_api_destroy; |
1063 | req->destroy = eio_api_destroy; |
1047 | |
1064 | |
1048 | #define SEND eio_submit (req); return req |
1065 | #define SEND eio_submit (req); return req |
1049 | |
1066 | |
1050 | #define PATH (void)0 |
1067 | #define PATH \ |
|
|
1068 | req->flags |= EIO_FLAG_PTR1_FREE; \ |
|
|
1069 | req->ptr1 = strdup (path); \ |
|
|
1070 | if (!req->ptr1) \ |
|
|
1071 | { \ |
|
|
1072 | eio_api_destroy (req); \ |
|
|
1073 | return 0; \ |
|
|
1074 | } |
1051 | |
1075 | |
|
|
1076 | eio_req *eio_nop (int pri, eio_cb cb, void *data) |
|
|
1077 | { |
|
|
1078 | REQ (EIO_NOP); SEND; |
|
|
1079 | } |
|
|
1080 | |
|
|
1081 | eio_req *eio_busy (double delay, int pri, eio_cb cb, void *data) |
|
|
1082 | { |
|
|
1083 | REQ (EIO_BUSY); req->nv1 = delay; SEND; |
|
|
1084 | } |
|
|
1085 | |
1052 | eio_req *eio_fsync (int fd, eio_cb cb) |
1086 | eio_req *eio_sync (int pri, eio_cb cb, void *data) |
1053 | { |
1087 | { |
|
|
1088 | REQ (EIO_SYNC); SEND; |
|
|
1089 | } |
|
|
1090 | |
|
|
1091 | eio_req *eio_fsync (int fd, int pri, eio_cb cb, void *data) |
|
|
1092 | { |
1054 | REQ (FSYNC); req->int1 = fd; SEND; |
1093 | REQ (EIO_FSYNC); req->int1 = fd; SEND; |
1055 | } |
1094 | } |
1056 | |
1095 | |
1057 | eio_req *eio_fdatasync (int fd, eio_cb cb) |
1096 | eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data) |
1058 | { |
1097 | { |
1059 | REQ (FDATASYNC); req->int1 = fd; SEND; |
1098 | REQ (EIO_FDATASYNC); req->int1 = fd; SEND; |
1060 | } |
1099 | } |
1061 | |
1100 | |
|
|
1101 | eio_req *eio_close (int fd, int pri, eio_cb cb, void *data) |
|
|
1102 | { |
|
|
1103 | REQ (EIO_CLOSE); req->int1 = fd; SEND; |
|
|
1104 | } |
|
|
1105 | |
1062 | eio_req *eio_readahead (int fd, off_t offset, size_t length, eio_cb cb) |
1106 | eio_req *eio_readahead (int fd, off_t offset, size_t length, int pri, eio_cb cb, void *data) |
1063 | { |
1107 | { |
1064 | REQ (READAHEAD); req->int1 = fd; req->offs = offset; req->size = length; SEND; |
1108 | REQ (EIO_READAHEAD); req->int1 = fd; req->offs = offset; req->size = length; SEND; |
1065 | } |
1109 | } |
1066 | |
1110 | |
1067 | eio_req *eio_read (int fd, off_t offset, size_t length, void *data, eio_cb cb) |
1111 | eio_req *eio_read (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data) |
1068 | { |
1112 | { |
1069 | REQ (READ); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = data; SEND; |
1113 | REQ (EIO_READ); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = buf; SEND; |
1070 | } |
1114 | } |
1071 | |
1115 | |
1072 | eio_req *eio_write (int fd, off_t offset, size_t length, void *data, eio_cb cb) |
1116 | eio_req *eio_write (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data) |
1073 | { |
1117 | { |
1074 | REQ (WRITE); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = data; SEND; |
1118 | REQ (EIO_WRITE); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = buf; SEND; |
1075 | } |
1119 | } |
1076 | |
1120 | |
1077 | eio_req *eio_fstat (int fd, eio_cb cb) |
1121 | eio_req *eio_fstat (int fd, int pri, eio_cb cb, void *data) |
1078 | { |
1122 | { |
1079 | REQ (FSTAT); req->int1 = fd; SEND; |
1123 | REQ (EIO_FSTAT); req->int1 = fd; SEND; |
1080 | } |
1124 | } |
1081 | |
1125 | |
1082 | eio_req *eio_futime (int fd, double atime, double mtime, eio_cb cb) |
1126 | eio_req *eio_futime (int fd, double atime, double mtime, int pri, eio_cb cb, void *data) |
1083 | { |
1127 | { |
1084 | REQ (FUTIME); req->int1 = fd; req->nv1 = atime; req->nv2 = mtime; SEND; |
1128 | REQ (EIO_FUTIME); req->int1 = fd; req->nv1 = atime; req->nv2 = mtime; SEND; |
1085 | } |
1129 | } |
1086 | |
1130 | |
1087 | eio_req *eio_ftruncate (int fd, off_t offset, eio_cb cb) |
1131 | eio_req *eio_ftruncate (int fd, off_t offset, int pri, eio_cb cb, void *data) |
1088 | { |
1132 | { |
1089 | REQ (FTRUNCATE); req->int1 = fd; req->offs = offset; SEND; |
1133 | REQ (EIO_FTRUNCATE); req->int1 = fd; req->offs = offset; SEND; |
1090 | } |
1134 | } |
1091 | |
1135 | |
1092 | eio_req *eio_fchmod (int fd, mode_t mode, eio_cb cb) |
1136 | eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data) |
1093 | { |
1137 | { |
1094 | REQ (FCHMOD); req->int1 = fd; req->int2 = (long)mode; SEND; |
1138 | REQ (EIO_FCHMOD); req->int1 = fd; req->int2 = (long)mode; SEND; |
1095 | } |
1139 | } |
1096 | |
1140 | |
1097 | eio_req *eio_fchown (int fd, uid_t uid, gid_t gid, eio_cb cb) |
1141 | eio_req *eio_fchown (int fd, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) |
1098 | { |
1142 | { |
1099 | REQ (FCHOWN); req->int1 = fd; req->int2 = (long)uid; req->int3 = (long)gid; SEND; |
1143 | REQ (EIO_FCHOWN); req->int1 = fd; req->int2 = (long)uid; req->int3 = (long)gid; SEND; |
1100 | } |
1144 | } |
1101 | |
1145 | |
1102 | eio_req *eio_dup2 (int fd, int fd2, eio_cb cb) |
1146 | eio_req *eio_dup2 (int fd, int fd2, int pri, eio_cb cb, void *data) |
1103 | { |
1147 | { |
1104 | REQ (DUP2); req->int1 = fd; req->int2 = fd2; SEND; |
1148 | REQ (EIO_DUP2); req->int1 = fd; req->int2 = fd2; SEND; |
1105 | } |
1149 | } |
1106 | |
1150 | |
1107 | eio_req *eio_sendfile (int out_fd, int in_fd, off_t in_offset, size_t length, eio_cb cb) |
1151 | eio_req *eio_sendfile (int out_fd, int in_fd, off_t in_offset, size_t length, int pri, eio_cb cb, void *data) |
1108 | { |
1152 | { |
1109 | REQ (SENDFILE); req->int1 = out_fd; req->int2 = in_fd; req->offs = in_offset; req->size = length; SEND; |
1153 | REQ (EIO_SENDFILE); req->int1 = out_fd; req->int2 = in_fd; req->offs = in_offset; req->size = length; SEND; |
1110 | } |
1154 | } |
1111 | |
1155 | |
1112 | eio_req *eio_open (const char *path, int flags, mode_t mode, eio_cb cb) |
1156 | eio_req *eio_open (const char *path, int flags, mode_t mode, int pri, eio_cb cb, void *data) |
1113 | { |
1157 | { |
1114 | REQ (OPEN); PATH; req->int1 = flags; req->int2 = (long)mode; SEND; |
1158 | REQ (EIO_OPEN); PATH; req->int1 = flags; req->int2 = (long)mode; SEND; |
1115 | } |
1159 | } |
1116 | |
1160 | |
1117 | eio_req *eio_readlink (const char *path, eio_cb cb) |
|
|
1118 | { |
|
|
1119 | REQ (READLINK); PATH; SEND; |
|
|
1120 | } |
|
|
1121 | |
|
|
1122 | eio_req *eio_stat (const char *path, eio_cb cb) |
|
|
1123 | { |
|
|
1124 | REQ (STAT); PATH; SEND; |
|
|
1125 | } |
|
|
1126 | |
|
|
1127 | eio_req *eio_lstat (const char *path, eio_cb cb) |
|
|
1128 | { |
|
|
1129 | REQ (LSTAT); PATH; SEND; |
|
|
1130 | } |
|
|
1131 | |
|
|
1132 | eio_req *eio_utime (const char *path, double atime, double mtime, eio_cb cb) |
1161 | eio_req *eio_utime (const char *path, double atime, double mtime, int pri, eio_cb cb, void *data) |
1133 | { |
1162 | { |
1134 | REQ (UTIME); PATH; req->nv1 = atime; req->nv2 = mtime; SEND; |
1163 | REQ (EIO_UTIME); PATH; req->nv1 = atime; req->nv2 = mtime; SEND; |
1135 | } |
1164 | } |
1136 | |
1165 | |
1137 | eio_req *eio_truncate (const char *path, off_t offset, eio_cb cb) |
1166 | eio_req *eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data) |
1138 | { |
1167 | { |
1139 | REQ (TRUNCATE); PATH; req->offs = offset; SEND; |
1168 | REQ (EIO_TRUNCATE); PATH; req->offs = offset; SEND; |
1140 | } |
1169 | } |
1141 | |
1170 | |
1142 | eio_req *eio_chown (const char *path, uid_t uid, gid_t gid, eio_cb cb) |
1171 | eio_req *eio_chown (const char *path, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) |
1143 | { |
1172 | { |
1144 | REQ (CHOWN); PATH; req->int2 = (long)uid; req->int3 = (long)gid; SEND; |
1173 | REQ (EIO_CHOWN); PATH; req->int2 = (long)uid; req->int3 = (long)gid; SEND; |
1145 | } |
1174 | } |
1146 | |
1175 | |
1147 | eio_req *eio_chmod (const char *path, mode_t mode, eio_cb cb) |
1176 | eio_req *eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data) |
1148 | { |
1177 | { |
1149 | REQ (CHMOD); PATH; req->int2 = (long)mode; SEND; |
1178 | REQ (EIO_CHMOD); PATH; req->int2 = (long)mode; SEND; |
1150 | } |
1179 | } |
1151 | |
1180 | |
1152 | eio_req *eio_mkdir (const char *path, mode_t mode, eio_cb cb) |
1181 | eio_req *eio_mkdir (const char *path, mode_t mode, int pri, eio_cb cb, void *data) |
1153 | { |
1182 | { |
1154 | REQ (MKDIR); PATH; req->int2 = (long)mode; SEND; |
1183 | REQ (EIO_MKDIR); PATH; req->int2 = (long)mode; SEND; |
1155 | } |
1184 | } |
1156 | |
1185 | |
1157 | eio_req *eio_unlink (const char *path, eio_cb cb) |
1186 | static eio_req * |
|
|
1187 | eio__1path (int type, const char *path, int pri, eio_cb cb, void *data) |
1158 | { |
1188 | { |
1159 | REQ (UNLINK); PATH; SEND; |
|
|
1160 | } |
|
|
1161 | |
|
|
1162 | eio_req *eio_rmdir (const char *path, eio_cb cb) |
|
|
1163 | { |
|
|
1164 | REQ (RMDIR); PATH; SEND; |
1189 | REQ (type); PATH; SEND; |
1165 | } |
1190 | } |
1166 | |
1191 | |
|
|
1192 | eio_req *eio_readlink (const char *path, int pri, eio_cb cb, void *data) |
|
|
1193 | { |
|
|
1194 | return eio__1path (EIO_READLINK, path, pri, cb, data); |
|
|
1195 | } |
|
|
1196 | |
|
|
1197 | eio_req *eio_stat (const char *path, int pri, eio_cb cb, void *data) |
|
|
1198 | { |
|
|
1199 | return eio__1path (EIO_STAT, path, pri, cb, data); |
|
|
1200 | } |
|
|
1201 | |
|
|
1202 | eio_req *eio_lstat (const char *path, int pri, eio_cb cb, void *data) |
|
|
1203 | { |
|
|
1204 | return eio__1path (EIO_LSTAT, path, pri, cb, data); |
|
|
1205 | } |
|
|
1206 | |
|
|
1207 | eio_req *eio_unlink (const char *path, int pri, eio_cb cb, void *data) |
|
|
1208 | { |
|
|
1209 | return eio__1path (EIO_UNLINK, path, pri, cb, data); |
|
|
1210 | } |
|
|
1211 | |
|
|
1212 | eio_req *eio_rmdir (const char *path, int pri, eio_cb cb, void *data) |
|
|
1213 | { |
|
|
1214 | return eio__1path (EIO_RMDIR, path, pri, cb, data); |
|
|
1215 | } |
|
|
1216 | |
1167 | eio_req *eio_readdir (const char *path, eio_cb cb) |
1217 | eio_req *eio_readdir (const char *path, int pri, eio_cb cb, void *data) |
1168 | { |
1218 | { |
1169 | REQ (READDIR); PATH; SEND; |
1219 | return eio__1path (EIO_READDIR, path, pri, cb, data); |
1170 | } |
1220 | } |
1171 | |
1221 | |
1172 | eio_req *eio_mknod (const char *path, mode_t mode, dev_t dev, eio_cb cb) |
1222 | eio_req *eio_mknod (const char *path, mode_t mode, dev_t dev, int pri, eio_cb cb, void *data) |
1173 | { |
1223 | { |
1174 | REQ (MKNOD); PATH; req->int2 = (long)mode; req->int2 = (long)dev; SEND; |
1224 | REQ (EIO_MKNOD); PATH; req->int2 = (long)mode; req->int2 = (long)dev; SEND; |
1175 | } |
1225 | } |
1176 | |
1226 | |
1177 | eio_req *eio_busy (double delay, eio_cb cb) |
1227 | static eio_req * |
|
|
1228 | eio__2path (int type, const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
1178 | { |
1229 | { |
1179 | REQ (BUSY); req->nv1 = delay; SEND; |
1230 | REQ (type); PATH; |
1180 | } |
|
|
1181 | |
1231 | |
|
|
1232 | req->flags |= EIO_FLAG_PTR2_FREE; |
|
|
1233 | req->ptr2 = strdup (new_path); |
|
|
1234 | if (!req->ptr2) |
|
|
1235 | { |
|
|
1236 | eio_api_destroy (req); |
|
|
1237 | return 0; |
|
|
1238 | } |
|
|
1239 | |
|
|
1240 | SEND; |
|
|
1241 | } |
|
|
1242 | |
|
|
1243 | eio_req *eio_link (const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
|
|
1244 | { |
|
|
1245 | return eio__2path (EIO_LINK, path, new_path, pri, cb, data); |
|
|
1246 | } |
|
|
1247 | |
|
|
1248 | eio_req *eio_symlink (const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
|
|
1249 | { |
|
|
1250 | return eio__2path (EIO_SYMLINK, path, new_path, pri, cb, data); |
|
|
1251 | } |
|
|
1252 | |
|
|
1253 | eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
|
|
1254 | { |
|
|
1255 | return eio__2path (EIO_RENAME, path, new_path, pri, cb, data); |
|
|
1256 | } |
|
|
1257 | |
1182 | eio_req *eio_nop (eio_cb cb) |
1258 | eio_req *eio_grp (eio_cb cb, void *data) |
1183 | { |
1259 | { |
|
|
1260 | const int pri = EIO_PRI_MAX; |
|
|
1261 | |
1184 | REQ (NOP); SEND; |
1262 | REQ (EIO_GROUP); SEND; |
1185 | } |
1263 | } |
1186 | |
1264 | |
1187 | #undef REQ |
1265 | #undef REQ |
1188 | #undef PATH |
1266 | #undef PATH |
1189 | #undef SEND |
1267 | #undef SEND |
1190 | |
1268 | |
1191 | #if 0 |
1269 | /*****************************************************************************/ |
1192 | |
1270 | /* grp functions */ |
1193 | void |
|
|
1194 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
|
|
1195 | PROTOTYPE: $$$;$ |
|
|
1196 | PPCODE: |
|
|
1197 | { |
|
|
1198 | dREQ; |
|
|
1199 | |
|
|
1200 | req->type = EIO_OPEN; |
|
|
1201 | req->sv1 = newSVsv (pathname); |
|
|
1202 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1203 | req->int1 = flags; |
|
|
1204 | req->int2 = mode; |
|
|
1205 | |
|
|
1206 | EIO_SEND; |
|
|
1207 | } |
|
|
1208 | |
|
|
1209 | void |
|
|
1210 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
|
|
1211 | PROTOTYPE: $;$ |
|
|
1212 | ALIAS: |
|
|
1213 | aio_fsync = EIO_FSYNC |
|
|
1214 | aio_fdatasync = EIO_FDATASYNC |
|
|
1215 | PPCODE: |
|
|
1216 | { |
|
|
1217 | dREQ; |
|
|
1218 | |
|
|
1219 | req->type = ix; |
|
|
1220 | req->sv1 = newSVsv (fh); |
|
|
1221 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
|
|
1222 | |
|
|
1223 | EIO_SEND (req); |
|
|
1224 | } |
|
|
1225 | |
|
|
1226 | void |
|
|
1227 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
|
|
1228 | PROTOTYPE: $;$ |
|
|
1229 | PPCODE: |
|
|
1230 | { |
|
|
1231 | dREQ; |
|
|
1232 | |
|
|
1233 | req->type = EIO_CLOSE; |
|
|
1234 | req->sv1 = newSVsv (fh); |
|
|
1235 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
|
|
1236 | |
|
|
1237 | EIO_SEND (req); |
|
|
1238 | } |
|
|
1239 | |
|
|
1240 | void |
|
|
1241 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
|
|
1242 | ALIAS: |
|
|
1243 | aio_read = EIO_READ |
|
|
1244 | aio_write = EIO_WRITE |
|
|
1245 | PROTOTYPE: $$$$$;$ |
|
|
1246 | PPCODE: |
|
|
1247 | { |
|
|
1248 | STRLEN svlen; |
|
|
1249 | char *svptr = SvPVbyte (data, svlen); |
|
|
1250 | UV len = SvUV (length); |
|
|
1251 | |
|
|
1252 | SvUPGRADE (data, SVt_PV); |
|
|
1253 | SvPOK_on (data); |
|
|
1254 | |
|
|
1255 | if (dataoffset < 0) |
|
|
1256 | dataoffset += svlen; |
|
|
1257 | |
|
|
1258 | if (dataoffset < 0 || dataoffset > svlen) |
|
|
1259 | croak ("dataoffset outside of data scalar"); |
|
|
1260 | |
|
|
1261 | if (ix == EIO_WRITE) |
|
|
1262 | { |
|
|
1263 | /* write: check length and adjust. */ |
|
|
1264 | if (!SvOK (length) || len + dataoffset > svlen) |
|
|
1265 | len = svlen - dataoffset; |
|
|
1266 | } |
|
|
1267 | else |
|
|
1268 | { |
|
|
1269 | /* read: grow scalar as necessary */ |
|
|
1270 | svptr = SvGROW (data, len + dataoffset + 1); |
|
|
1271 | } |
|
|
1272 | |
|
|
1273 | if (len < 0) |
|
|
1274 | croak ("length must not be negative"); |
|
|
1275 | |
|
|
1276 | { |
|
|
1277 | dREQ; |
|
|
1278 | |
|
|
1279 | req->type = ix; |
|
|
1280 | req->sv1 = newSVsv (fh); |
|
|
1281 | req->int1 = PerlIO_fileno (ix == EIO_READ ? IoIFP (sv_2io (fh)) |
|
|
1282 | : IoOFP (sv_2io (fh))); |
|
|
1283 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
|
|
1284 | req->size = len; |
|
|
1285 | req->sv2 = SvREFCNT_inc (data); |
|
|
1286 | req->ptr2 = (char *)svptr + dataoffset; |
|
|
1287 | req->stroffset = dataoffset; |
|
|
1288 | |
|
|
1289 | if (!SvREADONLY (data)) |
|
|
1290 | { |
|
|
1291 | SvREADONLY_on (data); |
|
|
1292 | req->flags |= FLAG_SV2_RO_OFF; |
|
|
1293 | } |
|
|
1294 | |
|
|
1295 | EIO_SEND; |
|
|
1296 | } |
|
|
1297 | } |
|
|
1298 | |
|
|
1299 | void |
|
|
1300 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
|
|
1301 | PROTOTYPE: $$;$ |
|
|
1302 | PPCODE: |
|
|
1303 | { |
|
|
1304 | SV *data; |
|
|
1305 | dREQ; |
|
|
1306 | |
|
|
1307 | data = newSV (NAME_MAX); |
|
|
1308 | SvPOK_on (data); |
|
|
1309 | |
|
|
1310 | req->type = EIO_READLINK; |
|
|
1311 | req->sv1 = newSVsv (path); |
|
|
1312 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1313 | req->sv2 = data; |
|
|
1314 | req->ptr2 = SvPVbyte_nolen (data); |
|
|
1315 | |
|
|
1316 | EIO_SEND; |
|
|
1317 | } |
|
|
1318 | |
|
|
1319 | void |
|
|
1320 | aio_sendfile (SV *out_fh, SV *in_fh, SV *in_offset, UV length, SV *callback=&PL_sv_undef) |
|
|
1321 | PROTOTYPE: $$$$;$ |
|
|
1322 | PPCODE: |
|
|
1323 | { |
|
|
1324 | dREQ; |
|
|
1325 | |
|
|
1326 | req->type = EIO_SENDFILE; |
|
|
1327 | req->sv1 = newSVsv (out_fh); |
|
|
1328 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (out_fh))); |
|
|
1329 | req->sv2 = newSVsv (in_fh); |
|
|
1330 | req->int2 = PerlIO_fileno (IoIFP (sv_2io (in_fh))); |
|
|
1331 | req->offs = SvVAL64 (in_offset); |
|
|
1332 | req->size = length; |
|
|
1333 | |
|
|
1334 | EIO_SEND; |
|
|
1335 | } |
|
|
1336 | |
|
|
1337 | void |
|
|
1338 | aio_readahead (SV *fh, SV *offset, IV length, SV *callback=&PL_sv_undef) |
|
|
1339 | PROTOTYPE: $$$;$ |
|
|
1340 | PPCODE: |
|
|
1341 | { |
|
|
1342 | dREQ; |
|
|
1343 | |
|
|
1344 | req->type = EIO_READAHEAD; |
|
|
1345 | req->sv1 = newSVsv (fh); |
|
|
1346 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
|
|
1347 | req->offs = SvVAL64 (offset); |
|
|
1348 | req->size = length; |
|
|
1349 | |
|
|
1350 | EIO_SEND; |
|
|
1351 | } |
|
|
1352 | |
|
|
1353 | void |
|
|
1354 | aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) |
|
|
1355 | ALIAS: |
|
|
1356 | aio_stat = EIO_STAT |
|
|
1357 | aio_lstat = EIO_LSTAT |
|
|
1358 | PPCODE: |
|
|
1359 | { |
|
|
1360 | dREQ; |
|
|
1361 | |
|
|
1362 | req->ptr2 = malloc (sizeof (EIO_STRUCT_STAT)); |
|
|
1363 | if (!req->ptr2) |
|
|
1364 | { |
|
|
1365 | req_destroy (req); |
|
|
1366 | croak ("out of memory during aio_stat statdata allocation"); |
|
|
1367 | } |
|
|
1368 | |
|
|
1369 | req->flags |= FLAG_PTR2_FREE; |
|
|
1370 | req->sv1 = newSVsv (fh_or_path); |
|
|
1371 | |
|
|
1372 | if (SvPOK (fh_or_path)) |
|
|
1373 | { |
|
|
1374 | req->type = ix; |
|
|
1375 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1376 | } |
|
|
1377 | else |
|
|
1378 | { |
|
|
1379 | req->type = EIO_FSTAT; |
|
|
1380 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1381 | } |
|
|
1382 | |
|
|
1383 | EIO_SEND; |
|
|
1384 | } |
|
|
1385 | |
|
|
1386 | void |
|
|
1387 | aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
|
|
1388 | PPCODE: |
|
|
1389 | { |
|
|
1390 | dREQ; |
|
|
1391 | |
|
|
1392 | req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; |
|
|
1393 | req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; |
|
|
1394 | req->sv1 = newSVsv (fh_or_path); |
|
|
1395 | |
|
|
1396 | if (SvPOK (fh_or_path)) |
|
|
1397 | { |
|
|
1398 | req->type = EIO_UTIME; |
|
|
1399 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1400 | } |
|
|
1401 | else |
|
|
1402 | { |
|
|
1403 | req->type = EIO_FUTIME; |
|
|
1404 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1405 | } |
|
|
1406 | |
|
|
1407 | EIO_SEND; |
|
|
1408 | } |
|
|
1409 | |
|
|
1410 | void |
|
|
1411 | aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) |
|
|
1412 | PPCODE: |
|
|
1413 | { |
|
|
1414 | dREQ; |
|
|
1415 | |
|
|
1416 | req->sv1 = newSVsv (fh_or_path); |
|
|
1417 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
|
|
1418 | |
|
|
1419 | if (SvPOK (fh_or_path)) |
|
|
1420 | { |
|
|
1421 | req->type = EIO_TRUNCATE; |
|
|
1422 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1423 | } |
|
|
1424 | else |
|
|
1425 | { |
|
|
1426 | req->type = EIO_FTRUNCATE; |
|
|
1427 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1428 | } |
|
|
1429 | |
|
|
1430 | EIO_SEND; |
|
|
1431 | } |
|
|
1432 | |
|
|
1433 | void |
|
|
1434 | aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) |
|
|
1435 | ALIAS: |
|
|
1436 | aio_chmod = EIO_CHMOD |
|
|
1437 | aio_fchmod = EIO_FCHMOD |
|
|
1438 | aio_mkdir = EIO_MKDIR |
|
|
1439 | PPCODE: |
|
|
1440 | { |
|
|
1441 | dREQ; |
|
|
1442 | |
|
|
1443 | req->type = type; |
|
|
1444 | req->int2 = mode; |
|
|
1445 | req->sv1 = newSVsv (fh_or_path); |
|
|
1446 | |
|
|
1447 | if (ix == EIO_FCHMOD) |
|
|
1448 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1449 | else |
|
|
1450 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1451 | |
|
|
1452 | EIO_SEND; |
|
|
1453 | } |
|
|
1454 | |
|
|
1455 | void |
|
|
1456 | aio_chown (SV8 *fh_or_path, SV *uid, SV *gid, SV *callback=&PL_sv_undef) |
|
|
1457 | PPCODE: |
|
|
1458 | { |
|
|
1459 | dREQ; |
|
|
1460 | |
|
|
1461 | req->int2 = SvOK (uid) ? SvIV (uid) : -1; |
|
|
1462 | req->int3 = SvOK (gid) ? SvIV (gid) : -1; |
|
|
1463 | req->sv1 = newSVsv (fh_or_path); |
|
|
1464 | |
|
|
1465 | if (SvPOK (fh_or_path)) |
|
|
1466 | { |
|
|
1467 | req->type = EIO_CHOWN; |
|
|
1468 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1469 | } |
|
|
1470 | else |
|
|
1471 | { |
|
|
1472 | req->type = EIO_FCHOWN; |
|
|
1473 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1474 | } |
|
|
1475 | |
|
|
1476 | EIO_SEND; |
|
|
1477 | } |
|
|
1478 | |
|
|
1479 | void |
|
|
1480 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
|
|
1481 | ALIAS: |
|
|
1482 | aio_unlink = EIO_UNLINK |
|
|
1483 | aio_rmdir = EIO_RMDIR |
|
|
1484 | aio_readdir = EIO_READDIR |
|
|
1485 | PPCODE: |
|
|
1486 | { |
|
|
1487 | dREQ; |
|
|
1488 | |
|
|
1489 | req->type = ix; |
|
|
1490 | req->sv1 = newSVsv (pathname); |
|
|
1491 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1492 | |
|
|
1493 | EIO_SEND; |
|
|
1494 | } |
|
|
1495 | |
|
|
1496 | void |
|
|
1497 | aio_link (SV8 *oldpath, SV8 *newpath, SV *callback=&PL_sv_undef) |
|
|
1498 | ALIAS: |
|
|
1499 | aio_link = EIO_LINK |
|
|
1500 | aio_symlink = EIO_SYMLINK |
|
|
1501 | aio_rename = EIO_RENAME |
|
|
1502 | PPCODE: |
|
|
1503 | { |
|
|
1504 | dREQ; |
|
|
1505 | |
|
|
1506 | req->type = ix; |
|
|
1507 | req->sv1 = newSVsv (oldpath); |
|
|
1508 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1509 | req->sv2 = newSVsv (newpath); |
|
|
1510 | req->ptr2 = SvPVbyte_nolen (req->sv2); |
|
|
1511 | |
|
|
1512 | EIO_SEND; |
|
|
1513 | } |
|
|
1514 | |
|
|
1515 | void |
|
|
1516 | aio_mknod (SV8 *pathname, int mode, UV dev, SV *callback=&PL_sv_undef) |
|
|
1517 | PPCODE: |
|
|
1518 | { |
|
|
1519 | dREQ; |
|
|
1520 | |
|
|
1521 | req->type = EIO_MKNOD; |
|
|
1522 | req->sv1 = newSVsv (pathname); |
|
|
1523 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1524 | req->int2 = (mode_t)mode; |
|
|
1525 | req->offs = dev; |
|
|
1526 | |
|
|
1527 | EIO_SEND; |
|
|
1528 | } |
|
|
1529 | |
|
|
1530 | void |
|
|
1531 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
|
|
1532 | PPCODE: |
|
|
1533 | { |
|
|
1534 | dREQ; |
|
|
1535 | |
|
|
1536 | req->type = EIO_BUSY; |
|
|
1537 | req->nv1 = delay < 0. ? 0. : delay; |
|
|
1538 | |
|
|
1539 | EIO_SEND; |
|
|
1540 | } |
|
|
1541 | |
|
|
1542 | void |
|
|
1543 | aio_group (SV *callback=&PL_sv_undef) |
|
|
1544 | PROTOTYPE: ;$ |
|
|
1545 | PPCODE: |
|
|
1546 | { |
|
|
1547 | dREQ; |
|
|
1548 | |
|
|
1549 | req->type = EIO_GROUP; |
|
|
1550 | |
|
|
1551 | req_send (req); |
|
|
1552 | XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
|
|
1553 | } |
|
|
1554 | |
|
|
1555 | void |
|
|
1556 | aio_nop (SV *callback=&PL_sv_undef) |
|
|
1557 | ALIAS: |
|
|
1558 | aio_nop = EIO_NOP |
|
|
1559 | aio_sync = EIO_SYNC |
|
|
1560 | PPCODE: |
|
|
1561 | { |
|
|
1562 | dREQ; |
|
|
1563 | |
|
|
1564 | #endif |
|
|
1565 | |
1271 | |
1566 | void eio_grp_feed (eio_req *grp, void (*feed)(eio_req *req), int limit) |
1272 | void eio_grp_feed (eio_req *grp, void (*feed)(eio_req *req), int limit) |
1567 | { |
1273 | { |
1568 | grp->int2 = limit; |
1274 | grp->int2 = limit; |
1569 | grp->feed = feed; |
1275 | grp->feed = feed; |
… | |
… | |
1592 | grp->grp_first->grp_prev = req; |
1298 | grp->grp_first->grp_prev = req; |
1593 | |
1299 | |
1594 | grp->grp_first = req; |
1300 | grp->grp_first = req; |
1595 | } |
1301 | } |
1596 | |
1302 | |
|
|
1303 | /*****************************************************************************/ |
|
|
1304 | /* misc garbage */ |
1597 | |
1305 | |
|
|
1306 | ssize_t eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count) |
|
|
1307 | { |
|
|
1308 | worker wrk; |
|
|
1309 | |
|
|
1310 | wrk.dbuf = 0; |
|
|
1311 | |
|
|
1312 | eio__sendfile (ofd, ifd, offset, count, &wrk); |
|
|
1313 | |
|
|
1314 | if (wrk.dbuf) |
|
|
1315 | free (wrk.dbuf); |
|
|
1316 | } |
|
|
1317 | |