*/
-#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <stdbool.h>
-
-#include <unistd.h>
-
#include <errno.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <sys/file.h>
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <netdb.h>
-#include <stdio.h>
#include <signal.h>
#include <fcntl.h>
+
+#include <alloca.h>
+#include <arpa/inet.h>
+#include <getopt.h>
#include <netinet/in.h>
#include <poll.h>
-#include <getopt.h>
+#include <stdbool.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <unistd.h>
#include "getaddrinfo.h"
#include "gettext.h"
#include "inet_ntop.h"
+#include "minmax.h"
+#include "size_max.h"
+#include "snprintf.h"
#include "strdup.h"
+#include "vasnprintf.h"
+#include "xsize.h"
extern void tls_negotiate (int, const char *, const char *);
extern int tls_write(int, const char *, int);
{
int in = fileno (stdin), out = fileno (stdout),
nbuffer, wrote;
- struct pollfd readfds[2], writefds[1];
- char buffer[BUFSIZ], *retry;
+ struct pollfd readfds[2];
+ char buffer[BUFSIZ];
struct sigaction act;
- sigset_t orig_mask;
+ sigset_t mask, 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);
+ sigemptyset (&mask);
+ sigaddset (&mask, SIGALRM);
+
readfds[0].fd = in;
readfds[1].fd = tls_fd;
readfds[0].events = POLLIN;
readfds[1].events = POLLIN;
- writefds[0].events = POLLOUT;
while (1)
{
int ready;
- sigprocmask (SIG_SETMASK, &act.sa_mask, &orig_mask);
+ sigprocmask (SIG_SETMASK, &mask, &orig_mask);
ready = poll (readfds, 2, -1);
sigprocmask (SIG_SETMASK, &orig_mask, NULL);
if (ready == -1 && errno != EINTR)
if (readfds[0].revents & POLLIN)
{
nbuffer = read (in, buffer, sizeof buffer -1);
-
if (nbuffer == 0)
goto finish;
redirect (tls_fd, buffer, nbuffer, tls_write);
}
if (readfds[1].revents & POLLIN)
- {
-readtop:
- nbuffer = tls_read(tls_fd, buffer, sizeof buffer -1);
+ do {
+ nbuffer = tls_read (tls_fd, buffer, sizeof buffer -1);
if (nbuffer == 0)
goto finish;
redirect (out, buffer, nbuffer, write);
- if (tls_pending())
- goto readtop;
- }
+ } while (tls_pending ());
}
finish: