Mercurial > cpython-lru_cache-weakref
annotate Modules/socketmodule.h @ 74006:88198b93ff2f
Issue #13560: Add PyUnicode_EncodeLocale()
* Use PyUnicode_EncodeLocale() in time.strftime() if wcsftime() is not
available
* Document my last changes in Misc/NEWS
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Sat, 17 Dec 2011 04:13:41 +0100 |
| parents | e767318baccd |
| children | 683a1b1ff15d |
| 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> |
|
44082
4cb95fc4129e
Marc-Andre Lemburg has found the culprit of the problem in r57142.
Christian Heimes <christian@cheimes.de>
parents:
42645
diff
changeset
|
11 # if !(defined(__CYGWIN__) || (defined(PYOS_OS2) && defined(PYCC_VACPP))) |
|
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> |
|
40893
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40450
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 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
83 #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
|
84 #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
|
85 #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
|
86 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
|
87 #endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
88 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
89 /* 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
|
90 #define PySocket_MODULE_NAME "_socket" |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
91 #define PySocket_CAPI_NAME "CAPI" |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
92 #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
|
93 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
94 /* 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
|
95 #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
|
96 typedef SOCKET SOCKET_T; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
97 # ifdef MS_WIN64 |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
98 # define SIZEOF_SOCKET_T 8 |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
99 # else |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
100 # define SIZEOF_SOCKET_T 4 |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
101 # 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
|
102 #else |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
103 typedef int SOCKET_T; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
104 # 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
|
105 #endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
106 |
|
64301
8f6e41c3a218
Issue #4835: make PyLong_FromSocket_t() and PyLong_AsSocket_t() private
Antoine Pitrou <solipsis@pitrou.net>
parents:
61466
diff
changeset
|
107 #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
|
108 #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
|
109 #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
|
110 #else |
|
8f6e41c3a218
Issue #4835: make PyLong_FromSocket_t() and PyLong_AsSocket_t() private
Antoine Pitrou <solipsis@pitrou.net>
parents:
61466
diff
changeset
|
111 #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
|
112 #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
|
113 #endif |
|
8f6e41c3a218
Issue #4835: make PyLong_FromSocket_t() and PyLong_AsSocket_t() private
Antoine Pitrou <solipsis@pitrou.net>
parents:
61466
diff
changeset
|
114 |
|
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
|
115 /* 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
|
116 typedef union sock_addr { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
117 struct sockaddr_in in; |
|
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
|
118 #ifdef AF_UNIX |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
119 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
|
120 #endif |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
35551
diff
changeset
|
121 #ifdef AF_NETLINK |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
122 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
|
123 #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
|
124 #ifdef ENABLE_IPV6 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
125 struct sockaddr_in6 in6; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
126 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
|
127 #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
|
128 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
129 struct sockaddr_l2 bt_l2; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
130 struct sockaddr_rc bt_rc; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
131 struct sockaddr_sco bt_sco; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
132 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
|
133 #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
|
134 #ifdef HAVE_NETPACKET_PACKET_H |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
135 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
|
136 #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
|
137 #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
|
138 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
|
139 #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
|
140 } 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
|
141 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
142 /* 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
|
143 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
|
144 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
|
145 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
146 typedef struct { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
147 PyObject_HEAD |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
148 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
|
149 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
|
150 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
|
151 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
|
152 PyObject *(*errorhandler)(void); /* Error handler; checks |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
153 errno, returns NULL and |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
154 sets a Python exception */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
155 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
|
156 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
|
157 } PySocketSockObject; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
158 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
159 /* --- 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
|
160 |
|
22041
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
161 /* 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
|
162 and how it works: |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
163 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
170 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
|
171 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
|
172 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
|
173 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
|
174 under the name "CAPI". |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
175 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
176 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
|
177 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
|
178 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
|
179 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
180 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
|
181 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
|
182 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
|
183 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
184 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
|
185 PySocketModule: |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
186 |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
187 if (PySocketModule_ImportModuleAndAPI()) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
188 return; |
|
22041
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
189 |
|
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 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
|
192 module: |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
193 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
194 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
|
195 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
196 PySocketModule.Sock_Type, |
|
22041
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
197 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
198 (PyObject*)&Sock, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
199 &key_file, &cert_file)) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
200 return NULL; |
|
22041
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
201 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
202 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
|
203 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
|
204 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
|
205 access functions. |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
206 |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
207 */ |
|
e0a288db022d
Add documentation about how the inter-module linking works.
Marc-André Lemburg <mal@egenix.com>
parents:
21970
diff
changeset
|
208 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
209 /* 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
|
210 typedef struct { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
211 PyTypeObject *Sock_Type; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
55573
diff
changeset
|
212 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
|
213 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
|
214 } 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
|
215 |
|
53824
b666e72f602f
turn this into a macro
Benjamin Peterson <benjamin@python.org>
parents:
53816
diff
changeset
|
216 #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
|
217 |
|
55573
5c8b2238a2f5
Merged revisions 74356-74357 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53824
diff
changeset
|
218 #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
|
219 } |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
220 #endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
221 #endif /* !Py__SOCKET_H */ |
