io_getevents.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* io_getevents.c
  2. libaio Linux async I/O interface
  3. Copyright 2002 Red Hat, Inc.
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. #include "libaio.h"
  17. #include <errno.h>
  18. #include <stdlib.h>
  19. #include <time.h>
  20. #include "syscall.h"
  21. io_syscall5(int, __io_getevents_0_4, io_getevents, io_context_t, ctx, long, min_nr, long, nr, struct io_event *, events, struct timespec *, timeout)
  22. #define AIO_RING_MAGIC 0xa10a10a1
  23. /* Ben will hate me for this */
  24. struct aio_ring {
  25. unsigned id; /* kernel internal index number */
  26. unsigned nr; /* number of io_events */
  27. unsigned head;
  28. unsigned tail;
  29. unsigned magic;
  30. unsigned compat_features;
  31. unsigned incompat_features;
  32. unsigned header_length; /* size of aio_ring */
  33. };
  34. int io_getevents(io_context_t ctx, long min_nr, long nr, struct io_event * events, struct timespec * timeout)
  35. {
  36. struct aio_ring *ring;
  37. ring = (struct aio_ring*)ctx;
  38. if (ring==NULL || ring->magic != AIO_RING_MAGIC)
  39. goto do_syscall;
  40. if (timeout!=NULL && timeout->tv_sec == 0 && timeout->tv_nsec == 0) {
  41. if (ring->head == ring->tail)
  42. return 0;
  43. }
  44. do_syscall:
  45. return __io_getevents_0_4(ctx, min_nr, nr, events, timeout);
  46. }