Move TCP closure detection to cstp.c, make it reconnect when it happens
authorDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 19 Oct 2009 02:56:44 +0000 (11:56 +0900)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 19 Oct 2009 02:56:44 +0000 (11:56 +0900)
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
cstp.c
mainloop.c

diff --git a/cstp.c b/cstp.c
index c58da8f..d03d5e1 100644 (file)
--- a/cstp.c
+++ b/cstp.c
@@ -502,6 +502,14 @@ int cstp_mainloop(struct openconnect_info *vpninfo, int *timeout)
                return 1;
        }
 
+       ret = SSL_get_error(vpninfo->https_ssl, len);
+       if (ret == SSL_ERROR_SYSCALL || ret == SSL_ERROR_ZERO_RETURN) {
+               vpninfo->progress(vpninfo, PRG_ERR,
+                                 "SSL read error %d (server probably closed connection); reconnecting.\n",
+                                 ret);
+                       goto do_reconnect;
+       }
+
 
        /* If SSL_write() fails we are expected to try again. With exactly
           the same data, at exactly the same location. So we keep the
index 13c8db4..2890d5b 100644 (file)
@@ -127,15 +127,8 @@ int vpn_mainloop(struct openconnect_info *vpninfo)
 
                tv.tv_sec = timeout / 1000;
                tv.tv_usec = (timeout % 1000) * 1000;
-               if (select(vpninfo->select_nfds, &rfds, &wfds, &efds, &tv) >= 0
-                   && FD_ISSET(vpninfo->ssl_fd, &rfds)) {
-                       char b;
-                       if (recv(vpninfo->ssl_fd, &b, 1, MSG_PEEK) == 0) {
-                               /* Zero indicates EOF, which OpenSSL won't handle on read() */
-                               vpninfo->progress(vpninfo, PRG_ERR, "Server closed connection!\n");
-                               exit(1);
-                       }
-               }
+
+               select(vpninfo->select_nfds, &rfds, &wfds, &efds, &tv);
        }
 
        cstp_bye(vpninfo, vpninfo->quit_reason);