Commit 714c740d authored by Nikos Mavrogiannopoulos's avatar Nikos Mavrogiannopoulos Committed by David Woodhouse

use windows types and return codes for socket errors

That is, use SOCKET instead of int for cmd_pipe, and return INVALID
socket for cmd_pipe.
Signed-off-by: default avatarNikos Mavrogiannopoulos <nmav@redhat.com>
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent 45e54f92
......@@ -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);
......
......@@ -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];
......
......@@ -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
......
......@@ -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);
......
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