annotate Modules/socketmodule.h @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents f714af60508d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 23815
diff changeset
5 #ifdef __VMS
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 23815
diff changeset
6 # include <socket.h>
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 23815
diff changeset
7 # else
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 23815
diff changeset
8 # include <sys/socket.h>
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 23815
diff changeset
9 # 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
10 # include <netinet/in.h>
79475
dea15868963f #16135: Removal of OS/2 support (Modules/*)
Jesus Cea <jcea@jcea.es>
parents: 74741
diff changeset
11 # if !defined(__CYGWIN__)
21959
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
12 # 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
13 # endif
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
14
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
15 #else /* MS_WINDOWS */
22096
9e5ff6747437 Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents: 22041
diff changeset
16 # include <winsock2.h>
9e5ff6747437 Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents: 22041
diff changeset
17 # include <ws2tcpip.h>
47667
b1f4ea4eb555 Merged revisions 64214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44568
diff changeset
18 /* VC6 is shipped with old platform headers, and does not have MSTcpIP.h
b1f4ea4eb555 Merged revisions 64214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44568
diff changeset
19 * Separate SDKs have all the functions we want, but older ones don't have
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
20 * any version information.
47718
96bff7e137fb Merged revisions 64267-64272 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47667
diff changeset
21 * I use SIO_GET_MULTICAST_FILTER to detect a decent SDK.
47667
b1f4ea4eb555 Merged revisions 64214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44568
diff changeset
22 */
47718
96bff7e137fb Merged revisions 64267-64272 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47667
diff changeset
23 # ifdef SIO_GET_MULTICAST_FILTER
47667
b1f4ea4eb555 Merged revisions 64214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44568
diff changeset
24 # include <MSTcpIP.h> /* for SIO_RCVALL */
b1f4ea4eb555 Merged revisions 64214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44568
diff changeset
25 # define HAVE_ADDRINFO
b1f4ea4eb555 Merged revisions 64214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44568
diff changeset
26 # define HAVE_SOCKADDR_STORAGE
b1f4ea4eb555 Merged revisions 64214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44568
diff changeset
27 # define HAVE_GETADDRINFO
b1f4ea4eb555 Merged revisions 64214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44568
diff changeset
28 # define HAVE_GETNAMEINFO
b1f4ea4eb555 Merged revisions 64214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44568
diff changeset
29 # define ENABLE_IPV6
b1f4ea4eb555 Merged revisions 64214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44568
diff changeset
30 # else
b1f4ea4eb555 Merged revisions 64214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44568
diff changeset
31 typedef int socklen_t;
b1f4ea4eb555 Merged revisions 64214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44568
diff changeset
32 # endif /* IPPROTO_IPV6 */
b1f4ea4eb555 Merged revisions 64214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44568
diff changeset
33 #endif /* MS_WINDOWS */
21959
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
34
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
35 #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
36 # 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
37 #else
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
38 # 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
39 #endif
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
40
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 35551
diff changeset
41 #ifdef HAVE_LINUX_NETLINK_H
36298
9eeaa33f9640 Get socketmodule to build after adding netlink support.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36286
diff changeset
42 # ifdef HAVE_ASM_TYPES_H
9eeaa33f9640 Get socketmodule to build after adding netlink support.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36286
diff changeset
43 # include <asm/types.h>
9eeaa33f9640 Get socketmodule to build after adding netlink support.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36286
diff changeset
44 # endif
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 35551
diff changeset
45 # include <linux/netlink.h>
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 35551
diff changeset
46 #else
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 35551
diff changeset
47 # undef AF_NETLINK
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 35551
diff changeset
48 #endif
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 35551
diff changeset
49
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
50 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
51 #include <bluetooth/bluetooth.h>
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
52 #include <bluetooth/rfcomm.h>
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
53 #include <bluetooth/l2cap.h>
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
54 #include <bluetooth/sco.h>
40842
90e22fea8363 Patch #1432399: Add HCI sockets.
Martin v. Löwis <martin@v.loewis.de>
parents: 40416
diff changeset
55 #include <bluetooth/hci.h>
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
56 #endif
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
57
31444
a282801b06b6 Add FreeBSD support for bluetooth sockets. (SF Patch #888148)
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
58 #ifdef HAVE_BLUETOOTH_H
a282801b06b6 Add FreeBSD support for bluetooth sockets. (SF Patch #888148)
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
59 #include <bluetooth.h>
a282801b06b6 Add FreeBSD support for bluetooth sockets. (SF Patch #888148)
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
60 #endif
a282801b06b6 Add FreeBSD support for bluetooth sockets. (SF Patch #888148)
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
61
70142
434dfe42fde1 Fix _socket compilation failures on non-Linux buildbots (cf. issue #1746656).
Nadeem Vawda <nadeem.vawda@gmail.com>
parents: 66663
diff changeset
62 #ifdef HAVE_NET_IF_H
434dfe42fde1 Fix _socket compilation failures on non-Linux buildbots (cf. issue #1746656).
Nadeem Vawda <nadeem.vawda@gmail.com>
parents: 66663
diff changeset
63 # include <net/if.h>
434dfe42fde1 Fix _socket compilation failures on non-Linux buildbots (cf. issue #1746656).
Nadeem Vawda <nadeem.vawda@gmail.com>
parents: 66663
diff changeset
64 #endif
434dfe42fde1 Fix _socket compilation failures on non-Linux buildbots (cf. issue #1746656).
Nadeem Vawda <nadeem.vawda@gmail.com>
parents: 66663
diff changeset
65
21959
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
66 #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
67 # 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
68 # 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
69 #endif
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
70
44568
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
71 #ifdef HAVE_LINUX_TIPC_H
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
72 # include <linux/tipc.h>
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
73 #endif
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
74
72758
e767318baccd Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents: 70142
diff changeset
75 #ifdef HAVE_LINUX_CAN_H
e767318baccd Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents: 70142
diff changeset
76 #include <linux/can.h>
e767318baccd Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents: 70142
diff changeset
77 #endif
e767318baccd Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents: 70142
diff changeset
78
e767318baccd Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents: 70142
diff changeset
79 #ifdef HAVE_LINUX_CAN_RAW_H
e767318baccd Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents: 70142
diff changeset
80 #include <linux/can/raw.h>
e767318baccd Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents: 70142
diff changeset
81 #endif
e767318baccd Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents: 70142
diff changeset
82
82024
f714af60508d Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents: 79475
diff changeset
83 #ifdef HAVE_LINUX_CAN_BCM_H
f714af60508d Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents: 79475
diff changeset
84 #include <linux/can/bcm.h>
f714af60508d Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents: 79475
diff changeset
85 #endif
f714af60508d Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents: 79475
diff changeset
86
74741
aa3680d2c24d Issue #13777: Add PF_SYSTEM sockets on OS X.
Martin v. Löwis <martin@v.loewis.de>
parents: 74142
diff changeset
87 #ifdef HAVE_SYS_SYS_DOMAIN_H
aa3680d2c24d Issue #13777: Add PF_SYSTEM sockets on OS X.
Martin v. Löwis <martin@v.loewis.de>
parents: 74142
diff changeset
88 #include <sys/sys_domain.h>
aa3680d2c24d Issue #13777: Add PF_SYSTEM sockets on OS X.
Martin v. Löwis <martin@v.loewis.de>
parents: 74142
diff changeset
89 #endif
aa3680d2c24d Issue #13777: Add PF_SYSTEM sockets on OS X.
Martin v. Löwis <martin@v.loewis.de>
parents: 74142
diff changeset
90 #ifdef HAVE_SYS_KERN_CONTROL_H
aa3680d2c24d Issue #13777: Add PF_SYSTEM sockets on OS X.
Martin v. Löwis <martin@v.loewis.de>
parents: 74142
diff changeset
91 #include <sys/kern_control.h>
aa3680d2c24d Issue #13777: Add PF_SYSTEM sockets on OS X.
Martin v. Löwis <martin@v.loewis.de>
parents: 74142
diff changeset
92 #endif
aa3680d2c24d Issue #13777: Add PF_SYSTEM sockets on OS X.
Martin v. Löwis <martin@v.loewis.de>
parents: 74142
diff changeset
93
21959
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
94 #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
95 #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
96 #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
97 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
98 #endif
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
99
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
100 /* Python module and C API name */
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
101 #define PySocket_MODULE_NAME "_socket"
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
102 #define PySocket_CAPI_NAME "CAPI"
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
103 #define PySocket_CAPSULE_NAME PySocket_MODULE_NAME "." PySocket_CAPI_NAME
21959
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
104
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
105 /* 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
106 #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
107 typedef SOCKET SOCKET_T;
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
108 # ifdef MS_WIN64
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
109 # define SIZEOF_SOCKET_T 8
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
110 # else
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
111 # define SIZEOF_SOCKET_T 4
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
112 # 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
113 #else
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
114 typedef int SOCKET_T;
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
115 # define SIZEOF_SOCKET_T SIZEOF_INT
21959
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
116 #endif
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
117
64301
8f6e41c3a218 Issue #4835: make PyLong_FromSocket_t() and PyLong_AsSocket_t() private
Antoine Pitrou <solipsis@pitrou.net>
parents: 61466
diff changeset
118 #if SIZEOF_SOCKET_T <= SIZEOF_LONG
8f6e41c3a218 Issue #4835: make PyLong_FromSocket_t() and PyLong_AsSocket_t() private
Antoine Pitrou <solipsis@pitrou.net>
parents: 61466
diff changeset
119 #define PyLong_FromSocket_t(fd) PyLong_FromLong((SOCKET_T)(fd))
8f6e41c3a218 Issue #4835: make PyLong_FromSocket_t() and PyLong_AsSocket_t() private
Antoine Pitrou <solipsis@pitrou.net>
parents: 61466
diff changeset
120 #define PyLong_AsSocket_t(fd) (SOCKET_T)PyLong_AsLong(fd)
8f6e41c3a218 Issue #4835: make PyLong_FromSocket_t() and PyLong_AsSocket_t() private
Antoine Pitrou <solipsis@pitrou.net>
parents: 61466
diff changeset
121 #else
8f6e41c3a218 Issue #4835: make PyLong_FromSocket_t() and PyLong_AsSocket_t() private
Antoine Pitrou <solipsis@pitrou.net>
parents: 61466
diff changeset
122 #define PyLong_FromSocket_t(fd) PyLong_FromLongLong((SOCKET_T)(fd))
8f6e41c3a218 Issue #4835: make PyLong_FromSocket_t() and PyLong_AsSocket_t() private
Antoine Pitrou <solipsis@pitrou.net>
parents: 61466
diff changeset
123 #define PyLong_AsSocket_t(fd) (SOCKET_T)PyLong_AsLongLong(fd)
8f6e41c3a218 Issue #4835: make PyLong_FromSocket_t() and PyLong_AsSocket_t() private
Antoine Pitrou <solipsis@pitrou.net>
parents: 61466
diff changeset
124 #endif
8f6e41c3a218 Issue #4835: make PyLong_FromSocket_t() and PyLong_AsSocket_t() private
Antoine Pitrou <solipsis@pitrou.net>
parents: 61466
diff changeset
125
35551
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 31790
diff changeset
126 /* Socket address */
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 31790
diff changeset
127 typedef union sock_addr {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
128 struct sockaddr_in in;
74142
683a1b1ff15d Issue #8623: Fix some strict-aliasing warnings. Patch by David Watson.
Charles-François Natali <neologix@free.fr>
parents: 72758
diff changeset
129 struct sockaddr sa;
35551
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 31790
diff changeset
130 #ifdef AF_UNIX
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
131 struct sockaddr_un un;
35551
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 31790
diff changeset
132 #endif
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 35551
diff changeset
133 #ifdef AF_NETLINK
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
134 struct sockaddr_nl nl;
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 35551
diff changeset
135 #endif
35551
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 31790
diff changeset
136 #ifdef ENABLE_IPV6
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
137 struct sockaddr_in6 in6;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
138 struct sockaddr_storage storage;
35551
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 31790
diff changeset
139 #endif
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 31790
diff changeset
140 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
141 struct sockaddr_l2 bt_l2;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
142 struct sockaddr_rc bt_rc;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
143 struct sockaddr_sco bt_sco;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
144 struct sockaddr_hci bt_hci;
35551
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 31790
diff changeset
145 #endif
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 31790
diff changeset
146 #ifdef HAVE_NETPACKET_PACKET_H
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
147 struct sockaddr_ll ll;
35551
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 31790
diff changeset
148 #endif
72758
e767318baccd Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents: 70142
diff changeset
149 #ifdef HAVE_LINUX_CAN_H
e767318baccd Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents: 70142
diff changeset
150 struct sockaddr_can can;
e767318baccd Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents: 70142
diff changeset
151 #endif
74741
aa3680d2c24d Issue #13777: Add PF_SYSTEM sockets on OS X.
Martin v. Löwis <martin@v.loewis.de>
parents: 74142
diff changeset
152 #ifdef HAVE_SYS_KERN_CONTROL_H
aa3680d2c24d Issue #13777: Add PF_SYSTEM sockets on OS X.
Martin v. Löwis <martin@v.loewis.de>
parents: 74142
diff changeset
153 struct sockaddr_ctl ctl;
aa3680d2c24d Issue #13777: Add PF_SYSTEM sockets on OS X.
Martin v. Löwis <martin@v.loewis.de>
parents: 74142
diff changeset
154 #endif
35551
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 31790
diff changeset
155 } sock_addr_t;
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 31790
diff changeset
156
21959
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
157 /* 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
158 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
159 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
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 typedef struct {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
162 PyObject_HEAD
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
163 SOCKET_T sock_fd; /* Socket file descriptor */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
164 int sock_family; /* Address family, e.g., AF_INET */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
165 int sock_type; /* Socket type, e.g., SOCK_STREAM */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
166 int sock_proto; /* Protocol type, usually 0 */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
167 PyObject *(*errorhandler)(void); /* Error handler; checks
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
168 errno, returns NULL and
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
169 sets a Python exception */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
170 double sock_timeout; /* Operation timeout in seconds;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
171 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
172 } PySocketSockObject;
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
173
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
174 /* --- 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
175
22041
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
176 /* 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
177 and how it works:
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
178
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
179 The _ssl module needs access to the type object defined in
22041
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
180 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
181 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
182 C API of a module in a struct which then gets exported to
53816
911df82bc25d add a replacement API for PyCObject, PyCapsule #5630
Benjamin Peterson <benjamin@python.org>
parents: 47718
diff changeset
183 other modules via a PyCapsule.
22041
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
184
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
185 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
186 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
187 well also include other C APIs needed by other modules)
53816
911df82bc25d add a replacement API for PyCObject, PyCapsule #5630
Benjamin Peterson <benjamin@python.org>
parents: 47718
diff changeset
188 and exports it as PyCapsule via the module dictionary
22041
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
189 under the name "CAPI".
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
190
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
191 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
192 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
193 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
194
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
195 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
196 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
197 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
198
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
199 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
200 PySocketModule:
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
201
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
202 if (PySocketModule_ImportModuleAndAPI())
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
203 return;
22041
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
204
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
205
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
206 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
207 module:
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
208
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
209 if (!PyArg_ParseTuple(args, "O!|zz:ssl",
22041
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
210
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
211 PySocketModule.Sock_Type,
22041
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
212
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
213 (PyObject*)&Sock,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
214 &key_file, &cert_file))
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
215 return NULL;
22041
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
216
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
217 Support could easily be extended to export more C APIs/symbols
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
218 this way. Currently, only the type object is exported,
22041
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
219 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
220 access functions.
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
221
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
222 */
e0a288db022d Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents: 21970
diff changeset
223
21959
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
224 /* 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
225 typedef struct {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
226 PyTypeObject *Sock_Type;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 55573
diff changeset
227 PyObject *error;
66663
3d9a86b8cc98 Issue #10272: The ssl module now raises socket.timeout instead of a generic
Antoine Pitrou <solipsis@pitrou.net>
parents: 64301
diff changeset
228 PyObject *timeout_error;
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
229 } 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
230
53824
b666e72f602f turn this into a macro
Benjamin Peterson <benjamin@python.org>
parents: 53816
diff changeset
231 #define PySocketModule_ImportModuleAndAPI() PyCapsule_Import(PySocket_CAPSULE_NAME, 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
232
55573
5c8b2238a2f5 Merged revisions 74356-74357 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 53824
diff changeset
233 #ifdef __cplusplus
21959
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
234 }
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
235 #endif
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
236 #endif /* !Py__SOCKET_H */