Mercurial > hg > octave-kai > gnulib-hg
annotate lib/sockets.c @ 15752:b86e9061a6d0
New module 'msvc-nothrow'. Makes _get_osfhandle safe on MSVC 9.
* lib/msvc-nothrow.h: New file.
* lib/msvc-nothrow.c: New file.
* m4/msvc-nothrow.m4: New file.
* modules/msvc-nothrow: New file.
* lib/dup2.c: Include msvc-nothrow.h.
(rpl_dup2): No need to protect _get_osfhandle call here.
* lib/accept4.c: Include msvc-nothrow.h.
* lib/error.c: Likewise.
* lib/fcntl.c: Likewise.
* lib/lseek.c: Likewise.
* lib/nonblocking.c: Likewise.
* lib/poll.c: Likewise.
* lib/read.c: Likewise.
* lib/select.c: Likewise.
* lib/sockets.h: Likewise.
* lib/sockets.c: Likewise.
* lib/stdio-read.c: Likewise.
* lib/stdio-write.c: Likewise.
* lib/write.c: Likewise.
* lib/w32sock.h: Likewise.
* lib/w32spawn.h: Likewise.
* lib/flock.c: Include msvc-nothrow.h instead of <io.h>.
* lib/fsync.c: Likewise.
* lib/isapipe.c: Likewise.
* modules/dup2 (Depends-on): Add msvc-nothrow.
* modules/accept4 (Depends-on): Likewise.
* modules/error (Depends-on): Likewise.
* modules/fcntl (Depends-on): Likewise.
* modules/lseek (Depends-on): Likewise.
* modules/nonblocking (Depends-on): Likewise.
* modules/poll (Depends-on): Likewise.
* modules/read (Depends-on): Likewise.
* modules/select (Depends-on): Likewise.
* modules/sockets (Depends-on): Likewise.
* modules/sigpipe (Depends-on): Likewise.
* modules/write (Depends-on): Likewise.
* modules/accept (Depends-on): Likewise.
* modules/bind (Depends-on): Likewise.
* modules/connect (Depends-on): Likewise.
* modules/gethostname (Depends-on): Likewise.
* modules/getpeername (Depends-on): Likewise.
* modules/getsockname (Depends-on): Likewise.
* modules/getsockopt (Depends-on): Likewise.
* modules/ioctl (Depends-on): Likewise.
* modules/listen (Depends-on): Likewise.
* modules/recv (Depends-on): Likewise.
* modules/recvfrom (Depends-on): Likewise.
* modules/send (Depends-on): Likewise.
* modules/sendto (Depends-on): Likewise.
* modules/setsockopt (Depends-on): Likewise.
* modules/shutdown (Depends-on): Likewise.
* modules/socket (Depends-on): Likewise.
* modules/execute (Depends-on): Likewise.
* modules/spawn-pipe (Depends-on): Likewise.
* modules/flock (Depends-on): Likewise.
* modules/fsync (Depends-on): Likewise.
* modules/isapipe (Depends-on): Likewise.
* tests/test-cloexec.c: Include msvc-nothrow.h.
* tests/test-dup-safer.c: Likewise.
* tests/test-dup2.c: Likewise.
* tests/test-dup3.c: Likewise.
* tests/test-fcntl.c: Likewise.
* tests/test-pipe.c: Likewise.
* tests/test-pipe2.c: Likewise.
* modules/cloexec-tests (Depends-on): Add msvc-nothrow.
* modules/unistd-safer-tests (Depends-on): Likewise.
* modules/dup2-tests (Depends-on): Likewise.
* modules/dup3-tests (Depends-on): Likewise.
* modules/fcntl-tests (Depends-on): Likewise.
* modules/pipe-posix-tests (Depends-on): Likewise.
* modules/pipe2-tests (Depends-on): Likewise.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 23 Sep 2011 21:38:44 +0200 |
parents | 3e7ea0014c67 |
children | 8250f2777afc |
rev | line source |
---|---|
9642 | 1 /* sockets.c --- wrappers for Windows socket functions |
2 | |
14079
97fc9a21a8fb
maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents:
12559
diff
changeset
|
3 Copyright (C) 2008-2011 Free Software Foundation, Inc. |
9642 | 4 |
5 This program is free software: you can redistribute it and/or modify | |
6 it under the terms of the GNU General Public License as published by | |
7 the Free Software Foundation; either version 3 of the License, or | |
8 (at your option) any later version. | |
9 | |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | |
18 /* Written by Simon Josefsson */ | |
19 | |
20 #include <config.h> | |
21 | |
11416
1b59f3d3ede6
Make sockets.h self-contained.
Bruno Haible <bruno@clisp.org>
parents:
9642
diff
changeset
|
22 /* Specification. */ |
1b59f3d3ede6
Make sockets.h self-contained.
Bruno Haible <bruno@clisp.org>
parents:
9642
diff
changeset
|
23 #include "sockets.h" |
1b59f3d3ede6
Make sockets.h self-contained.
Bruno Haible <bruno@clisp.org>
parents:
9642
diff
changeset
|
24 |
11426
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
25 #if WINDOWS_SOCKETS |
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
26 |
9642 | 27 /* This includes winsock2.h on MinGW. */ |
12209
31e5813d01e1
sockets: avoid compiler warning
Eric Blake <ebb9@byu.net>
parents:
11764
diff
changeset
|
28 # include <sys/socket.h> |
9642 | 29 |
14595
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
30 # include "fd-hook.h" |
15752
b86e9061a6d0
New module 'msvc-nothrow'. Makes _get_osfhandle safe on MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
14726
diff
changeset
|
31 # include "msvc-nothrow.h" |
11426
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
32 |
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
33 /* Get set_winsock_errno, FD_TO_SOCKET etc. */ |
12209
31e5813d01e1
sockets: avoid compiler warning
Eric Blake <ebb9@byu.net>
parents:
11764
diff
changeset
|
34 # include "w32sock.h" |
11426
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
35 |
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
36 static int |
14595
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
37 close_fd_maybe_socket (const struct fd_hook *remaining_list, |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
38 gl_close_fn primary, |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
39 int fd) |
11426
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
40 { |
14726
3e7ea0014c67
fclose: Fix possible link error.
Bruno Haible <bruno@clisp.org>
parents:
14612
diff
changeset
|
41 /* Note about multithread-safety: There is a race condition where, between |
3e7ea0014c67
fclose: Fix possible link error.
Bruno Haible <bruno@clisp.org>
parents:
14612
diff
changeset
|
42 our calls to closesocket() and the primary close(), some other thread |
3e7ea0014c67
fclose: Fix possible link error.
Bruno Haible <bruno@clisp.org>
parents:
14612
diff
changeset
|
43 could make system calls that allocate precisely the same HANDLE value |
3e7ea0014c67
fclose: Fix possible link error.
Bruno Haible <bruno@clisp.org>
parents:
14612
diff
changeset
|
44 as sock; then the primary close() would call CloseHandle() on it. */ |
11426
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
45 SOCKET sock; |
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
46 WSANETWORKEVENTS ev; |
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
47 |
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
48 /* Test whether fd refers to a socket. */ |
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
49 sock = FD_TO_SOCKET (fd); |
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
50 ev.lNetworkEvents = 0xDEADBEEF; |
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
51 WSAEnumNetworkEvents (sock, NULL, &ev); |
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
52 if (ev.lNetworkEvents != 0xDEADBEEF) |
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
53 { |
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
54 /* fd refers to a socket. */ |
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
55 /* FIXME: other applications, like squid, use an undocumented |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12209
diff
changeset
|
56 _free_osfhnd free function. But this is not enough: The 'osfile' |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12209
diff
changeset
|
57 flags for fd also needs to be cleared, but it is hard to access it. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12209
diff
changeset
|
58 Instead, here we just close twice the file descriptor. */ |
11426
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
59 if (closesocket (sock)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12209
diff
changeset
|
60 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12209
diff
changeset
|
61 set_winsock_errno (); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12209
diff
changeset
|
62 return -1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12209
diff
changeset
|
63 } |
11426
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
64 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12209
diff
changeset
|
65 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12209
diff
changeset
|
66 /* This call frees the file descriptor and does a |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12209
diff
changeset
|
67 CloseHandle ((HANDLE) _get_osfhandle (fd)), which fails. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12209
diff
changeset
|
68 _close (fd); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12209
diff
changeset
|
69 return 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12209
diff
changeset
|
70 } |
11426
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
71 } |
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
72 else |
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
73 /* Some other type of file descriptor. */ |
14595
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
74 return execute_close_hooks (remaining_list, primary, fd); |
11426
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
75 } |
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
76 |
14595
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
77 static int |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
78 ioctl_fd_maybe_socket (const struct fd_hook *remaining_list, |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
79 gl_ioctl_fn primary, |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
80 int fd, int request, void *arg) |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
81 { |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
82 SOCKET sock; |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
83 WSANETWORKEVENTS ev; |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
84 |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
85 /* Test whether fd refers to a socket. */ |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
86 sock = FD_TO_SOCKET (fd); |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
87 ev.lNetworkEvents = 0xDEADBEEF; |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
88 WSAEnumNetworkEvents (sock, NULL, &ev); |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
89 if (ev.lNetworkEvents != 0xDEADBEEF) |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
90 { |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
91 /* fd refers to a socket. */ |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
92 if (ioctlsocket (sock, request, arg) < 0) |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
93 { |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
94 set_winsock_errno (); |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
95 return -1; |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
96 } |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
97 else |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
98 return 0; |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
99 } |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
100 else |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
101 /* Some other type of file descriptor. */ |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
102 return execute_ioctl_hooks (remaining_list, primary, fd, request, arg); |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
103 } |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
104 |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
105 static struct fd_hook fd_sockets_hook; |
11426
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
106 |
11764
57245c9661b9
Allow multiple calls to gl_sockets_startup.
Bruno Haible <bruno@clisp.org>
parents:
11426
diff
changeset
|
107 static int initialized_sockets_version /* = 0 */; |
57245c9661b9
Allow multiple calls to gl_sockets_startup.
Bruno Haible <bruno@clisp.org>
parents:
11426
diff
changeset
|
108 |
12209
31e5813d01e1
sockets: avoid compiler warning
Eric Blake <ebb9@byu.net>
parents:
11764
diff
changeset
|
109 #endif /* WINDOWS_SOCKETS */ |
11426
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
110 |
14612
6ef4f1f39105
Revert "use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE"
Jim Meyering <meyering@redhat.com>
parents:
14610
diff
changeset
|
111 int |
12482
11bc92a9e2bc
gnulib-common: prefer _GL_UNUSED over _UNUSED_PARAMETER_
Eric Blake <ebb9@byu.net>
parents:
12421
diff
changeset
|
112 gl_sockets_startup (int version _GL_UNUSED) |
9642 | 113 { |
114 #if WINDOWS_SOCKETS | |
11764
57245c9661b9
Allow multiple calls to gl_sockets_startup.
Bruno Haible <bruno@clisp.org>
parents:
11426
diff
changeset
|
115 if (version > initialized_sockets_version) |
57245c9661b9
Allow multiple calls to gl_sockets_startup.
Bruno Haible <bruno@clisp.org>
parents:
11426
diff
changeset
|
116 { |
57245c9661b9
Allow multiple calls to gl_sockets_startup.
Bruno Haible <bruno@clisp.org>
parents:
11426
diff
changeset
|
117 WSADATA data; |
57245c9661b9
Allow multiple calls to gl_sockets_startup.
Bruno Haible <bruno@clisp.org>
parents:
11426
diff
changeset
|
118 int err; |
57245c9661b9
Allow multiple calls to gl_sockets_startup.
Bruno Haible <bruno@clisp.org>
parents:
11426
diff
changeset
|
119 |
57245c9661b9
Allow multiple calls to gl_sockets_startup.
Bruno Haible <bruno@clisp.org>
parents:
11426
diff
changeset
|
120 err = WSAStartup (version, &data); |
57245c9661b9
Allow multiple calls to gl_sockets_startup.
Bruno Haible <bruno@clisp.org>
parents:
11426
diff
changeset
|
121 if (err != 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12209
diff
changeset
|
122 return 1; |
9642 | 123 |
11764
57245c9661b9
Allow multiple calls to gl_sockets_startup.
Bruno Haible <bruno@clisp.org>
parents:
11426
diff
changeset
|
124 if (data.wVersion < version) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12209
diff
changeset
|
125 return 2; |
9642 | 126 |
11764
57245c9661b9
Allow multiple calls to gl_sockets_startup.
Bruno Haible <bruno@clisp.org>
parents:
11426
diff
changeset
|
127 if (initialized_sockets_version == 0) |
14595
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
128 register_fd_hook (close_fd_maybe_socket, ioctl_fd_maybe_socket, |
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
129 &fd_sockets_hook); |
11426
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
130 |
11764
57245c9661b9
Allow multiple calls to gl_sockets_startup.
Bruno Haible <bruno@clisp.org>
parents:
11426
diff
changeset
|
131 initialized_sockets_version = version; |
57245c9661b9
Allow multiple calls to gl_sockets_startup.
Bruno Haible <bruno@clisp.org>
parents:
11426
diff
changeset
|
132 } |
9642 | 133 #endif |
134 | |
135 return 0; | |
136 } | |
137 | |
138 int | |
139 gl_sockets_cleanup (void) | |
140 { | |
141 #if WINDOWS_SOCKETS | |
142 int err; | |
143 | |
11764
57245c9661b9
Allow multiple calls to gl_sockets_startup.
Bruno Haible <bruno@clisp.org>
parents:
11426
diff
changeset
|
144 initialized_sockets_version = 0; |
57245c9661b9
Allow multiple calls to gl_sockets_startup.
Bruno Haible <bruno@clisp.org>
parents:
11426
diff
changeset
|
145 |
14595
32d72ffe29dd
ioctl: Remove link dependency on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
146 unregister_fd_hook (&fd_sockets_hook); |
11426
d40b890c5200
Remove dependency from 'close' module to -lws2_32 on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
11416
diff
changeset
|
147 |
9642 | 148 err = WSACleanup (); |
149 if (err != 0) | |
150 return 1; | |
151 #endif | |
152 | |
153 return 0; | |
154 } |