imap-2007e-poll.patch

This commit is contained in:
Chris 2019-01-03 04:21:04 -06:00
parent 940401df1f
commit 5871bac2a8
3 changed files with 28 additions and 52 deletions

View File

@ -41,6 +41,7 @@
extern int errno; /* just in case */ extern int errno; /* just in case */
#include <pwd.h> #include <pwd.h>
#include "misc.h" #include "misc.h"
#include <poll.h>
#include "fs_unix.c" #include "fs_unix.c"

View File

@ -42,6 +42,7 @@ extern int errno; /* just in case */
#include <pwd.h> #include <pwd.h>
#include <shadow.h> #include <shadow.h>
#include "misc.h" #include "misc.h"
#include <poll.h>
#include "fs_unix.c" #include "fs_unix.c"

View File

@ -235,12 +235,11 @@ TCPSTREAM *tcp_open (char *host,char *service,unsigned long port)
int tcp_socket_open (int family,void *adr,size_t adrlen,unsigned short port, int tcp_socket_open (int family,void *adr,size_t adrlen,unsigned short port,
char *tmp,int *ctr,char *hst) char *tmp,int *ctr,char *hst)
{ {
int i,ti,sock,flgs; int i,ti,sock,flgs,tmo;
struct pollfd pfd;
size_t len; size_t len;
time_t now; time_t now;
struct protoent *pt = getprotobyname ("tcp"); struct protoent *pt = getprotobyname ("tcp");
fd_set rfds,wfds,efds;
struct timeval tmo;
struct sockaddr *sadr = ip_sockaddr (family,adr,adrlen,port,&len); struct sockaddr *sadr = ip_sockaddr (family,adr,adrlen,port,&len);
blocknotify_t bn = (blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL); blocknotify_t bn = (blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL);
/* fetid Solaris */ /* fetid Solaris */
@ -252,14 +251,6 @@ int tcp_socket_open (int family,void *adr,size_t adrlen,unsigned short port,
sprintf (tmp,"Unable to create TCP socket: %s",strerror (errno)); sprintf (tmp,"Unable to create TCP socket: %s",strerror (errno));
(*bn) (BLOCK_NONSENSITIVE,data); (*bn) (BLOCK_NONSENSITIVE,data);
} }
else if (sock >= FD_SETSIZE) {/* unselectable sockets are useless */
sprintf (tmp,"Unable to create selectable TCP socket (%d >= %d)",
sock,FD_SETSIZE);
(*bn) (BLOCK_NONSENSITIVE,data);
close (sock);
sock = -1;
errno = EMFILE;
}
else { /* get current socket flags */ else { /* get current socket flags */
flgs = fcntl (sock,F_GETFL,0); flgs = fcntl (sock,F_GETFL,0);
@ -284,16 +275,11 @@ int tcp_socket_open (int family,void *adr,size_t adrlen,unsigned short port,
if ((sock >= 0) && ctr) { /* want open timeout? */ if ((sock >= 0) && ctr) { /* want open timeout? */
now = time (0); /* open timeout */ now = time (0); /* open timeout */
ti = ttmo_open ? now + ttmo_open : 0; ti = ttmo_open ? now + ttmo_open : 0;
tmo.tv_usec = 0; pfd.fd = sock;
FD_ZERO (&rfds); /* initialize selection vector */ pfd.events = POLLIN | POLLOUT;
FD_ZERO (&wfds); /* initialize selection vector */
FD_ZERO (&efds); /* handle errors too */
FD_SET (sock,&rfds); /* block for error or readable or writable */
FD_SET (sock,&wfds);
FD_SET (sock,&efds);
do { /* block under timeout */ do { /* block under timeout */
tmo.tv_sec = ti ? ti - now : 0; tmo = ti ? ti - now : 0;
i = select (sock+1,&rfds,&wfds,&efds,ti ? &tmo : NIL); i = poll (&pfd, 1, ti ? tmo * 1000 : -1);
now = time (0); /* fake timeout if interrupt & time expired */ now = time (0); /* fake timeout if interrupt & time expired */
if ((i < 0) && (errno == EINTR) && ti && (ti <= now)) i = 0; if ((i < 0) && (errno == EINTR) && ti && (ti <= now)) i = 0;
} while ((i < 0) && (errno == EINTR)); } while ((i < 0) && (errno == EINTR));
@ -302,7 +288,7 @@ int tcp_socket_open (int family,void *adr,size_t adrlen,unsigned short port,
fcntl (sock,F_SETFL,flgs); fcntl (sock,F_SETFL,flgs);
/* This used to be a zero-byte read(), but that crashes Solaris */ /* This used to be a zero-byte read(), but that crashes Solaris */
/* get socket status */ /* get socket status */
if(FD_ISSET(sock, &rfds)) while (((i = *ctr = read (sock,tmp,1)) < 0) && (errno == EINTR)); if(pfd.revents & POLLIN) while (((i = *ctr = read (sock,tmp,1)) < 0) && (errno == EINTR));
} }
if (i <= 0) { /* timeout or error? */ if (i <= 0) { /* timeout or error? */
i = i ? errno : ETIMEDOUT;/* determine error code */ i = i ? errno : ETIMEDOUT;/* determine error code */
@ -545,9 +531,8 @@ long tcp_getbuffer (TCPSTREAM *stream,unsigned long size,char *s)
stream->ictr -=n; stream->ictr -=n;
} }
if (size) { if (size) {
int i; int i, tmo;
fd_set fds,efds; struct pollfd pfd;
struct timeval tmo;
time_t t = time (0); time_t t = time (0);
blocknotify_t bn=(blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL); blocknotify_t bn=(blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL);
(*bn) (BLOCK_TCPREAD,NIL); (*bn) (BLOCK_TCPREAD,NIL);
@ -556,16 +541,13 @@ long tcp_getbuffer (TCPSTREAM *stream,unsigned long size,char *s)
time_t now = tl; time_t now = tl;
time_t ti = ttmo_read ? now + ttmo_read : 0; time_t ti = ttmo_read ? now + ttmo_read : 0;
if (tcpdebug) mm_log ("Reading TCP buffer",TCPDEBUG); if (tcpdebug) mm_log ("Reading TCP buffer",TCPDEBUG);
tmo.tv_usec = 0;
FD_ZERO (&fds); /* initialize selection vector */ pfd.events = POLLIN;
FD_ZERO (&efds); /* handle errors too */ pfd.fd = stream->tcpsi;
/* set bit in selection vectors */
FD_SET (stream->tcpsi,&fds);
FD_SET (stream->tcpsi,&efds);
errno = NIL; /* initially no error */ errno = NIL; /* initially no error */
do { /* block under timeout */ do { /* block under timeout */
tmo.tv_sec = ti ? ti - now : 0; tmo = ti ? ti - now : 0;
i = select (stream->tcpsi+1,&fds,NIL,&efds,ti ? &tmo : NIL); i = poll (&pfd, 1, ti ? tmo * 1000 : -1);
now = time (0); /* fake timeout if interrupt & time expired */ now = time (0); /* fake timeout if interrupt & time expired */
if ((i < 0) && (errno == EINTR) && ti && (ti <= now)) i = 0; if ((i < 0) && (errno == EINTR) && ti && (ti <= now)) i = 0;
} while ((i < 0) && (errno == EINTR)); } while ((i < 0) && (errno == EINTR));
@ -605,9 +587,8 @@ long tcp_getbuffer (TCPSTREAM *stream,unsigned long size,char *s)
long tcp_getdata (TCPSTREAM *stream) long tcp_getdata (TCPSTREAM *stream)
{ {
int i; int i, tmo;
fd_set fds,efds; struct pollfd pfd;
struct timeval tmo;
time_t t = time (0); time_t t = time (0);
blocknotify_t bn = (blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL); blocknotify_t bn = (blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL);
if (stream->tcpsi < 0) return NIL; if (stream->tcpsi < 0) return NIL;
@ -617,15 +598,12 @@ long tcp_getdata (TCPSTREAM *stream)
time_t now = tl; time_t now = tl;
time_t ti = ttmo_read ? now + ttmo_read : 0; time_t ti = ttmo_read ? now + ttmo_read : 0;
if (tcpdebug) mm_log ("Reading TCP data",TCPDEBUG); if (tcpdebug) mm_log ("Reading TCP data",TCPDEBUG);
tmo.tv_usec = 0; pfd.fd = stream->tcpsi;
FD_ZERO (&fds); /* initialize selection vector */ pfd.events = POLLIN;
FD_ZERO (&efds); /* handle errors too */
FD_SET (stream->tcpsi,&fds);/* set bit in selection vectors */
FD_SET (stream->tcpsi,&efds);
errno = NIL; /* initially no error */ errno = NIL; /* initially no error */
do { /* block under timeout */ do { /* block under timeout */
tmo.tv_sec = ti ? ti - now : 0; tmo = ti ? ti - now : 0;
i = select (stream->tcpsi+1,&fds,NIL,&efds,ti ? &tmo : NIL); i = poll (&pfd, 1, ti ? tmo * 1000 : -1);
now = time (0); /* fake timeout if interrupt & time expired */ now = time (0); /* fake timeout if interrupt & time expired */
if ((i < 0) && (errno == EINTR) && ti && (ti <= now)) i = 0; if ((i < 0) && (errno == EINTR) && ti && (ti <= now)) i = 0;
} while ((i < 0) && (errno == EINTR)); } while ((i < 0) && (errno == EINTR));
@ -677,9 +655,8 @@ long tcp_soutr (TCPSTREAM *stream,char *string)
long tcp_sout (TCPSTREAM *stream,char *string,unsigned long size) long tcp_sout (TCPSTREAM *stream,char *string,unsigned long size)
{ {
int i; int i, tmo;
fd_set fds,efds; struct pollfd pfd;
struct timeval tmo;
time_t t = time (0); time_t t = time (0);
blocknotify_t bn = (blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL); blocknotify_t bn = (blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL);
if (stream->tcpso < 0) return NIL; if (stream->tcpso < 0) return NIL;
@ -689,15 +666,12 @@ long tcp_sout (TCPSTREAM *stream,char *string,unsigned long size)
time_t now = tl; time_t now = tl;
time_t ti = ttmo_write ? now + ttmo_write : 0; time_t ti = ttmo_write ? now + ttmo_write : 0;
if (tcpdebug) mm_log ("Writing to TCP",TCPDEBUG); if (tcpdebug) mm_log ("Writing to TCP",TCPDEBUG);
tmo.tv_usec = 0; pfd.fd = stream->tcpso;
FD_ZERO (&fds); /* initialize selection vector */ pfd.events = POLLOUT;
FD_ZERO (&efds); /* handle errors too */
FD_SET (stream->tcpso,&fds);/* set bit in selection vector */
FD_SET(stream->tcpso,&efds);/* set bit in error selection vector */
errno = NIL; /* block and write */ errno = NIL; /* block and write */
do { /* block under timeout */ do { /* block under timeout */
tmo.tv_sec = ti ? ti - now : 0; tmo = ti ? ti - now : 0;
i = select (stream->tcpso+1,NIL,&fds,&efds,ti ? &tmo : NIL); i = poll (&pfd, 1, ti ? tmo * 1000 : -1);
now = time (0); /* fake timeout if interrupt & time expired */ now = time (0); /* fake timeout if interrupt & time expired */
if ((i < 0) && (errno == EINTR) && ti && (ti <= now)) i = 0; if ((i < 0) && (errno == EINTR) && ti && (ti <= now)) i = 0;
} while ((i < 0) && (errno == EINTR)); } while ((i < 0) && (errno == EINTR));