#include <signal.h>
#include <fcntl.h>
#include <netinet/in.h>
-#ifdef HAVE_POLL_H
-#include <sys/poll.h>
-#endif
-#include "getopt.h"
+#include <poll.h>
+#include <getopt.h>
#include "getaddrinfo.h"
#include "gettext.h"
#include "inet_ntop.h"
int argc;
char **argv;
{
- int in = fileno (stdin), out = fileno (stdout),
+ int in = fileno (stdin), out = fileno (stdout),
nbuffer, wrote;
-#ifdef HAVE_POLL
struct pollfd readfds[2], writefds[1];
-#else
- fd_set readfds, writefds;
-#endif
char buffer[BUFSIZ], *retry;
struct sigaction act;
+ sigset_t orig_mask;
int this_option_optind = optind ? optind : 1;
int option_index = 0, c;
memset (&act, 0, sizeof (act));
act.sa_handler = do_tls_negotiate;
sigemptyset (&act.sa_mask);
+ sigaddset (&act.sa_mask, SIGALRM);
act.sa_flags = SA_RESTART|SA_RESETHAND;
sigaction (SIGALRM, &act, NULL);
-#ifdef HAVE_POLL
readfds[0].fd = in;
readfds[1].fd = tls_fd;
readfds[0].events = POLLIN;
readfds[1].events = POLLIN;
writefds[0].events = POLLOUT;
-#endif
while (1)
{
-#ifdef HAVE_POLL
- if (poll (readfds, 2, -1) == -1 && errno != EINTR)
-#else
- FD_ZERO (&readfds);
- FD_SET (tls_fd, &readfds);
- FD_SET (in, &readfds);
- if (select (tls_fd+1, &readfds, NULL, NULL, NULL) == -1
- && errno != EINTR )
-#endif
+ int ready;
+
+ sigprocmask (SIG_SETMASK, &act.sa_mask, &orig_mask);
+ ready = poll (readfds, 2, -1);
+ sigprocmask (SIG_SETMASK, &orig_mask, NULL);
+ if (ready == -1 && errno != EINTR)
{
perror ("poll");
return 1;
}
-#ifdef HAVE_POLL
if (readfds[0].revents & POLLIN)
-#else
- if (FD_ISSET (in, &readfds))
-#endif
{
nbuffer = read (in, buffer, sizeof buffer -1);
goto finish;
for (retry = buffer; nbuffer > 0; nbuffer -= wrote, retry += wrote)
{
-#ifdef HAVE_POLL
+ sigprocmask (SIG_SETMASK, &act.sa_mask, &orig_mask);
writefds[0].fd = tls_fd;
- if (poll (writefds, 1, -1) == -1)
-#else
- FD_ZERO (&writefds);
- FD_SET (tls_fd, &writefds);
- if (select (tls_fd+1, NULL, &writefds, NULL, NULL) == -1)
-#endif
+ ready = poll (writefds, 1, -1);
+ sigprocmask (SIG_SETMASK, &orig_mask, NULL);
+ if (ready == -1 && errno != EINTR)
{
perror ("poll");
return 1;
if (wrote < 0) goto finish;
}
}
-#ifdef HAVE_POLL
if (readfds[1].revents & POLLIN)
-#else
- if (FD_ISSET (tls_fd, &readfds))
-#endif
{
readtop:
nbuffer = tls_read(tls_fd, buffer, sizeof buffer -1);
goto finish;
for (retry = buffer; nbuffer > 0; nbuffer -= wrote, retry += wrote)
{
-#ifdef HAVE_POLL
+ sigprocmask (SIG_SETMASK, &act.sa_mask, &orig_mask);
writefds[0].fd = out;
- if (poll (writefds, 1, -1) == -1)
-#else
- FD_ZERO (&writefds);
- FD_SET (out, &writefds);
- if (select (out+1, NULL, &writefds, NULL, NULL) == -1)
-#endif
+ ready = poll (writefds, 1, -1);
+ sigprocmask (SIG_SETMASK, &orig_mask, NULL);
+ if (ready == -1 && errno != EINTR)
{
perror ("poll");
return 1;