Skip to content

Commit

Permalink
use windows types and return codes for socket errors
Browse files Browse the repository at this point in the history
That is, use SOCKET instead of int for cmd_pipe, and return INVALID
socket for cmd_pipe.

Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
Nikos Mavrogiannopoulos authored and David Woodhouse committed Sep 15, 2014
1 parent 45e54f9 commit 714c740
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions compat.c
Expand Up @@ -338,13 +338,13 @@ WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* sockets must be closed with closesocket() regardless.
*/

int dumb_socketpair(int socks[2], int make_overlapped)
OPENCONNECT_CMD_SOCKET dumb_socketpair(OPENCONNECT_CMD_SOCKET socks[2], int make_overlapped)
{
union {
struct sockaddr_in inaddr;
struct sockaddr addr;
} a;
SOCKET listener;
OPENCONNECT_CMD_SOCKET listener;
int e;
socklen_t addrlen = sizeof(a.inaddr);
DWORD flags = (make_overlapped ? WSA_FLAG_OVERLAPPED : 0);
Expand Down
17 changes: 12 additions & 5 deletions library.c
Expand Up @@ -435,21 +435,28 @@ void openconnect_set_cancel_fd(struct openconnect_info *vpninfo, int fd)
vpninfo->cmd_fd = fd;
}

int openconnect_setup_cmd_pipe(struct openconnect_info *vpninfo)
#ifdef _WIN32
# define CMD_PIPE_ERR INVALID_SOCKET
#else
# define CMD_PIPE_ERR -EIO
#endif

OPENCONNECT_CMD_SOCKET openconnect_setup_cmd_pipe(struct openconnect_info *vpninfo)
{
int pipefd[2];
OPENCONNECT_CMD_SOCKET pipefd[2];

#ifdef _WIN32
if (dumb_socketpair(pipefd, 0))
return -EIO;
return CMD_PIPE_ERR;
#else
if (pipe(pipefd) < 0)
return -EIO;
return CMD_PIPE_ERR;
#endif

if (set_sock_nonblock(pipefd[0]) || set_sock_nonblock(pipefd[1])) {
close(pipefd[0]);
close(pipefd[1]);
return -EIO;
return CMD_PIPE_ERR;
}
vpninfo->cmd_fd = pipefd[0];
vpninfo->cmd_fd_write = pipefd[1];
Expand Down
4 changes: 3 additions & 1 deletion openconnect-internal.h
Expand Up @@ -527,9 +527,11 @@ void openconnect__win32_sock_init();
#undef inet_pton
#define inet_pton openconnect__win32_inet_pton
int openconnect__win32_inet_pton(int af, const char *src, void *dst);
int dumb_socketpair(int socks[2], int make_overlapped);
#define OPENCONNECT_CMD_SOCKET SOCKET
OPENCONNECT_CMD_SOCKET dumb_socketpair(OPENCONNECT_CMD_SOCKET socks[2], int make_overlapped);
#else
#define closesocket close
#define OPENCONNECT_CMD_SOCKET int
#ifndef O_BINARY
#define O_BINARY 0
#endif
Expand Down
7 changes: 6 additions & 1 deletion openconnect.h
Expand Up @@ -390,7 +390,12 @@ void openconnect_set_cancel_fd(struct openconnect_info *vpninfo, int fd);
to the library. This returns a file descriptor to the write side of
the pipe. Both sides will be closed by openconnect_vpninfo_free().
This replaces openconnect_set_cancel_fd(). */
int openconnect_setup_cmd_pipe(struct openconnect_info *vpninfo);
#ifdef _WIN32
SOCKET
#else
int
#endif
openconnect_setup_cmd_pipe(struct openconnect_info *vpninfo);

const char *openconnect_get_version(void);

Expand Down

0 comments on commit 714c740

Please sign in to comment.