Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

70 lines
1.6 KiB

  1. #include <unistd.h>
  2. #include <fcntl.h>
  3. #include <errno.h>
  4. #include "io_internal.h"
  5. #ifdef HAVE_KQUEUE
  6. #include <sys/types.h>
  7. #include <sys/event.h>
  8. #include <sys/time.h>
  9. #endif
  10. #ifdef HAVE_EPOLL
  11. #include <inttypes.h>
  12. #include <sys/epoll.h>
  13. #include <byte.h>
  14. #endif
  15. #ifdef HAVE_DEVPOLL
  16. #include <sys/types.h>
  17. #include <sys/socket.h>
  18. #include <sys/devpoll.h>
  19. #endif
  20. #ifdef DEBUG
  21. #include <assert.h>
  22. #else
  23. #define assert(x)
  24. #endif
  25. /* IDEA: if someone calls io_dontwantwrite, do not do the syscall to
  26. * tell the kernel about it. Only when a write event comes in and the
  27. * user has told us he does not want them, THEN tell the kernel we are
  28. * not interested. In the typical protocol case of "write request, read
  29. * reply", this should save a lot of syscalls. */
  30. void io_dontwantwrite_really(int64 d,io_entry* e) {
  31. int newfd;
  32. (void)d;
  33. assert(e->kernelwantwrite);
  34. newfd=!e->kernelwantread;
  35. io_wanted_fds-=newfd;
  36. #ifdef HAVE_KQUEUE
  37. if (io_waitmode==KQUEUE) {
  38. struct kevent kev;
  39. struct timespec ts;
  40. EV_SET(&kev, d, EVFILT_WRITE, EV_DELETE, 0, 0, 0);
  41. ts.tv_sec=0; ts.tv_nsec=0;
  42. kevent(io_master,&kev,1,0,0,&ts);
  43. }
  44. #endif
  45. #ifdef HAVE_DEVPOLL
  46. if (io_waitmode==DEVPOLL) {
  47. struct pollfd x;
  48. x.fd=d;
  49. x.events=0;
  50. if (e->kernelwantread) x.events|=POLLIN;
  51. if (!x.events) x.events=POLLREMOVE;
  52. write(io_master,&x,sizeof(x));
  53. }
  54. #endif
  55. e->wantwrite=0;
  56. e->kernelwantwrite=0;
  57. }
  58. void io_dontwantwrite(int64 d) {
  59. io_entry* e=iarray_get(&io_fds,d);
  60. if (e) {
  61. if (e->canwrite)
  62. io_dontwantwrite_really(d,e);
  63. e->wantwrite=0;
  64. }
  65. }