Skip to content

Commit

Permalink
Move TCP closure detection to cstp.c, make it reconnect when it happens
Browse files Browse the repository at this point in the history
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Oct 19, 2009
1 parent 86e4316 commit dacb3eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
8 changes: 8 additions & 0 deletions cstp.c
Expand Up @@ -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
Expand Down
11 changes: 2 additions & 9 deletions mainloop.c
Expand Up @@ -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);
Expand Down

0 comments on commit dacb3eb

Please sign in to comment.