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.

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