~ubuntu-branches/ubuntu/trusty/gnutls26/trusty

« back to all changes in this revision

Viewing changes to lib/gl/sockets.c

  • Committer: Package Import Robot
  • Author(s): Andreas Metzler
  • Date: 2011-10-01 15:28:13 UTC
  • mfrom: (12.1.20 sid)
  • Revision ID: package-import@ubuntu.com-20111001152813-yygm1c4cxonfxhzy
* New upstream version.
  + Allow CA importing of 0 certificates to succeed. Closes: #640639
* Add libp11-kit-dev to libgnutls-dev dependencies. (see #643811)
* [20_guiledocstring.diff] guile: Fix docstring extraction with CPP 4.5+.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* sockets.c --- wrappers for Windows socket functions
2
2
 
3
 
   Copyright (C) 2008-2010 Free Software Foundation, Inc.
 
3
   Copyright (C) 2008-2011 Free Software Foundation, Inc.
4
4
 
5
5
   This program is free software: you can redistribute it and/or modify
6
6
   it under the terms of the GNU Lesser General Public License as published by
27
27
/* This includes winsock2.h on MinGW. */
28
28
# include <sys/socket.h>
29
29
 
30
 
# include "close-hook.h"
 
30
# include "fd-hook.h"
31
31
 
32
32
/* Get set_winsock_errno, FD_TO_SOCKET etc. */
33
33
# include "w32sock.h"
34
34
 
35
35
static int
36
 
close_fd_maybe_socket (int fd, const struct close_hook *remaining_list)
 
36
close_fd_maybe_socket (const struct fd_hook *remaining_list,
 
37
                       gl_close_fn primary,
 
38
                       int fd)
37
39
{
 
40
  /* Note about multithread-safety: There is a race condition where, between
 
41
     our calls to closesocket() and the primary close(), some other thread
 
42
     could make system calls that allocate precisely the same HANDLE value
 
43
     as sock; then the primary close() would call CloseHandle() on it.  */
38
44
  SOCKET sock;
39
45
  WSANETWORKEVENTS ev;
40
46
 
64
70
    }
65
71
  else
66
72
    /* Some other type of file descriptor.  */
67
 
    return execute_close_hooks (fd, remaining_list);
68
 
}
69
 
 
70
 
static struct close_hook close_sockets_hook;
 
73
    return execute_close_hooks (remaining_list, primary, fd);
 
74
}
 
75
 
 
76
static int
 
77
ioctl_fd_maybe_socket (const struct fd_hook *remaining_list,
 
78
                       gl_ioctl_fn primary,
 
79
                       int fd, int request, void *arg)
 
80
{
 
81
  SOCKET sock;
 
82
  WSANETWORKEVENTS ev;
 
83
 
 
84
  /* Test whether fd refers to a socket.  */
 
85
  sock = FD_TO_SOCKET (fd);
 
86
  ev.lNetworkEvents = 0xDEADBEEF;
 
87
  WSAEnumNetworkEvents (sock, NULL, &ev);
 
88
  if (ev.lNetworkEvents != 0xDEADBEEF)
 
89
    {
 
90
      /* fd refers to a socket.  */
 
91
      if (ioctlsocket (sock, request, arg) < 0)
 
92
        {
 
93
          set_winsock_errno ();
 
94
          return -1;
 
95
        }
 
96
      else
 
97
        return 0;
 
98
    }
 
99
  else
 
100
    /* Some other type of file descriptor.  */
 
101
    return execute_ioctl_hooks (remaining_list, primary, fd, request, arg);
 
102
}
 
103
 
 
104
static struct fd_hook fd_sockets_hook;
71
105
 
72
106
static int initialized_sockets_version /* = 0 */;
73
107
 
90
124
        return 2;
91
125
 
92
126
      if (initialized_sockets_version == 0)
93
 
        register_close_hook (close_fd_maybe_socket, &close_sockets_hook);
 
127
        register_fd_hook (close_fd_maybe_socket, ioctl_fd_maybe_socket,
 
128
                          &fd_sockets_hook);
94
129
 
95
130
      initialized_sockets_version = version;
96
131
    }
107
142
 
108
143
  initialized_sockets_version = 0;
109
144
 
110
 
  unregister_close_hook (&close_sockets_hook);
 
145
  unregister_fd_hook (&fd_sockets_hook);
111
146
 
112
147
  err = WSACleanup ();
113
148
  if (err != 0)