1*4b169a6bSchristos /* connect.c --- wrappers for Windows connect function
2*4b169a6bSchristos
3*4b169a6bSchristos Copyright (C) 2008-2022 Free Software Foundation, Inc.
4*4b169a6bSchristos
5*4b169a6bSchristos This file is free software: you can redistribute it and/or modify
6*4b169a6bSchristos it under the terms of the GNU Lesser General Public License as
7*4b169a6bSchristos published by the Free Software Foundation; either version 2.1 of the
8*4b169a6bSchristos License, or (at your option) any later version.
9*4b169a6bSchristos
10*4b169a6bSchristos This file is distributed in the hope that it will be useful,
11*4b169a6bSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of
12*4b169a6bSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13*4b169a6bSchristos GNU Lesser General Public License for more details.
14*4b169a6bSchristos
15*4b169a6bSchristos You should have received a copy of the GNU Lesser General Public License
16*4b169a6bSchristos along with this program. If not, see <https://www.gnu.org/licenses/>. */
17*4b169a6bSchristos
18*4b169a6bSchristos /* Written by Paolo Bonzini */
19*4b169a6bSchristos
20*4b169a6bSchristos #include <config.h>
21*4b169a6bSchristos
22*4b169a6bSchristos #define WIN32_LEAN_AND_MEAN
23*4b169a6bSchristos /* Get winsock2.h. */
24*4b169a6bSchristos #include <sys/socket.h>
25*4b169a6bSchristos
26*4b169a6bSchristos /* Get set_winsock_errno, FD_TO_SOCKET etc. */
27*4b169a6bSchristos #include "w32sock.h"
28*4b169a6bSchristos
29*4b169a6bSchristos #undef connect
30*4b169a6bSchristos
31*4b169a6bSchristos int
rpl_connect(int fd,const struct sockaddr * sockaddr,socklen_t len)32*4b169a6bSchristos rpl_connect (int fd, const struct sockaddr *sockaddr, socklen_t len)
33*4b169a6bSchristos {
34*4b169a6bSchristos SOCKET sock = FD_TO_SOCKET (fd);
35*4b169a6bSchristos
36*4b169a6bSchristos if (sock == INVALID_SOCKET)
37*4b169a6bSchristos {
38*4b169a6bSchristos errno = EBADF;
39*4b169a6bSchristos return -1;
40*4b169a6bSchristos }
41*4b169a6bSchristos else
42*4b169a6bSchristos {
43*4b169a6bSchristos int r = connect (sock, sockaddr, len);
44*4b169a6bSchristos if (r < 0)
45*4b169a6bSchristos {
46*4b169a6bSchristos /* EINPROGRESS is not returned by WinSock 2.0; for backwards
47*4b169a6bSchristos compatibility, connect(2) uses EWOULDBLOCK. */
48*4b169a6bSchristos if (WSAGetLastError () == WSAEWOULDBLOCK)
49*4b169a6bSchristos WSASetLastError (WSAEINPROGRESS);
50*4b169a6bSchristos
51*4b169a6bSchristos set_winsock_errno ();
52*4b169a6bSchristos }
53*4b169a6bSchristos
54*4b169a6bSchristos return r;
55*4b169a6bSchristos }
56*4b169a6bSchristos }
57