1 /* runterminal.c -- shared testing code loop for message loop */
13 #include <sys/socket.h>
14 #include <netinet/in.h>
16 #include <tlspool/starttls.h>
18 void runterminal (int chanio, int *sigcont, starttls_t *tlsdata,
19 uint32_t startflags, const char *localid, const char *remoteid) {
20 struct pollfd inout [2];
24 inout [1].fd = chanio;
25 inout [0].events = inout [1].events = POLLIN;
29 printf ("Received SIGCONT, will now initiate TLS handshake renegotiation\n");
30 tlsdata->flags = startflags;
32 strcpy (tlsdata->localid, localid);
34 strcpy (tlsdata->remoteid, remoteid);
35 if (-1 == tlspool_starttls (-1, tlsdata, NULL, NULL)) {
36 printf ("TLS handshake renegotiation failed, terminating\n");
39 printf ("TLS handshake renegotiation completed successfully\n");
41 if (poll (inout, 2, -1) == -1) {
48 if ((inout [0].revents | inout [1].revents) & ~POLLIN) {
51 if (inout [0].revents & POLLIN) {
52 sz = read (0, buf, sizeof (buf));
53 printf ("Read %ld bytes, sigcont==%d (should be 0 for proper operation)\n", sz, *sigcont);
59 } else if (send (chanio, buf, sz, MSG_DONTWAIT) != sz) {
62 printf ("Sent %ld bytes\n", sz);
65 if (inout [1].revents & POLLIN) {
66 sz = recv (chanio, buf, sizeof (buf), MSG_DONTWAIT);
67 printf ("Received %ld bytes, sigcont==%d (should be 0 for proper operation)\n", sz, *sigcont);
73 } else if (write (1, buf, sz) != sz) {
76 printf ("Printed %ld bytes\n", sz);