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.

186 lines
7.0 KiB

  1. http://anonscm.debian.org/cgit/collab-maint/uw-imap.git/plain/debian/patches/1005_poll.patch
  2. Description: Use poll(2) instead of select(2) to support more than 1024 file descriptors
  3. Author: Ben Smithurst <ben.smithurst@gradwell.com>
  4. Bug-Debian: https://bugs.debian.org/478193
  5. --- a/src/osdep/unix/os_lnx.c
  6. +++ b/src/osdep/unix/os_lnx.c
  7. @@ -41,6 +41,7 @@
  8. extern int errno; /* just in case */
  9. #include <pwd.h>
  10. #include "misc.h"
  11. +#include <poll.h>
  12. #include "fs_unix.c"
  13. --- a/src/osdep/unix/os_slx.c
  14. +++ b/src/osdep/unix/os_slx.c
  15. @@ -42,6 +42,7 @@ extern int errno; /* just in case */
  16. #include <pwd.h>
  17. #include <shadow.h>
  18. #include "misc.h"
  19. +#include <poll.h>
  20. #include "fs_unix.c"
  21. --- a/src/osdep/unix/tcp_unix.c
  22. +++ b/src/osdep/unix/tcp_unix.c
  23. @@ -235,12 +235,11 @@ TCPSTREAM *tcp_open (char *host,char *se
  24. int tcp_socket_open (int family,void *adr,size_t adrlen,unsigned short port,
  25. char *tmp,int *ctr,char *hst)
  26. {
  27. - int i,ti,sock,flgs;
  28. + int i,ti,sock,flgs,tmo;
  29. + struct pollfd pfd;
  30. size_t len;
  31. time_t now;
  32. struct protoent *pt = getprotobyname ("tcp");
  33. - fd_set rfds,wfds,efds;
  34. - struct timeval tmo;
  35. struct sockaddr *sadr = ip_sockaddr (family,adr,adrlen,port,&len);
  36. blocknotify_t bn = (blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL);
  37. /* fetid Solaris */
  38. @@ -252,14 +251,6 @@ int tcp_socket_open (int family,void *ad
  39. sprintf (tmp,"Unable to create TCP socket: %s",strerror (errno));
  40. (*bn) (BLOCK_NONSENSITIVE,data);
  41. }
  42. - else if (sock >= FD_SETSIZE) {/* unselectable sockets are useless */
  43. - sprintf (tmp,"Unable to create selectable TCP socket (%d >= %d)",
  44. - sock,FD_SETSIZE);
  45. - (*bn) (BLOCK_NONSENSITIVE,data);
  46. - close (sock);
  47. - sock = -1;
  48. - errno = EMFILE;
  49. - }
  50. else { /* get current socket flags */
  51. flgs = fcntl (sock,F_GETFL,0);
  52. @@ -284,16 +275,11 @@ int tcp_socket_open (int family,void *ad
  53. if ((sock >= 0) && ctr) { /* want open timeout? */
  54. now = time (0); /* open timeout */
  55. ti = ttmo_open ? now + ttmo_open : 0;
  56. - tmo.tv_usec = 0;
  57. - FD_ZERO (&rfds); /* initialize selection vector */
  58. - FD_ZERO (&wfds); /* initialize selection vector */
  59. - FD_ZERO (&efds); /* handle errors too */
  60. - FD_SET (sock,&rfds); /* block for error or readable or writable */
  61. - FD_SET (sock,&wfds);
  62. - FD_SET (sock,&efds);
  63. + pfd.fd = sock;
  64. + pfd.events = POLLIN | POLLOUT;
  65. do { /* block under timeout */
  66. - tmo.tv_sec = ti ? ti - now : 0;
  67. - i = select (sock+1,&rfds,&wfds,&efds,ti ? &tmo : NIL);
  68. + tmo = ti ? ti - now : 0;
  69. + i = poll (&pfd, 1, ti ? tmo * 1000 : -1);
  70. now = time (0); /* fake timeout if interrupt & time expired */
  71. if ((i < 0) && (errno == EINTR) && ti && (ti <= now)) i = 0;
  72. } while ((i < 0) && (errno == EINTR));
  73. @@ -302,7 +288,7 @@ int tcp_socket_open (int family,void *ad
  74. fcntl (sock,F_SETFL,flgs);
  75. /* This used to be a zero-byte read(), but that crashes Solaris */
  76. /* get socket status */
  77. - if(FD_ISSET(sock, &rfds)) while (((i = *ctr = read (sock,tmp,1)) < 0) && (errno == EINTR));
  78. + if(pfd.revents & POLLIN) while (((i = *ctr = read (sock,tmp,1)) < 0) && (errno == EINTR));
  79. }
  80. if (i <= 0) { /* timeout or error? */
  81. i = i ? errno : ETIMEDOUT;/* determine error code */
  82. @@ -545,9 +531,8 @@ long tcp_getbuffer (TCPSTREAM *stream,un
  83. stream->ictr -=n;
  84. }
  85. if (size) {
  86. - int i;
  87. - fd_set fds,efds;
  88. - struct timeval tmo;
  89. + int i, tmo;
  90. + struct pollfd pfd;
  91. time_t t = time (0);
  92. blocknotify_t bn=(blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL);
  93. (*bn) (BLOCK_TCPREAD,NIL);
  94. @@ -556,16 +541,13 @@ long tcp_getbuffer (TCPSTREAM *stream,un
  95. time_t now = tl;
  96. time_t ti = ttmo_read ? now + ttmo_read : 0;
  97. if (tcpdebug) mm_log ("Reading TCP buffer",TCPDEBUG);
  98. - tmo.tv_usec = 0;
  99. - FD_ZERO (&fds); /* initialize selection vector */
  100. - FD_ZERO (&efds); /* handle errors too */
  101. - /* set bit in selection vectors */
  102. - FD_SET (stream->tcpsi,&fds);
  103. - FD_SET (stream->tcpsi,&efds);
  104. +
  105. + pfd.events = POLLIN;
  106. + pfd.fd = stream->tcpsi;
  107. errno = NIL; /* initially no error */
  108. do { /* block under timeout */
  109. - tmo.tv_sec = ti ? ti - now : 0;
  110. - i = select (stream->tcpsi+1,&fds,NIL,&efds,ti ? &tmo : NIL);
  111. + tmo = ti ? ti - now : 0;
  112. + i = poll (&pfd, 1, ti ? tmo * 1000 : -1);
  113. now = time (0); /* fake timeout if interrupt & time expired */
  114. if ((i < 0) && (errno == EINTR) && ti && (ti <= now)) i = 0;
  115. } while ((i < 0) && (errno == EINTR));
  116. @@ -605,9 +587,8 @@ long tcp_getbuffer (TCPSTREAM *stream,un
  117. long tcp_getdata (TCPSTREAM *stream)
  118. {
  119. - int i;
  120. - fd_set fds,efds;
  121. - struct timeval tmo;
  122. + int i, tmo;
  123. + struct pollfd pfd;
  124. time_t t = time (0);
  125. blocknotify_t bn = (blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL);
  126. if (stream->tcpsi < 0) return NIL;
  127. @@ -617,15 +598,12 @@ long tcp_getdata (TCPSTREAM *stream)
  128. time_t now = tl;
  129. time_t ti = ttmo_read ? now + ttmo_read : 0;
  130. if (tcpdebug) mm_log ("Reading TCP data",TCPDEBUG);
  131. - tmo.tv_usec = 0;
  132. - FD_ZERO (&fds); /* initialize selection vector */
  133. - FD_ZERO (&efds); /* handle errors too */
  134. - FD_SET (stream->tcpsi,&fds);/* set bit in selection vectors */
  135. - FD_SET (stream->tcpsi,&efds);
  136. + pfd.fd = stream->tcpsi;
  137. + pfd.events = POLLIN;
  138. errno = NIL; /* initially no error */
  139. do { /* block under timeout */
  140. - tmo.tv_sec = ti ? ti - now : 0;
  141. - i = select (stream->tcpsi+1,&fds,NIL,&efds,ti ? &tmo : NIL);
  142. + tmo = ti ? ti - now : 0;
  143. + i = poll (&pfd, 1, ti ? tmo * 1000 : -1);
  144. now = time (0); /* fake timeout if interrupt & time expired */
  145. if ((i < 0) && (errno == EINTR) && ti && (ti <= now)) i = 0;
  146. } while ((i < 0) && (errno == EINTR));
  147. @@ -677,9 +655,8 @@ long tcp_soutr (TCPSTREAM *stream,char *
  148. long tcp_sout (TCPSTREAM *stream,char *string,unsigned long size)
  149. {
  150. - int i;
  151. - fd_set fds,efds;
  152. - struct timeval tmo;
  153. + int i, tmo;
  154. + struct pollfd pfd;
  155. time_t t = time (0);
  156. blocknotify_t bn = (blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL);
  157. if (stream->tcpso < 0) return NIL;
  158. @@ -689,15 +666,12 @@ long tcp_sout (TCPSTREAM *stream,char *s
  159. time_t now = tl;
  160. time_t ti = ttmo_write ? now + ttmo_write : 0;
  161. if (tcpdebug) mm_log ("Writing to TCP",TCPDEBUG);
  162. - tmo.tv_usec = 0;
  163. - FD_ZERO (&fds); /* initialize selection vector */
  164. - FD_ZERO (&efds); /* handle errors too */
  165. - FD_SET (stream->tcpso,&fds);/* set bit in selection vector */
  166. - FD_SET(stream->tcpso,&efds);/* set bit in error selection vector */
  167. + pfd.fd = stream->tcpso;
  168. + pfd.events = POLLOUT;
  169. errno = NIL; /* block and write */
  170. do { /* block under timeout */
  171. - tmo.tv_sec = ti ? ti - now : 0;
  172. - i = select (stream->tcpso+1,NIL,&fds,&efds,ti ? &tmo : NIL);
  173. + tmo = ti ? ti - now : 0;
  174. + i = poll (&pfd, 1, ti ? tmo * 1000 : -1);
  175. now = time (0); /* fake timeout if interrupt & time expired */
  176. if ((i < 0) && (errno == EINTR) && ti && (ti <= now)) i = 0;
  177. } while ((i < 0) && (errno == EINTR));