Skip to content

Commit

Permalink
mainloop: Convert vpn_mainloop() into a library function
Browse files Browse the repository at this point in the history
Rename to openconnect_mainloop() and allow the caller to specify
reconnection parameters.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
  • Loading branch information
cernekee committed Jan 15, 2014
1 parent efcb093 commit 7237bd7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions libopenconnect.map.in
Expand Up @@ -38,6 +38,7 @@ OPENCONNECT_3.0 {
OPENCONNECT_3.1 {
global:
openconnect_setup_cmd_pipe;
openconnect_mainloop;
} OPENCONNECT_3.0;

OPENCONNECT_PRIVATE {
Expand Down
7 changes: 3 additions & 4 deletions main.c
Expand Up @@ -504,6 +504,7 @@ int main(int argc, char **argv)
char *config_arg;
char *token_str = NULL;
oc_token_mode_t token_mode = OC_TOKEN_MODE_NONE;
int reconnect_timeout = 300;

#ifdef ENABLE_NLS
bindtextdomain("openconnect", LOCALEDIR);
Expand Down Expand Up @@ -532,8 +533,6 @@ int main(int argc, char **argv)
vpninfo->deflate = 1;
vpninfo->dtls_attempt_period = 60;
vpninfo->max_qlen = 10;
vpninfo->reconnect_interval = RECONNECT_INTERVAL_MIN;
vpninfo->reconnect_timeout = 300;
vpninfo->uid_csd = 0;
/* We could let them override this on the command line some day, perhaps */
openconnect_set_reported_os(vpninfo, NULL);
Expand Down Expand Up @@ -612,7 +611,7 @@ int main(int argc, char **argv)
non_inter = 1;
break;
case OPT_RECONNECT_TIMEOUT:
vpninfo->reconnect_timeout = atoi(config_arg);
reconnect_timeout = atoi(config_arg);
break;
case OPT_DTLS_CIPHERS:
vpninfo->dtls_ciphers = keep_config_arg();
Expand Down Expand Up @@ -970,7 +969,7 @@ int main(int argc, char **argv)
if (fp)
fclose(fp);
}
vpn_mainloop(vpninfo);
openconnect_mainloop(vpninfo, reconnect_timeout, RECONNECT_INTERVAL_MIN);

if (sig_caught)
vpn_progress(vpninfo, PRG_INFO, _("Caught signal: %s\n"), strsignal(sig_caught));
Expand Down
7 changes: 6 additions & 1 deletion mainloop.c
Expand Up @@ -60,10 +60,15 @@ int queue_new_packet(struct pkt **q, void *buf, int len)
* = -EPERM, if the gateway sent 401 Unauthorized (cookie expired)
* < 0, for any other error
*/
int vpn_mainloop(struct openconnect_info *vpninfo)
int openconnect_mainloop(struct openconnect_info *vpninfo,
int reconnect_timeout,
int reconnect_interval)
{
int ret = 0;

vpninfo->reconnect_timeout = reconnect_timeout;
vpninfo->reconnect_interval = reconnect_interval;

if (vpninfo->cmd_fd != -1) {
FD_SET(vpninfo->cmd_fd, &vpninfo->select_rfds);
if (vpninfo->cmd_fd >= vpninfo->select_nfds)
Expand Down
1 change: 0 additions & 1 deletion openconnect-internal.h
Expand Up @@ -428,7 +428,6 @@ int openconnect_local_cert_md5(struct openconnect_info *vpninfo,

/* mainloop.c */
int vpn_add_pollfd(struct openconnect_info *vpninfo, int fd, short events);
int vpn_mainloop(struct openconnect_info *vpninfo);
int queue_new_packet(struct pkt **q, void *buf, int len);
void queue_packet(struct pkt **q, struct pkt *new);
int keepalive_action(struct keepalive_info *ka, int *timeout);
Expand Down
9 changes: 9 additions & 0 deletions openconnect.h
Expand Up @@ -170,6 +170,9 @@ struct oc_auth_form {
/* byte commands to write into the cmd_fd */
#define OC_CMD_CANCEL 'x'

#define RECONNECT_INTERVAL_MIN 10
#define RECONNECT_INTERVAL_MAX 100

struct openconnect_info;

#define OPENCONNECT_X509 void
Expand Down Expand Up @@ -257,6 +260,12 @@ int openconnect_setup_cmd_pipe(struct openconnect_info *vpninfo);

const char *openconnect_get_version(void);

/* Start the main loop; exits if OC_CMD_CANCEL is received on cmd_fd or
the remote site aborts. */
int openconnect_mainloop(struct openconnect_info *vpninfo,
int reconnect_timeout,
int reconnect_interval);

/* The first (privdata) argument to each of these functions is either
the privdata argument provided to openconnect_vpninfo_new_with_cbdata(),
or if that argument was NULL then it'll be the vpninfo itself. */
Expand Down

0 comments on commit 7237bd7

Please sign in to comment.