1*4b169a6bSchristos /* accept.c --- wrappers for Windows accept 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 accept
30*4b169a6bSchristos
31*4b169a6bSchristos int
rpl_accept(int fd,struct sockaddr * addr,socklen_t * addrlen)32*4b169a6bSchristos rpl_accept (int fd, struct sockaddr *addr, socklen_t *addrlen)
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 SOCKET fh = accept (sock, addr, addrlen);
44*4b169a6bSchristos if (fh == INVALID_SOCKET)
45*4b169a6bSchristos {
46*4b169a6bSchristos set_winsock_errno ();
47*4b169a6bSchristos return -1;
48*4b169a6bSchristos }
49*4b169a6bSchristos else
50*4b169a6bSchristos return SOCKET_TO_FD (fh);
51*4b169a6bSchristos }
52*4b169a6bSchristos }
53