Mercurial > cpython-lru_cache-weakref
annotate Modules/socketmodule.h @ 24042:63fbbed10714 legacy-trunk
Simplify HTTPSConnection constructor.
See discussion in SF bug 458463.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Fri, 28 Jun 2002 23:38:14 +0000 |
| parents | 203d1412a7e8 |
| children | ac487a7f7f2c |
| rev | line source |
|---|---|
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1 /* Socket module header file */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3 /* Includes needed for the sockaddr_* symbols below */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
4 #ifndef MS_WINDOWS |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
5 # include <sys/socket.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
6 # include <netinet/in.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
7 # if !(defined(__BEOS__) || defined(__CYGWIN__) || (defined(PYOS_OS2) && defined(PYCC_VACPP))) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
8 # include <netinet/tcp.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
9 # endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
10 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
11 #else /* MS_WINDOWS */ |
|
22096
9e5ff6747437
Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents:
22041
diff
changeset
|
12 #if _MSC_VER >= 1300 |
|
9e5ff6747437
Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents:
22041
diff
changeset
|
13 # include <winsock2.h> |
|
9e5ff6747437
Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents:
22041
diff
changeset
|
14 # include <ws2tcpip.h> |
|
9e5ff6747437
Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents:
22041
diff
changeset
|
15 # define HAVE_ADDRINFO |
|
9e5ff6747437
Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents:
22041
diff
changeset
|
16 # define HAVE_SOCKADDR_STORAGE |
|
9e5ff6747437
Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents:
22041
diff
changeset
|
17 # define HAVE_GETADDRINFO |
|
9e5ff6747437
Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents:
22041
diff
changeset
|
18 # define HAVE_GETNAMEINFO |
|
9e5ff6747437
Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents:
22041
diff
changeset
|
19 # define ENABLE_IPV6 |
|
9e5ff6747437
Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents:
22041
diff
changeset
|
20 #else |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
21 # include <winsock.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
22 #endif |
|
22096
9e5ff6747437
Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents:
22041
diff
changeset
|
23 #endif |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
24 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
25 #ifdef HAVE_SYS_UN_H |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
26 # include <sys/un.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
27 #else |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
28 # undef AF_UNIX |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
29 #endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
30 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
31 #ifdef HAVE_NETPACKET_PACKET_H |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
32 # include <sys/ioctl.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
33 # include <net/if.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
34 # include <netpacket/packet.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
35 #endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
36 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
37 #ifndef Py__SOCKET_H |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
38 #define Py__SOCKET_H |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
39 #ifdef __cplusplus |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
40 extern "C" { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
41 #endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
42 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
43 /* Python module and C API name */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
44 #define PySocket_MODULE_NAME "_socket" |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
45 #define PySocket_CAPI_NAME "CAPI" |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
46 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
47 /* Abstract the socket file descriptor type */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
48 #ifdef MS_WINDOWS |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
49 typedef SOCKET SOCKET_T; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
50 # ifdef MS_WIN64 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
51 # define SIZEOF_SOCKET_T 8 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
52 # else |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
53 # define SIZEOF_SOCKET_T 4 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
54 # endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
55 #else |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
56 typedef int SOCKET_T; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
57 # define SIZEOF_SOCKET_T SIZEOF_INT |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
58 #endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
59 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
60 /* The object holding a socket. It holds some extra information, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
61 like the address family, which is used to decode socket address |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
62 arguments properly. */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
63 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
64 typedef struct { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
65 PyObject_HEAD |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
66 SOCKET_T sock_fd; /* Socket file descriptor */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
67 int sock_family; /* Address family, e.g., AF_INET */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
68 int sock_type; /* Socket type, e.g., SOCK_STREAM */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
69 int sock_proto; /* Protocol type, usually 0 */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
70 union sock_addr { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
71 struct sockaddr_in in; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
72 #ifdef AF_UNIX |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
73 struct sockaddr_un un; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
74 #endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
75 #ifdef ENABLE_IPV6 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
76 struct sockaddr_in6 in6; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
77 struct sockaddr_storage storage; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
78 #endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
79 #ifdef HAVE_NETPACKET_PACKET_H |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
80 struct sockaddr_ll ll; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
81 #endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
82 } sock_addr; |
|
21969
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
83 PyObject *(*errorhandler)(void); /* Error handler; checks |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
84 errno, returns NULL and |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
85 sets a Python exception */ |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23724
diff
changeset
|
86 double sock_timeout; /* Operation timeout in seconds; |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23724
diff
changeset
|
87 0.0 means non-blocking */ |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
88 } PySocketSockObject; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
89 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
90 /* --- C API ----------------------------------------------------*/ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
91 |
|
22041
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
92 /* Short explanation of what this C API export mechanism does |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
93 and how it works: |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
94 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
95 The _ssl module needs access to the type object defined in |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
96 the _socket module. Since cross-DLL linking introduces a lot of |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
97 problems on many platforms, the "trick" is to wrap the |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
98 C API of a module in a struct which then gets exported to |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
99 other modules via a PyCObject. |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
100 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
101 The code in socketmodule.c defines this struct (which currently |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
102 only contains the type object reference, but could very |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
103 well also include other C APIs needed by other modules) |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
104 and exports it as PyCObject via the module dictionary |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
105 under the name "CAPI". |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
106 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
107 Other modules can now include the socketmodule.h file |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
108 which defines the needed C APIs to import and set up |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
109 a static copy of this struct in the importing module. |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
110 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
111 After initialization, the importing module can then |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
112 access the C APIs from the _socket module by simply |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
113 referring to the static struct, e.g. |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
114 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
115 Load _socket module and its C API; this sets up the global |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
116 PySocketModule: |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
117 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
118 if (PySocketModule_ImportModuleAndAPI()) |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
119 return; |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
120 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
121 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
122 Now use the C API as if it were defined in the using |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
123 module: |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
124 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
125 if (!PyArg_ParseTuple(args, "O!|zz:ssl", |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
126 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
127 PySocketModule.Sock_Type, |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
128 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
129 (PyObject*)&Sock, |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
130 &key_file, &cert_file)) |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
131 return NULL; |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
132 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
133 Support could easily be extended to export more C APIs/symbols |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
134 this way. Currently, only the type object is exported, |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
135 other candidates would be socket constructors and socket |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
136 access functions. |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
137 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
138 */ |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
139 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
140 /* C API for usage by other Python modules */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
141 typedef struct { |
|
21969
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
142 PyTypeObject *Sock_Type; |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
143 } PySocketModule_APIObject; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
144 |
|
21969
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
145 /* XXX The net effect of the following appears to be to define a function |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
146 XXX named PySocketModule_APIObject in _ssl.c. It's unclear why it isn't |
|
22041
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
147 XXX defined there directly. |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
148 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
149 >>> It's defined here because other modules might also want to use |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
150 >>> the C API. |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
151 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
152 */ |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
153 #ifndef PySocket_BUILDING_SOCKET |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
154 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
155 /* --- C API ----------------------------------------------------*/ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
156 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
157 /* Interfacestructure to C API for other modules. |
| 23724 | 158 Call PySocketModule_ImportModuleAndAPI() to initialize this |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
159 structure. After that usage is simple: |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
160 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
161 if (!PyArg_ParseTuple(args, "O!|zz:ssl", |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
162 &PySocketModule.Sock_Type, (PyObject*)&Sock, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
163 &key_file, &cert_file)) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
164 return NULL; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
165 ... |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
166 */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
167 |
|
21969
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
168 static |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
169 PySocketModule_APIObject PySocketModule; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
170 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
171 /* You *must* call this before using any of the functions in |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
172 PySocketModule and check its outcome; otherwise all accesses will |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
173 result in a segfault. Returns 0 on success. */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
174 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
175 #ifndef DPRINTF |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
176 # define DPRINTF if (0) printf |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
177 #endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
178 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
179 static |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
180 int PySocketModule_ImportModuleAndAPI(void) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
181 { |
|
21969
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
182 PyObject *mod = 0, *v = 0; |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
183 char *apimodule = PySocket_MODULE_NAME; |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
184 char *apiname = PySocket_CAPI_NAME; |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
185 void *api; |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
186 |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
187 DPRINTF("Importing the %s C API...\n", apimodule); |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
188 mod = PyImport_ImportModule(apimodule); |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
189 if (mod == NULL) |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
190 goto onError; |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
191 DPRINTF(" %s package found\n", apimodule); |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
192 v = PyObject_GetAttrString(mod, apiname); |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
193 if (v == NULL) |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
194 goto onError; |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
195 Py_DECREF(mod); |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
196 DPRINTF(" API object %s found\n", apiname); |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
197 api = PyCObject_AsVoidPtr(v); |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
198 if (api == NULL) |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
199 goto onError; |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
200 Py_DECREF(v); |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
201 memcpy(&PySocketModule, api, sizeof(PySocketModule)); |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
202 DPRINTF(" API object loaded and initialized.\n"); |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
203 return 0; |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
204 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
205 onError: |
|
21969
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
206 DPRINTF(" not found.\n"); |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
207 Py_XDECREF(mod); |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
208 Py_XDECREF(v); |
|
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
209 return -1; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
210 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
211 |
|
21969
72c95448ee4b
For readability, switch to tab indents; was using a mix of tab indents,
Tim Peters <tim.peters@gmail.com>
parents:
21959
diff
changeset
|
212 #endif /* !PySocket_BUILDING_SOCKET */ |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
213 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
214 #ifdef __cplusplus |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
215 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
216 #endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
217 #endif /* !Py__SOCKET_H */ |
