Commit 60d4e180 authored by Kevin Cernekee's avatar Kevin Cernekee

Add new helper functions to support cmd_fd feature

Signed-off-by: default avatarKevin Cernekee <cernekee@gmail.com>
parent 5e4048b9
......@@ -298,6 +298,7 @@ struct openconnect_info {
int cmd_fd;
int cmd_fd_write;
int got_cancel_cmd;
struct pkt *incoming_queue;
struct pkt *outgoing_queue;
......@@ -403,7 +404,9 @@ const char *keystore_strerror(int err);
int keystore_fetch(const char *key, unsigned char **result);
#endif
void cmd_fd_set(struct openconnect_info *vpninfo, fd_set *fds, int *maxfd);
void check_cmd_fd(struct openconnect_info *vpninfo, fd_set *fds);
int is_cancel_pending(struct openconnect_info *vpninfo, fd_set *fds);
void poll_cmd_fd(struct openconnect_info *vpninfo, int timeout);
/* ${SSL_LIBRARY}.c */
int openconnect_SSL_gets(struct openconnect_info *vpninfo, char *buf, size_t len);
......
......@@ -167,6 +167,9 @@ struct oc_auth_form {
#define PRG_DEBUG 2
#define PRG_TRACE 3
/* byte commands to write into the cmd_fd */
#define OC_CMD_CANCEL 'x'
struct openconnect_info;
#define OPENCONNECT_X509 void
......
......@@ -530,7 +530,42 @@ void cmd_fd_set(struct openconnect_info *vpninfo, fd_set *fds, int *maxfd)
}
}
void check_cmd_fd(struct openconnect_info *vpninfo, fd_set *fds)
{
char cmd;
if (vpninfo->cmd_fd == -1 || !FD_ISSET(vpninfo->cmd_fd, fds))
return;
if (vpninfo->cmd_fd_write == -1) {
/* legacy openconnect_set_cancel_fd() users */
vpninfo->got_cancel_cmd = 1;
return;
}
if (read(vpninfo->cmd_fd, &cmd, 1) != 1)
return;
switch (cmd) {
case OC_CMD_CANCEL:
vpninfo->got_cancel_cmd = 1;
break;
}
}
int is_cancel_pending(struct openconnect_info *vpninfo, fd_set *fds)
{
return vpninfo->cmd_fd != -1 && FD_ISSET(vpninfo->cmd_fd, fds);
check_cmd_fd(vpninfo, fds);
return vpninfo->got_cancel_cmd;
}
void poll_cmd_fd(struct openconnect_info *vpninfo, int timeout)
{
fd_set rd_set;
int maxfd = 0;
struct timeval tv = { timeout, 0 };
FD_ZERO(&rd_set);
cmd_fd_set(vpninfo, &rd_set, &maxfd);
select(maxfd + 1, &rd_set, NULL, NULL, &tv);
check_cmd_fd(vpninfo, &rd_set);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment