Home | History | Annotate | Line # | Download | only in import
      1  1.1  christos /* socket.c --- wrappers for Windows socket function
      2  1.1  christos 
      3  1.1  christos    Copyright (C) 2008-2022 Free Software Foundation, Inc.
      4  1.1  christos 
      5  1.1  christos    This file is free software: you can redistribute it and/or modify
      6  1.1  christos    it under the terms of the GNU Lesser General Public License as
      7  1.1  christos    published by the Free Software Foundation; either version 2.1 of the
      8  1.1  christos    License, or (at your option) any later version.
      9  1.1  christos 
     10  1.1  christos    This file is distributed in the hope that it will be useful,
     11  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  1.1  christos    GNU Lesser General Public License for more details.
     14  1.1  christos 
     15  1.1  christos    You should have received a copy of the GNU Lesser General Public License
     16  1.1  christos    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
     17  1.1  christos 
     18  1.1  christos /* Written by Paolo Bonzini */
     19  1.1  christos 
     20  1.1  christos #include <config.h>
     21  1.1  christos 
     22  1.1  christos #define WIN32_LEAN_AND_MEAN
     23  1.1  christos /* Get winsock2.h. */
     24  1.1  christos #include <sys/socket.h>
     25  1.1  christos 
     26  1.1  christos /* Get set_winsock_errno, FD_TO_SOCKET etc. */
     27  1.1  christos #include "w32sock.h"
     28  1.1  christos 
     29  1.1  christos #include "sockets.h"
     30  1.1  christos 
     31  1.1  christos /* Don't assume that UNICODE is defined.  */
     32  1.1  christos #undef WSASocket
     33  1.1  christos #define WSASocket WSASocketW
     34  1.1  christos 
     35  1.1  christos int
     36  1.1  christos rpl_socket (int domain, int type, int protocol)
     37  1.1  christos {
     38  1.1  christos   SOCKET fh;
     39  1.1  christos 
     40  1.1  christos   gl_sockets_startup (SOCKETS_1_1);
     41  1.1  christos 
     42  1.1  christos   /* We have to use WSASocket() to create non-overlapped IO sockets.
     43  1.1  christos      Overlapped IO sockets cannot be used with read/write.  */
     44  1.1  christos   fh = WSASocket (domain, type, protocol, NULL, 0, 0);
     45  1.1  christos 
     46  1.1  christos   if (fh == INVALID_SOCKET)
     47  1.1  christos     {
     48  1.1  christos       set_winsock_errno ();
     49  1.1  christos       return -1;
     50  1.1  christos     }
     51  1.1  christos   else
     52  1.1  christos     return SOCKET_TO_FD (fh);
     53  1.1  christos }
     54