~ubuntu-branches/ubuntu/quantal/openconnect/quantal

« back to all changes in this revision

Viewing changes to mainloop.c

  • Committer: Bazaar Package Importer
  • Author(s): Ross Burton
  • Date: 2009-06-24 19:17:44 UTC
  • mfrom: (1.2.1 upstream) (3.1.2 karmic)
  • Revision ID: james.westby@ubuntu.com-20090624191744-0fk1vxfmjopaistk
Tags: 2.01-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <signal.h>
30
30
#include <arpa/inet.h>
31
31
#include <unistd.h>
 
32
#include <string.h>
 
33
 
 
34
#include <openssl/ssl.h>
32
35
 
33
36
#include "openconnect.h"
34
37
 
67
70
        struct sigaction sa;
68
71
        memset(&sa, 0, sizeof(sa));
69
72
        sa.sa_handler = handle_sigint;
70
 
        
 
73
 
71
74
        sigaction(SIGINT, &sa, NULL);
72
75
        sigaction(SIGHUP, &sa, NULL);
73
76
 
77
80
                struct timeval tv;
78
81
                fd_set rfds, wfds, efds;
79
82
 
 
83
#ifdef SSL_F_DTLS1_CONNECT
80
84
                if (vpninfo->new_dtls_ssl)
81
85
                        dtls_try_handshake(vpninfo);
82
86
 
87
91
                }
88
92
                if (vpninfo->dtls_ssl)
89
93
                        did_work += dtls_mainloop(vpninfo, &timeout);
90
 
 
 
94
#endif
91
95
                if (vpninfo->quit_reason)
92
96
                        break;
93
97
 
114
118
                if (did_work)
115
119
                        continue;
116
120
 
117
 
                vpninfo->progress(vpninfo, PRG_TRACE, 
 
121
                vpninfo->progress(vpninfo, PRG_TRACE,
118
122
                                  "Did no work; sleeping for %d ms...\n", timeout);
119
123
                memcpy(&rfds, &vpninfo->select_rfds, sizeof(rfds));
120
124
                memcpy(&wfds, &vpninfo->select_wfds, sizeof(wfds));
123
127
                tv.tv_sec = timeout / 1000;
124
128
                tv.tv_usec = (timeout % 1000) * 1000;
125
129
                if (select(vpninfo->select_nfds, &rfds, &wfds, &efds, &tv) >= 0
126
 
                    && FD_ISSET(vpninfo->ssl_fd, &efds)) {
127
 
                        /* OpenSSL doesn't seem to cope properly with this... */
128
 
                        vpninfo->progress(vpninfo, PRG_ERR, "Server closed connection!\n");
129
 
                        exit(1);
 
130
                    && FD_ISSET(vpninfo->ssl_fd, &rfds)) {
 
131
                        char b;
 
132
                        if (recv(vpninfo->ssl_fd, &b, 1, MSG_PEEK) == 0) {
 
133
                                /* Zero indicates EOF, which OpenSSL won't handle on read() */
 
134
                                vpninfo->progress(vpninfo, PRG_ERR, "Server closed connection!\n");
 
135
                                exit(1);
 
136
                        }
130
137
                }
131
138
        }
132
139