Mercurial > gnulib
annotate lib/socket.c @ 40057:b06060465f09
maint: Run 'make update-copyright'
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 01 Jan 2019 00:25:11 +0100 |
parents | 10eb9086bea0 |
children |
rev | line source |
---|---|
10690
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
1 /* socket.c --- wrappers for Windows socket function |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
2 |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
3 Copyright (C) 2008-2019 Free Software Foundation, Inc. |
10690
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
4 |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
6 it under the terms of the GNU General Public License as published by |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
7 the Free Software Foundation; either version 3 of the License, or |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
8 (at your option) any later version. |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
9 |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
10 This program is distributed in the hope that it will be useful, |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
13 GNU General Public License for more details. |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
14 |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU General Public License |
19190 | 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
10690
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
17 |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
18 /* Written by Paolo Bonzini */ |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
19 |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
20 #include <config.h> |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
21 |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
22 #define WIN32_LEAN_AND_MEAN |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
23 /* Get winsock2.h. */ |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
24 #include <sys/socket.h> |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
25 |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
26 /* Get set_winsock_errno, FD_TO_SOCKET etc. */ |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
27 #include "w32sock.h" |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
28 |
11765
4b822ff432cf
Implicitly initialize the sockets library.
Bruno Haible <bruno@clisp.org>
parents:
10693
diff
changeset
|
29 #include "sockets.h" |
4b822ff432cf
Implicitly initialize the sockets library.
Bruno Haible <bruno@clisp.org>
parents:
10693
diff
changeset
|
30 |
10690
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
31 int |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
32 rpl_socket (int domain, int type, int protocol) |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
33 { |
11765
4b822ff432cf
Implicitly initialize the sockets library.
Bruno Haible <bruno@clisp.org>
parents:
10693
diff
changeset
|
34 SOCKET fh; |
4b822ff432cf
Implicitly initialize the sockets library.
Bruno Haible <bruno@clisp.org>
parents:
10693
diff
changeset
|
35 |
4b822ff432cf
Implicitly initialize the sockets library.
Bruno Haible <bruno@clisp.org>
parents:
10693
diff
changeset
|
36 gl_sockets_startup (SOCKETS_1_1); |
4b822ff432cf
Implicitly initialize the sockets library.
Bruno Haible <bruno@clisp.org>
parents:
10693
diff
changeset
|
37 |
10690
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
38 /* We have to use WSASocket() to create non-overlapped IO sockets. |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
39 Overlapped IO sockets cannot be used with read/write. */ |
11765
4b822ff432cf
Implicitly initialize the sockets library.
Bruno Haible <bruno@clisp.org>
parents:
10693
diff
changeset
|
40 fh = WSASocket (domain, type, protocol, NULL, 0, 0); |
10690
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
41 |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
42 if (fh == INVALID_SOCKET) |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
43 { |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
44 set_winsock_errno (); |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
45 return -1; |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
46 } |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
47 else |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
48 return SOCKET_TO_FD (fh); |
01f3623813da
Split winsock.c into many smaller files.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
49 } |