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.34 by root, Tue Aug 23 00:03:14 2005 UTC vs.
Revision 1.42 by root, Fri Jul 21 07:35:31 2006 UTC

7 7
8#include "autoconf/config.h" 8#include "autoconf/config.h"
9 9
10#include <pthread.h> 10#include <pthread.h>
11 11
12#include <stddef.h>
13#include <errno.h>
12#include <sys/types.h> 14#include <sys/types.h>
13#include <sys/stat.h> 15#include <sys/stat.h>
14 16#include <limits.h>
15#include <unistd.h> 17#include <unistd.h>
16#include <fcntl.h> 18#include <fcntl.h>
17#include <signal.h> 19#include <signal.h>
18#include <sched.h> 20#include <sched.h>
19 21
23# elif __freebsd 25# elif __freebsd
24# include <sys/socket.h> 26# include <sys/socket.h>
25# include <sys/uio.h> 27# include <sys/uio.h>
26# elif __hpux 28# elif __hpux
27# include <sys/socket.h> 29# include <sys/socket.h>
30# elif __solaris /* not yet */
31# include <sys/sendfile.h>
28# else 32# else
29# error sendfile support requested but not available 33# error sendfile support requested but not available
30# endif 34# endif
31#endif 35#endif
32 36
37/* used for struct dirent, AIX doesn't provide it */
38#ifndef NAME_MAX
39# define NAME_MAX 4096
40#endif
41
33#if __ia64 42#if __ia64
34# define STACKSIZE 65536 43# define STACKSIZE 65536
35#else 44#else
36# define STACKSIZE 4096 45# define STACKSIZE 8192
37#endif 46#endif
38 47
39enum { 48enum {
40 REQ_QUIT, 49 REQ_QUIT,
41 REQ_OPEN, REQ_CLOSE, 50 REQ_OPEN, REQ_CLOSE,
42 REQ_READ, REQ_WRITE, REQ_READAHEAD, 51 REQ_READ, REQ_WRITE, REQ_READAHEAD,
43 REQ_SENDFILE, 52 REQ_SENDFILE,
44 REQ_STAT, REQ_LSTAT, REQ_FSTAT, 53 REQ_STAT, REQ_LSTAT, REQ_FSTAT,
45 REQ_FSYNC, REQ_FDATASYNC, 54 REQ_FSYNC, REQ_FDATASYNC,
46 REQ_UNLINK, REQ_RMDIR, 55 REQ_UNLINK, REQ_RMDIR, REQ_RENAME,
47 REQ_SYMLINK, 56 REQ_READDIR,
57 REQ_LINK, REQ_SYMLINK,
48}; 58};
49 59
50typedef struct aio_cb { 60typedef struct aio_cb {
51 struct aio_cb *volatile next; 61 struct aio_cb *volatile next;
52 62
53 int type; 63 int type;
54 64
65 /* should receive a cleanup, with unions */
55 int fd, fd2; 66 int fd, fd2;
56 off_t offset; 67 off_t offset;
57 size_t length; 68 size_t length;
58 ssize_t result; 69 ssize_t result;
59 mode_t mode; /* open */ 70 mode_t mode; /* open */
95 Safefree (req->statdata); 106 Safefree (req->statdata);
96 107
97 if (req->callback) 108 if (req->callback)
98 SvREFCNT_dec (req->callback); 109 SvREFCNT_dec (req->callback);
99 110
111 if (req->type == REQ_READDIR && req->result >= 0)
112 free (req->data2ptr);
113
100 Safefree (req); 114 Safefree (req);
101} 115}
102 116
103static void 117static void
104poll_wait () 118poll_wait ()
168 PL_statcache = *(req->statdata); 182 PL_statcache = *(req->statdata);
169 } 183 }
170 184
171 ENTER; 185 ENTER;
172 PUSHMARK (SP); 186 PUSHMARK (SP);
173 XPUSHs (sv_2mortal (newSViv (req->result)));
174 187
175 if (req->type == REQ_OPEN) 188 if (req->type == REQ_READDIR)
176 { 189 {
190 SV *rv = &PL_sv_undef;
191
192 if (req->result >= 0)
193 {
194 char *buf = req->data2ptr;
195 AV *av = newAV ();
196
197 while (req->result)
198 {
199 SV *sv = newSVpv (buf, 0);
200
201 av_push (av, sv);
202 buf += SvCUR (sv) + 1;
203 req->result--;
204 }
205
206 rv = sv_2mortal (newRV_noinc ((SV *)av));
207 }
208
209 XPUSHs (rv);
210 }
211 else
212 {
213 XPUSHs (sv_2mortal (newSViv (req->result)));
214
215 if (req->type == REQ_OPEN)
216 {
177 /* convert fd to fh */ 217 /* convert fd to fh */
178 SV *fh; 218 SV *fh;
179 219
180 PUTBACK; 220 PUTBACK;
181 call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); 221 call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL);
182 SPAGAIN; 222 SPAGAIN;
183 223
184 fh = SvREFCNT_inc (POPs); 224 fh = SvREFCNT_inc (POPs);
185 225
186 PUSHMARK (SP); 226 PUSHMARK (SP);
187 XPUSHs (sv_2mortal (fh)); 227 XPUSHs (sv_2mortal (fh));
228 }
188 } 229 }
189 230
190 if (SvOK (req->callback)) 231 if (SvOK (req->callback))
191 { 232 {
192 PUTBACK; 233 PUTBACK;
315 356
316 if (fcntl (respipe [1], F_SETFL, O_NONBLOCK)) 357 if (fcntl (respipe [1], F_SETFL, O_NONBLOCK))
317 croak ("cannot set result pipe to nonblocking mode"); 358 croak ("cannot set result pipe to nonblocking mode");
318} 359}
319 360
320static void atfork_prepare (void)
321{
322 pthread_mutex_lock (&reqlock);
323 pthread_mutex_lock (&reslock);
324}
325
326static void atfork_parent (void)
327{
328 pthread_mutex_unlock (&reslock);
329 pthread_mutex_unlock (&reqlock);
330}
331
332static void atfork_child (void)
333{
334 aio_req prv;
335
336 started = 0;
337
338 while (reqs)
339 {
340 prv = reqs;
341 reqs = prv->next;
342 free_req (prv);
343 }
344
345 reqs = reqe = 0;
346
347 while (ress)
348 {
349 prv = ress;
350 ress = prv->next;
351 free_req (prv);
352 }
353
354 ress = rese = 0;
355
356 close (respipe [0]);
357 close (respipe [1]);
358 create_pipe ();
359
360 atfork_parent ();
361}
362
363/*****************************************************************************/ 361/*****************************************************************************/
364/* work around various missing functions */ 362/* work around various missing functions */
365 363
366#if !HAVE_PREADWRITE 364#if !HAVE_PREADWRITE
367# define pread aio_pread 365# define pread aio_pread
370/* 368/*
371 * make our pread/pwrite safe against themselves, but not against 369 * make our pread/pwrite safe against themselves, but not against
372 * normal read/write by using a mutex. slows down execution a lot, 370 * normal read/write by using a mutex. slows down execution a lot,
373 * but that's your problem, not mine. 371 * but that's your problem, not mine.
374 */ 372 */
375static pthread_mutex_t iolock = PTHREAD_MUTEX_INITIALIZER; 373static pthread_mutex_t preadwritelock = PTHREAD_MUTEX_INITIALIZER;
376 374
377static ssize_t 375static ssize_t
378pread (int fd, void *buf, size_t count, off_t offset) 376pread (int fd, void *buf, size_t count, off_t offset)
379{ 377{
380 ssize_t res; 378 ssize_t res;
381 off_t ooffset; 379 off_t ooffset;
382 380
383 pthread_mutex_lock (&iolock); 381 pthread_mutex_lock (&preadwritelock);
384 ooffset = lseek (fd, 0, SEEK_CUR); 382 ooffset = lseek (fd, 0, SEEK_CUR);
385 lseek (fd, offset, SEEK_SET); 383 lseek (fd, offset, SEEK_SET);
386 res = read (fd, buf, count); 384 res = read (fd, buf, count);
387 lseek (fd, ooffset, SEEK_SET); 385 lseek (fd, ooffset, SEEK_SET);
388 pthread_mutex_unlock (&iolock); 386 pthread_mutex_unlock (&preadwritelock);
389 387
390 return res; 388 return res;
391} 389}
392 390
393static ssize_t 391static ssize_t
394pwrite (int fd, void *buf, size_t count, off_t offset) 392pwrite (int fd, void *buf, size_t count, off_t offset)
395{ 393{
396 ssize_t res; 394 ssize_t res;
397 off_t ooffset; 395 off_t ooffset;
398 396
399 pthread_mutex_lock (&iolock); 397 pthread_mutex_lock (&preadwritelock);
400 ooffset = lseek (fd, 0, SEEK_CUR); 398 ooffset = lseek (fd, 0, SEEK_CUR);
401 lseek (fd, offset, SEEK_SET); 399 lseek (fd, offset, SEEK_SET);
402 res = write (fd, buf, count); 400 res = write (fd, buf, count);
403 lseek (fd, offset, SEEK_SET); 401 lseek (fd, offset, SEEK_SET);
404 pthread_mutex_unlock (&iolock); 402 pthread_mutex_unlock (&preadwritelock);
405 403
406 return res; 404 return res;
407} 405}
408#endif 406#endif
409 407
412#endif 410#endif
413 411
414#if !HAVE_READAHEAD 412#if !HAVE_READAHEAD
415# define readahead aio_readahead 413# define readahead aio_readahead
416 414
417static char readahead_buf[4096];
418
419static ssize_t 415static ssize_t
420readahead (int fd, off_t offset, size_t count) 416readahead (int fd, off_t offset, size_t count)
421{ 417{
418 char readahead_buf[4096];
419
422 while (count > 0) 420 while (count > 0)
423 { 421 {
424 size_t len = count < sizeof (readahead_buf) ? count : sizeof (readahead_buf); 422 size_t len = count < sizeof (readahead_buf) ? count : sizeof (readahead_buf);
425 423
426 pread (fd, readahead_buf, len, offset); 424 pread (fd, readahead_buf, len, offset);
430 428
431 errno = 0; 429 errno = 0;
432} 430}
433#endif 431#endif
434 432
433#if !HAVE_READDIR_R
434# define readdir_r aio_readdir_r
435
436static pthread_mutex_t readdirlock = PTHREAD_MUTEX_INITIALIZER;
437
438static int
439readdir_r (DIR *dirp, struct dirent *ent, struct dirent **res)
440{
441 struct dirent *e;
442 int errorno;
443
444 pthread_mutex_lock (&readdirlock);
445
446 e = readdir (dirp);
447 errorno = errno;
448
449 if (e)
450 {
451 *res = ent;
452 strcpy (ent->d_name, e->d_name);
453 }
454 else
455 *res = 0;
456
457 pthread_mutex_unlock (&readdirlock);
458
459 errno = errorno;
460 return e ? 0 : -1;
461}
462#endif
463
435/* sendfile always needs emulation */ 464/* sendfile always needs emulation */
436static ssize_t 465static ssize_t
437sendfile_ (int ofd, int ifd, off_t offset, size_t count) 466sendfile_ (int ofd, int ifd, off_t offset, size_t count)
438{ 467{
439 ssize_t res; 468 ssize_t res;
440 469
441 if (!count) 470 if (!count)
442 return 0; 471 return 0;
443 472
473#if HAVE_SENDFILE
444#if __linux 474# if __linux
445 res = sendfile (ofd, ifd, &offset, count); 475 res = sendfile (ofd, ifd, &offset, count);
446 476
447#elif __freebsd 477# elif __freebsd
448 /* 478 /*
449 * Of course, the freebsd sendfile is a dire hack with no thoughts 479 * Of course, the freebsd sendfile is a dire hack with no thoughts
450 * wasted on making it similar to other i/o functions. 480 * wasted on making it similar to other I/O functions.
451 */ 481 */
452 { 482 {
453 off_t sbytes; 483 off_t sbytes;
454 res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0); 484 res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0);
455 485
456 if (!res && errno == EAGAIN) 486 if (res < 0 && sbytes)
457 /* maybe on others, too, as usual, the manpage leaves you guessing */ 487 /* maybe only on EAGAIN only: as usual, the manpage leaves you guessing */
458 res = sbytes; 488 res = sbytes;
459 } 489 }
460 490
461#elif __hpux 491# elif __hpux
462 res = sendfile (ofd, ifd, offset, count, 0, 0); 492 res = sendfile (ofd, ifd, offset, count, 0, 0);
463 493
494# elif __solaris
495 {
496 struct sendfilevec vec;
497 size_t sbytes;
498
499 vec.sfv_fd = ifd;
500 vec.sfv_flag = 0;
501 vec.sfv_off = offset;
502 vec.sfv_len = count;
503
504 res = sendfilev (ofd, &vec, 1, &sbytes);
505
506 if (res < 0 && sbytes)
507 res = sbytes;
508 }
509
510# endif
464#else 511#else
465 res = -1; 512 res = -1;
466 errno = ENOSYS; 513 errno = ENOSYS;
467#endif 514#endif
468 515
516 if (res < 0
469 if (res < 0 && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK)) 517 && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK
518#if __solaris
519 || errno == EAFNOSUPPORT || errno == EPROTOTYPE
520#endif
521 )
522 )
470 { 523 {
471 /* emulate sendfile. this is a major pain in the ass */ 524 /* emulate sendfile. this is a major pain in the ass */
472 char *buf = malloc (4096); 525 char buf[4096];
473 res = 0; 526 res = 0;
474 527
475 for (;;) 528 while (count)
476 { 529 {
477 ssize_t cnt; 530 ssize_t cnt;
478 531
479 cnt = pread (ifd, buf, 4096, offset); 532 cnt = pread (ifd, buf, count > 4096 ? 4096 : count, offset);
480 533
481 if (cnt <= 0) 534 if (cnt <= 0)
482 { 535 {
483 if (cnt && !res) res = -1; 536 if (cnt && !res) res = -1;
484 break; 537 break;
485 } 538 }
486 539
487 cnt = write (ofd, buf, cnt); 540 cnt = write (ofd, buf, cnt);
488 541
489 if (cnt <= 0) 542 if (cnt <= 0)
490 { 543 {
491 if (cnt && !res) res = -1; 544 if (cnt && !res) res = -1;
492 break; 545 break;
493 } 546 }
494 547
495 offset += cnt; 548 offset += cnt;
496 res += cnt; 549 res += cnt;
550 count -= cnt;
497 } 551 }
498
499 {
500 int errorno = errno;
501 free (buf);
502 errno = errorno;
503 }
504 } 552 }
505 553
506 return res; 554 return res;
555}
556
557/* read a full directory */
558static int
559scandir_ (const char *path, void **namesp)
560{
561 DIR *dirp = opendir (path);
562 union
563 {
564 struct dirent d;
565 char b [offsetof (struct dirent, d_name) + NAME_MAX + 1];
566 } u;
567 struct dirent *entp;
568 char *name, *names;
569 int memlen = 4096;
570 int memofs = 0;
571 int res = 0;
572 int errorno;
573
574 if (!dirp)
575 return -1;
576
577 names = malloc (memlen);
578
579 for (;;)
580 {
581 errno = 0, readdir_r (dirp, &u.d, &entp);
582
583 if (!entp)
584 break;
585
586 name = entp->d_name;
587
588 if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2])))
589 {
590 int len = strlen (name) + 1;
591
592 res++;
593
594 while (memofs + len > memlen)
595 {
596 memlen *= 2;
597 names = realloc (names, memlen);
598 if (!names)
599 break;
600 }
601
602 memcpy (names + memofs, name, len);
603 memofs += len;
604 }
605 }
606
607 errorno = errno;
608 closedir (dirp);
609
610 if (errorno)
611 {
612 free (names);
613 errno = errorno;
614 res = -1;
615 }
616
617 *namesp = (void *)names;
618 return res;
507} 619}
508 620
509/*****************************************************************************/ 621/*****************************************************************************/
510 622
511static void * 623static void *
554 666
555 case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; 667 case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break;
556 case REQ_CLOSE: req->result = close (req->fd); break; 668 case REQ_CLOSE: req->result = close (req->fd); break;
557 case REQ_UNLINK: req->result = unlink (req->dataptr); break; 669 case REQ_UNLINK: req->result = unlink (req->dataptr); break;
558 case REQ_RMDIR: req->result = rmdir (req->dataptr); break; 670 case REQ_RMDIR: req->result = rmdir (req->dataptr); break;
671 case REQ_RENAME: req->result = rename (req->data2ptr, req->dataptr); break;
672 case REQ_LINK: req->result = link (req->data2ptr, req->dataptr); break;
559 case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break; 673 case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break;
560 674
561 case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; 675 case REQ_FDATASYNC: req->result = fdatasync (req->fd); break;
562 case REQ_FSYNC: req->result = fsync (req->fd); break; 676 case REQ_FSYNC: req->result = fsync (req->fd); break;
677 case REQ_READDIR: req->result = scandir_ (req->dataptr, &req->data2ptr); break;
563 678
564 case REQ_QUIT: 679 case REQ_QUIT:
565 break; 680 break;
566 681
567 default: 682 default:
591 pthread_mutex_unlock (&reslock); 706 pthread_mutex_unlock (&reslock);
592 } 707 }
593 while (type != REQ_QUIT); 708 while (type != REQ_QUIT);
594 709
595 return 0; 710 return 0;
711}
712
713/*****************************************************************************/
714
715static void atfork_prepare (void)
716{
717 pthread_mutex_lock (&reqlock);
718 pthread_mutex_lock (&reslock);
719#if !HAVE_PREADWRITE
720 pthread_mutex_lock (&preadwritelock);
721#endif
722#if !HAVE_READDIR_R
723 pthread_mutex_lock (&readdirlock);
724#endif
725}
726
727static void atfork_parent (void)
728{
729#if !HAVE_READDIR_R
730 pthread_mutex_unlock (&readdirlock);
731#endif
732#if !HAVE_PREADWRITE
733 pthread_mutex_unlock (&preadwritelock);
734#endif
735 pthread_mutex_unlock (&reslock);
736 pthread_mutex_unlock (&reqlock);
737}
738
739static void atfork_child (void)
740{
741 aio_req prv;
742
743 started = 0;
744
745 while (reqs)
746 {
747 prv = reqs;
748 reqs = prv->next;
749 free_req (prv);
750 }
751
752 reqs = reqe = 0;
753
754 while (ress)
755 {
756 prv = ress;
757 ress = prv->next;
758 free_req (prv);
759 }
760
761 ress = rese = 0;
762
763 close (respipe [0]);
764 close (respipe [1]);
765 create_pipe ();
766
767 atfork_parent ();
596} 768}
597 769
598#define dREQ \ 770#define dREQ \
599 aio_req req; \ 771 aio_req req; \
600 \ 772 \
611 783
612PROTOTYPES: ENABLE 784PROTOTYPES: ENABLE
613 785
614BOOT: 786BOOT:
615{ 787{
788 HV *stash = gv_stashpv ("IO::AIO", 1);
789 newCONSTSUB (stash, "EXDEV", newSViv (EXDEV));
790 newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY));
791 newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY));
792
616 create_pipe (); 793 create_pipe ();
617 pthread_atfork (atfork_prepare, atfork_parent, atfork_child); 794 pthread_atfork (atfork_prepare, atfork_parent, atfork_child);
618} 795}
619 796
620void 797void
621min_parallel(nthreads) 798min_parallel (nthreads)
622 int nthreads 799 int nthreads
623 PROTOTYPE: $ 800 PROTOTYPE: $
624 801
625void 802void
626max_parallel(nthreads) 803max_parallel (nthreads)
627 int nthreads 804 int nthreads
628 PROTOTYPE: $ 805 PROTOTYPE: $
629 806
630int 807int
631max_outstanding(nreqs) 808max_outstanding (nreqs)
632 int nreqs 809 int nreqs
633 PROTOTYPE: $ 810 PROTOTYPE: $
634 CODE: 811 CODE:
635 RETVAL = max_outstanding; 812 RETVAL = max_outstanding;
636 max_outstanding = nreqs; 813 max_outstanding = nreqs;
637 814
638void 815void
639aio_open(pathname,flags,mode,callback=&PL_sv_undef) 816aio_open (pathname,flags,mode,callback=&PL_sv_undef)
640 SV * pathname 817 SV * pathname
641 int flags 818 int flags
642 int mode 819 int mode
643 SV * callback 820 SV * callback
644 PROTOTYPE: $$$;$ 821 PROTOTYPE: $$$;$
654 831
655 send_req (req); 832 send_req (req);
656} 833}
657 834
658void 835void
659aio_close(fh,callback=&PL_sv_undef) 836aio_close (fh,callback=&PL_sv_undef)
660 SV * fh 837 SV * fh
661 SV * callback 838 SV * callback
662 PROTOTYPE: $;$ 839 PROTOTYPE: $;$
663 ALIAS: 840 ALIAS:
664 aio_close = REQ_CLOSE 841 aio_close = REQ_CLOSE
674 851
675 send_req (req); 852 send_req (req);
676} 853}
677 854
678void 855void
679aio_read(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) 856aio_read (fh,offset,length,data,dataoffset,callback=&PL_sv_undef)
680 SV * fh 857 SV * fh
681 UV offset 858 UV offset
682 UV length 859 UV length
683 SV * data 860 SV * data
684 UV dataoffset 861 UV dataoffset
738 send_req (req); 915 send_req (req);
739 } 916 }
740} 917}
741 918
742void 919void
743aio_sendfile(out_fh,in_fh,in_offset,length,callback=&PL_sv_undef) 920aio_sendfile (out_fh,in_fh,in_offset,length,callback=&PL_sv_undef)
744 SV * out_fh 921 SV * out_fh
745 SV * in_fh 922 SV * in_fh
746 UV in_offset 923 UV in_offset
747 UV length 924 UV length
748 SV * callback 925 SV * callback
761 938
762 send_req (req); 939 send_req (req);
763} 940}
764 941
765void 942void
766aio_readahead(fh,offset,length,callback=&PL_sv_undef) 943aio_readahead (fh,offset,length,callback=&PL_sv_undef)
767 SV * fh 944 SV * fh
768 UV offset 945 UV offset
769 IV length 946 IV length
770 SV * callback 947 SV * callback
771 PROTOTYPE: $$$;$ 948 PROTOTYPE: $$$;$
781 958
782 send_req (req); 959 send_req (req);
783} 960}
784 961
785void 962void
786aio_stat(fh_or_path,callback=&PL_sv_undef) 963aio_stat (fh_or_path,callback=&PL_sv_undef)
787 SV * fh_or_path 964 SV * fh_or_path
788 SV * callback 965 SV * callback
789 ALIAS: 966 ALIAS:
790 aio_stat = REQ_STAT 967 aio_stat = REQ_STAT
791 aio_lstat = REQ_LSTAT 968 aio_lstat = REQ_LSTAT
815 992
816 send_req (req); 993 send_req (req);
817} 994}
818 995
819void 996void
820aio_unlink(pathname,callback=&PL_sv_undef) 997aio_unlink (pathname,callback=&PL_sv_undef)
821 SV * pathname 998 SV * pathname
822 SV * callback 999 SV * callback
823 ALIAS: 1000 ALIAS:
824 aio_unlink = REQ_UNLINK 1001 aio_unlink = REQ_UNLINK
825 aio_rmdir = REQ_RMDIR 1002 aio_rmdir = REQ_RMDIR
1003 aio_readdir = REQ_READDIR
826 CODE: 1004 CODE:
827{ 1005{
828 dREQ; 1006 dREQ;
829 1007
830 req->type = ix; 1008 req->type = ix;
833 1011
834 send_req (req); 1012 send_req (req);
835} 1013}
836 1014
837void 1015void
838aio_symlink(oldpath,newpath,callback=&PL_sv_undef) 1016aio_link (oldpath,newpath,callback=&PL_sv_undef)
839 SV * oldpath 1017 SV * oldpath
840 SV * newpath 1018 SV * newpath
841 SV * callback 1019 SV * callback
1020 ALIAS:
1021 aio_link = REQ_LINK
1022 aio_symlink = REQ_SYMLINK
1023 aio_rename = REQ_RENAME
842 CODE: 1024 CODE:
843{ 1025{
844 dREQ; 1026 dREQ;
845 1027
846 req->type = REQ_SYMLINK; 1028 req->type = ix;
847 req->fh = newSVsv (oldpath); 1029 req->fh = newSVsv (oldpath);
848 req->data2ptr = SvPVbyte_nolen (req->fh); 1030 req->data2ptr = SvPVbyte_nolen (req->fh);
849 req->data = newSVsv (newpath); 1031 req->data = newSVsv (newpath);
850 req->dataptr = SvPVbyte_nolen (req->data); 1032 req->dataptr = SvPVbyte_nolen (req->data);
851 1033
852 send_req (req); 1034 send_req (req);
853} 1035}
854 1036
1037#if 0
1038
1039# undocumented, because it does not cancel active requests
855void 1040void
1041cancel_most_requests ()
1042 PROTOTYPE:
1043 CODE:
1044{
1045 aio_req *req;
1046
1047 pthread_mutex_lock (&reqlock);
1048 for (req = reqs; req; req = req->next)
1049 req->flags |= 1;
1050 pthread_mutex_unlock (&reqlock);
1051
1052 pthread_mutex_lock (&reslock);
1053 for (req = ress; req; req = req->next)
1054 req->flags |= 1;
1055 pthread_mutex_unlock (&reslock);
1056}
1057
1058#endif
1059
1060void
856flush() 1061flush ()
857 PROTOTYPE: 1062 PROTOTYPE:
858 CODE: 1063 CODE:
859 while (nreqs) 1064 while (nreqs)
860 { 1065 {
861 poll_wait (); 1066 poll_wait ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines