Mercurial > cpython-lru_cache-weakref
annotate Modules/socketmodule.c @ 65035:87f4b32905df 2.7
Cosmetic fix to use print function.
| author | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> |
|---|---|
| date | Fri, 01 Oct 2010 10:48:47 +0000 |
| parents | 1dc2b50d344f |
| children | 20f463a4584d |
| rev | line source |
|---|---|
| 294 | 1 /* Socket module */ |
| 2 | |
| 3 /* | |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4 |
| 294 | 5 This module provides an interface to Berkeley socket IPC. |
| 6 | |
| 7 Limitations: | |
| 8 | |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
9 - Only AF_INET, AF_INET6 and AF_UNIX address families are supported in a |
|
44561
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44474
diff
changeset
|
10 portable manner, though AF_PACKET, AF_NETLINK and AF_TIPC are supported |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44474
diff
changeset
|
11 under Linux. |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
12 - No read/write operations (use sendall/recv or makefile instead). |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
13 - Additional restrictions apply on some non-Unix platforms (compensated |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
14 for by socket.py). |
| 294 | 15 |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
16 Module interface: |
| 294 | 17 |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
18 - socket.error: exception raised for socket specific errors |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
19 - socket.gaierror: exception raised for getaddrinfo/getnameinfo errors, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
20 a subclass of socket.error |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
21 - socket.herror: exception raised for gethostby* errors, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
22 a subclass of socket.error |
|
25105
39e09f30f7ef
Update the module doc comment.
Guido van Rossum <guido@python.org>
parents:
24687
diff
changeset
|
23 - socket.fromfd(fd, family, type[, proto]) --> new socket object (created |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
24 from an existing file descriptor) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
25 - socket.gethostbyname(hostname) --> host IP address (string: 'dd.dd.dd.dd') |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
26 - socket.gethostbyaddr(IP address) --> (hostname, [alias, ...], [IP addr, ...]) |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
27 - socket.gethostname() --> host name (string: 'spam' or 'spam.domain.com') |
|
4783
feba6d58d204
Added the new getprotobyname() call to the module overview at the top.
Guido van Rossum <guido@python.org>
parents:
4782
diff
changeset
|
28 - socket.getprotobyname(protocolname) --> protocol number |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
29 - socket.getservbyname(servicename[, protocolname]) --> port number |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
30 - socket.getservbyport(portnumber[, protocolname]) --> service name |
|
25105
39e09f30f7ef
Update the module doc comment.
Guido van Rossum <guido@python.org>
parents:
24687
diff
changeset
|
31 - socket.socket([family[, type [, proto]]]) --> new socket object |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
32 - socket.socketpair([family[, type [, proto]]]) --> (socket, socket) |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
33 - socket.ntohs(16 bit value) --> new int object |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
34 - socket.ntohl(32 bit value) --> new int object |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
35 - socket.htons(16 bit value) --> new int object |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
36 - socket.htonl(32 bit value) --> new int object |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
37 - socket.getaddrinfo(host, port [, family, socktype, proto, flags]) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
38 --> List of (family, socktype, proto, canonname, sockaddr) |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
39 - socket.getnameinfo(sockaddr, flags) --> (host, port) |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
40 - socket.AF_INET, socket.SOCK_STREAM, etc.: constants from <socket.h> |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
41 - socket.has_ipv6: boolean value indicating if IPv6 is supported |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
42 - socket.inet_aton(IP address) -> 32-bit packed IP representation |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
43 - socket.inet_ntoa(packed IP) -> IP address string |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
44 - socket.getdefaulttimeout() -> None | float |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
45 - socket.setdefaulttimeout(None | float) |
| 294 | 46 - an Internet socket address is a pair (hostname, port) |
| 47 where hostname can be anything recognized by gethostbyname() | |
| 48 (including the dd.dd.dd.dd notation) and port is in host byte order | |
| 49 - where a hostname is returned, the dd.dd.dd.dd notation is used | |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
50 - a UNIX domain socket address is a string specifying the pathname |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
51 - an AF_PACKET socket address is a tuple containing a string |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
52 specifying the ethernet interface and an integer specifying |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
53 the Ethernet protocol number to be received. For example: |
|
16427
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
54 ("eth0",0x1234). Optional 3rd,4th,5th elements in the tuple |
|
32611
8b3288f607e1
[Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents:
32578
diff
changeset
|
55 specify packet-type and ha-type/addr. |
|
44561
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44474
diff
changeset
|
56 - an AF_TIPC socket address is expressed as |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44474
diff
changeset
|
57 (addr_type, v1, v2, v3 [, scope]); where addr_type can be one of: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
58 TIPC_ADDR_NAMESEQ, TIPC_ADDR_NAME, and TIPC_ADDR_ID; |
|
44561
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44474
diff
changeset
|
59 and scope can be one of: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
60 TIPC_ZONE_SCOPE, TIPC_CLUSTER_SCOPE, and TIPC_NODE_SCOPE. |
|
44561
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44474
diff
changeset
|
61 The meaning of v1, v2 and v3 depends on the value of addr_type: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
62 if addr_type is TIPC_ADDR_NAME: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
63 v1 is the server type |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
64 v2 is the port identifier |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
65 v3 is ignored |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
66 if addr_type is TIPC_ADDR_NAMESEQ: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
67 v1 is the server type |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
68 v2 is the lower port number |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
69 v3 is the upper port number |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
70 if addr_type is TIPC_ADDR_ID: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
71 v1 is the node |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
72 v2 is the ref |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
73 v3 is ignored |
|
44561
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44474
diff
changeset
|
74 |
| 294 | 75 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
76 Local naming conventions: |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
77 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
78 - names starting with sock_ are socket object methods |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
79 - names starting with socket_ are module-level functions |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
80 - names starting with PySocket are exported through socketmodule.h |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
81 |
| 294 | 82 */ |
| 83 | |
|
37934
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
84 #ifdef __APPLE__ |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
85 /* |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
86 * inet_aton is not available on OSX 10.3, yet we want to use a binary |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
87 * that was build on 10.4 or later to work on that release, weak linking |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
88 * comes to the rescue. |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
89 */ |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
90 # pragma weak inet_aton |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
91 #endif |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
92 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
93 #include "Python.h" |
|
37069
dd49847a60d3
RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents:
36684
diff
changeset
|
94 #include "structmember.h" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
95 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
96 #undef MAX |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
97 #define MAX(x, y) ((x) < (y) ? (y) : (x)) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
98 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
99 /* Socket object documentation */ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
100 PyDoc_STRVAR(sock_doc, |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
101 "socket([family[, type[, proto]]]) -> socket object\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
102 \n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
103 Open a socket of the given type. The family argument specifies the\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
104 address family; it defaults to AF_INET. The type argument specifies\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
105 whether this is a stream (SOCK_STREAM, this is the default)\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
106 or datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
107 specifying the default protocol. Keyword arguments are accepted.\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
108 \n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
109 A socket object represents one endpoint of a network connection.\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
110 \n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
111 Methods of socket objects (keyword arguments not allowed):\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
112 \n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
113 accept() -- accept a connection, returning new socket and client address\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
114 bind(addr) -- bind the socket to a local address\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
115 close() -- close the socket\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
116 connect(addr) -- connect the socket to a remote address\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
117 connect_ex(addr) -- connect, return an error code instead of an exception\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
118 dup() -- return a new socket object identical to the current one [*]\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
119 fileno() -- return underlying file descriptor\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
120 getpeername() -- return remote address [*]\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
121 getsockname() -- return local address\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
122 getsockopt(level, optname[, buflen]) -- get socket options\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
123 gettimeout() -- return timeout or None\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
124 listen(n) -- start listening for incoming connections\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
125 makefile([mode, [bufsize]]) -- return a file object for the socket [*]\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
126 recv(buflen[, flags]) -- receive data\n\ |
|
38580
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38498
diff
changeset
|
127 recv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\n\ |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
128 recvfrom(buflen[, flags]) -- receive data and sender\'s address\n\ |
|
38580
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38498
diff
changeset
|
129 recvfrom_into(buffer[, nbytes, [, flags])\n\ |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
130 -- receive data and sender\'s address (into a buffer)\n\ |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
131 sendall(data[, flags]) -- send all data\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
132 send(data[, flags]) -- send data, may not send all of it\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
133 sendto(data[, flags], addr) -- send data to a given address\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
134 setblocking(0 | 1) -- set or clear the blocking I/O flag\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
135 setsockopt(level, optname, value) -- set socket options\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
136 settimeout(None | float) -- set or clear the timeout\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
137 shutdown(how) -- shut down traffic in one or both directions\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
138 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
139 [*] not available on all platforms!"); |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
140 |
|
30722
651fc8d98d99
Fix a bunch of typos in documentation, docstrings and comments.
Walter Dörwald <walter@livinglogic.de>
parents:
30683
diff
changeset
|
141 /* XXX This is a terrible mess of platform-dependent preprocessor hacks. |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
142 I hope some day someone can clean this up please... */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
143 |
|
11288
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
144 /* Hacks for gethostbyname_r(). On some non-Linux platforms, the configure |
|
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
145 script doesn't get this right, so we hardcode some platform checks below. |
|
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
146 On the other hand, not all Linux versions agree, so there the settings |
|
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
147 computed by the configure script are needed! */ |
|
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
148 |
|
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
149 #ifndef linux |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
150 # undef HAVE_GETHOSTBYNAME_R_3_ARG |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
151 # undef HAVE_GETHOSTBYNAME_R_5_ARG |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
152 # undef HAVE_GETHOSTBYNAME_R_6_ARG |
|
11288
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
153 #endif |
|
10454
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
154 |
|
10579
1ed1eb5bc6ec
Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents:
10561
diff
changeset
|
155 #ifndef WITH_THREAD |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
156 # undef HAVE_GETHOSTBYNAME_R |
|
10579
1ed1eb5bc6ec
Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents:
10561
diff
changeset
|
157 #endif |
|
1ed1eb5bc6ec
Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents:
10561
diff
changeset
|
158 |
|
10454
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
159 #ifdef HAVE_GETHOSTBYNAME_R |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
160 # if defined(_AIX) || defined(__osf__) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
161 # define HAVE_GETHOSTBYNAME_R_3_ARG |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
162 # elif defined(__sun) || defined(__sgi) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
163 # define HAVE_GETHOSTBYNAME_R_5_ARG |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
164 # elif defined(linux) |
|
11288
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
165 /* Rely on the configure script */ |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
166 # else |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
167 # undef HAVE_GETHOSTBYNAME_R |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
168 # endif |
|
10454
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
169 #endif |
|
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
170 |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
171 #if !defined(HAVE_GETHOSTBYNAME_R) && defined(WITH_THREAD) && \ |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
172 !defined(MS_WINDOWS) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
173 # define USE_GETHOSTBYNAME_LOCK |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
174 #endif |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
175 |
|
35635
27e1426b7f31
Patch #1288833: Removed thread lock from socket.getaddrinfo on
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35551
diff
changeset
|
176 /* To use __FreeBSD_version */ |
|
27e1426b7f31
Patch #1288833: Removed thread lock from socket.getaddrinfo on
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35551
diff
changeset
|
177 #ifdef HAVE_SYS_PARAM_H |
|
27e1426b7f31
Patch #1288833: Removed thread lock from socket.getaddrinfo on
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35551
diff
changeset
|
178 #include <sys/param.h> |
|
27e1426b7f31
Patch #1288833: Removed thread lock from socket.getaddrinfo on
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35551
diff
changeset
|
179 #endif |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
180 /* On systems on which getaddrinfo() is believed to not be thread-safe, |
|
29036
ccf7e138a126
Addition to [731644]: also use the lock when using the getaddrinfo
Just van Rossum <just@letterror.com>
parents:
29035
diff
changeset
|
181 (this includes the getaddrinfo emulation) protect access with a lock. */ |
|
35635
27e1426b7f31
Patch #1288833: Removed thread lock from socket.getaddrinfo on
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35551
diff
changeset
|
182 #if defined(WITH_THREAD) && (defined(__APPLE__) || \ |
|
27e1426b7f31
Patch #1288833: Removed thread lock from socket.getaddrinfo on
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35551
diff
changeset
|
183 (defined(__FreeBSD__) && __FreeBSD_version+0 < 503000) || \ |
|
39043
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
184 defined(__OpenBSD__) || defined(__NetBSD__) || \ |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
185 defined(__VMS) || !defined(HAVE_GETADDRINFO)) |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
186 #define USE_GETADDRINFO_LOCK |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
187 #endif |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
188 |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
189 #ifdef USE_GETADDRINFO_LOCK |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
190 #define ACQUIRE_GETADDRINFO_LOCK PyThread_acquire_lock(netdb_lock, 1); |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
191 #define RELEASE_GETADDRINFO_LOCK PyThread_release_lock(netdb_lock); |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
192 #else |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
193 #define ACQUIRE_GETADDRINFO_LOCK |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
194 #define RELEASE_GETADDRINFO_LOCK |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
195 #endif |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
196 |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
197 #if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
198 # include "pythread.h" |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
199 #endif |
| 294 | 200 |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
201 #if 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:
21757
diff
changeset
|
202 # include <types.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
203 # include <io.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
204 # 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:
21757
diff
changeset
|
205 # include <utils.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
206 # include <ctype.h> |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
207 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
208 |
|
26551
0c995cd07026
Don't include <ioctl.h> unless on __VMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
26550
diff
changeset
|
209 #if defined(__VMS) |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25994
diff
changeset
|
210 # include <ioctl.h> |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25994
diff
changeset
|
211 #endif |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25994
diff
changeset
|
212 |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
213 #if defined(PYOS_OS2) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
214 # define INCL_DOS |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
215 # define INCL_DOSERRORS |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
216 # define INCL_NOPMAPI |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
217 # include <os2.h> |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
218 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
219 |
|
29929
08d2636b8e58
Get socketmodule compiling on IRIX 6.5.10.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29790
diff
changeset
|
220 #if defined(__sgi) && _COMPILER_VERSION>700 && !_SGIAPI |
|
25327
337fcc24985b
Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents:
25105
diff
changeset
|
221 /* make sure that the reentrant (gethostbyaddr_r etc) |
|
337fcc24985b
Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents:
25105
diff
changeset
|
222 functions are declared correctly if compiling with |
|
337fcc24985b
Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents:
25105
diff
changeset
|
223 MIPSPro 7.x in ANSI C mode (default) */ |
|
29929
08d2636b8e58
Get socketmodule compiling on IRIX 6.5.10.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29790
diff
changeset
|
224 |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
225 /* XXX Using _SGIAPI is the wrong thing, |
|
29929
08d2636b8e58
Get socketmodule compiling on IRIX 6.5.10.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29790
diff
changeset
|
226 but I don't know what the right thing is. */ |
|
33478
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
227 #undef _SGIAPI /* to avoid warning */ |
|
25327
337fcc24985b
Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents:
25105
diff
changeset
|
228 #define _SGIAPI 1 |
|
29929
08d2636b8e58
Get socketmodule compiling on IRIX 6.5.10.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29790
diff
changeset
|
229 |
|
33478
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
230 #undef _XOPEN_SOURCE |
|
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
231 #include <sys/socket.h> |
|
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
232 #include <sys/types.h> |
|
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
233 #include <netinet/in.h> |
|
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
234 #ifdef _SS_ALIGNSIZE |
|
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
235 #define HAVE_GETADDRINFO 1 |
|
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
236 #define HAVE_GETNAMEINFO 1 |
|
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
237 #endif |
|
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
238 |
|
29929
08d2636b8e58
Get socketmodule compiling on IRIX 6.5.10.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29790
diff
changeset
|
239 #define HAVE_INET_PTON |
|
08d2636b8e58
Get socketmodule compiling on IRIX 6.5.10.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29790
diff
changeset
|
240 #include <netdb.h> |
|
25327
337fcc24985b
Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents:
25105
diff
changeset
|
241 #endif |
|
337fcc24985b
Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents:
25105
diff
changeset
|
242 |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
243 /* Irix 6.5 fails to define this variable at all. This is needed |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
244 for both GCC and SGI's compiler. I'd say that the SGI headers |
|
36610
0671f3c462d5
Bug #854823: socketmodule now builds on Sun platforms even when
Georg Brandl <georg@python.org>
parents:
36476
diff
changeset
|
245 are just busted. Same thing for Solaris. */ |
|
0671f3c462d5
Bug #854823: socketmodule now builds on Sun platforms even when
Georg Brandl <georg@python.org>
parents:
36476
diff
changeset
|
246 #if (defined(__sgi) || defined(sun)) && !defined(INET_ADDRSTRLEN) |
|
30646
a6fb6822814a
made the SGI INET_ADDRSTRLEN define apply for any compiler on Irix. Both the
Anthony Baxter <anthonybaxter@gmail.com>
parents:
30630
diff
changeset
|
247 #define INET_ADDRSTRLEN 16 |
|
a6fb6822814a
made the SGI INET_ADDRSTRLEN define apply for any compiler on Irix. Both the
Anthony Baxter <anthonybaxter@gmail.com>
parents:
30630
diff
changeset
|
248 #endif |
|
a6fb6822814a
made the SGI INET_ADDRSTRLEN define apply for any compiler on Irix. Both the
Anthony Baxter <anthonybaxter@gmail.com>
parents:
30630
diff
changeset
|
249 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
250 /* Generic includes */ |
|
38716
42808526511c
Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
38655
diff
changeset
|
251 #ifdef HAVE_SYS_TYPES_H |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
252 #include <sys/types.h> |
|
38716
42808526511c
Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
38655
diff
changeset
|
253 #endif |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
254 |
|
21961
ea23e6e49290
Also fix the comment.
Marc-André Lemburg <mal@egenix.com>
parents:
21960
diff
changeset
|
255 /* Generic socket object definitions and includes */ |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
256 #define PySocket_BUILDING_SOCKET |
|
21960
7a917ad8f442
Fix the name of the header file.
Marc-André Lemburg <mal@egenix.com>
parents:
21959
diff
changeset
|
257 #include "socketmodule.h" |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
258 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
259 /* Addressing includes */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
260 |
|
3738
ce74bba8a6a6
Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents:
3702
diff
changeset
|
261 #ifndef MS_WINDOWS |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
262 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
263 /* Non-MS WINDOWS includes */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
264 # include <netdb.h> |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
265 |
|
11288
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
266 /* Headers needed for inet_ntoa() and inet_addr() */ |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
267 # ifdef __BEOS__ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
268 # include <net/netdb.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
269 # elif 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:
21757
diff
changeset
|
270 # include <netdb.h> |
|
20871
f576ffd57966
SF patch 473749 compile under OS/2 VA C++, from Michael Muller.
Tim Peters <tim.peters@gmail.com>
parents:
20853
diff
changeset
|
271 typedef size_t socklen_t; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
272 # else |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
273 # include <arpa/inet.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
274 # endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
275 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
276 # ifndef RISCOS |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
277 # include <fcntl.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
278 # else |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
279 # include <sys/ioctl.h> |
|
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
280 # include <socklib.h> |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
281 # define NO_DUP |
|
20654
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20648
diff
changeset
|
282 int h_errno; /* not used */ |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
283 # define INET_ADDRSTRLEN 16 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
284 # endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
285 |
|
20654
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20648
diff
changeset
|
286 #else |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
287 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
288 /* MS_WINDOWS includes */ |
|
38716
42808526511c
Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
38655
diff
changeset
|
289 # ifdef HAVE_FCNTL_H |
|
42808526511c
Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
38655
diff
changeset
|
290 # include <fcntl.h> |
|
42808526511c
Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
38655
diff
changeset
|
291 # endif |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
292 |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
293 #endif |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
294 |
|
31504
2abc52c3d4c2
remove support for missing ANSI C header files (limits.h, stddef.h, etc).
Skip Montanaro <skip@pobox.com>
parents:
31443
diff
changeset
|
295 #include <stddef.h> |
|
18263
41491d196748
Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents:
18262
diff
changeset
|
296 |
|
41491d196748
Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents:
18262
diff
changeset
|
297 #ifndef offsetof |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
298 # define offsetof(type, member) ((size_t)(&((type *)0)->member)) |
|
18263
41491d196748
Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents:
18262
diff
changeset
|
299 #endif |
|
41491d196748
Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents:
18262
diff
changeset
|
300 |
|
25994
bb813346b227
Use O_NONBLOCK rather than O_NDELAY, so we get POSIX non-blocking I/O.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25327
diff
changeset
|
301 #ifndef O_NONBLOCK |
|
bb813346b227
Use O_NONBLOCK rather than O_NDELAY, so we get POSIX non-blocking I/O.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25327
diff
changeset
|
302 # define O_NONBLOCK O_NDELAY |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
303 #endif |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
304 |
|
33427
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
305 /* include Python's addrinfo.h unless it causes trouble */ |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
306 #if defined(__sgi) && _COMPILER_VERSION>700 && defined(_SS_ALIGNSIZE) |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
307 /* Do not include addinfo.h on some newer IRIX versions. |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
308 * _SS_ALIGNSIZE is defined in sys/socket.h by 6.5.21, |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
309 * for example, but not by 6.5.10. |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
310 */ |
|
38716
42808526511c
Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
38655
diff
changeset
|
311 #elif defined(_MSC_VER) && _MSC_VER>1201 |
|
33427
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
312 /* Do not include addrinfo.h for MSVC7 or greater. 'addrinfo' and |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
313 * EAI_* constants are defined in (the already included) ws2tcpip.h. |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
314 */ |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
315 #else |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
316 # include "addrinfo.h" |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
317 #endif |
|
33066
cda0455bd0a0
Bug #1001857: socketmodule does not build under cygwin
Jason Tishler <jason@tishler.net>
parents:
33063
diff
changeset
|
318 |
|
18262
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
319 #ifndef HAVE_INET_PTON |
|
43972
a8dd8874ff2d
Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
43876
diff
changeset
|
320 #if !defined(NTDDI_VERSION) || (NTDDI_VERSION < NTDDI_LONGHORN) |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
321 int inet_pton(int af, const char *src, void *dst); |
|
18790
7cd22bf56d7b
Silence warnings in MSVC++: hide unused variables, add constness back to
Martin v. Löwis <martin@v.loewis.de>
parents:
18753
diff
changeset
|
322 const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); |
|
18262
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
323 #endif |
|
43972
a8dd8874ff2d
Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
43876
diff
changeset
|
324 #endif |
|
18262
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
325 |
|
18954
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
326 #ifdef __APPLE__ |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
327 /* On OS X, getaddrinfo returns no error indication of lookup |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
328 failure, so we must use the emulation instead of the libinfo |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
329 implementation. Unfortunately, performing an autoconf test |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
330 for this bug would require DNS access for the machine performing |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
331 the configuration, which is not acceptable. Therefore, we |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
332 determine the bug just by checking for __APPLE__. If this bug |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
333 gets ever fixed, perhaps checking for sys/version.h would be |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
334 appropriate, which is 10/0 on the system with the bug. */ |
|
24078
702a5900df7d
Mac OS X Jaguar (developer preview) seems to have a working getaddrinfo().
Jack Jansen <jack.jansen@cwi.nl>
parents:
23832
diff
changeset
|
335 #ifndef HAVE_GETNAMEINFO |
|
702a5900df7d
Mac OS X Jaguar (developer preview) seems to have a working getaddrinfo().
Jack Jansen <jack.jansen@cwi.nl>
parents:
23832
diff
changeset
|
336 /* This bug seems to be fixed in Jaguar. Ths easiest way I could |
|
702a5900df7d
Mac OS X Jaguar (developer preview) seems to have a working getaddrinfo().
Jack Jansen <jack.jansen@cwi.nl>
parents:
23832
diff
changeset
|
337 Find to check for Jaguar is that it has getnameinfo(), which |
|
702a5900df7d
Mac OS X Jaguar (developer preview) seems to have a working getaddrinfo().
Jack Jansen <jack.jansen@cwi.nl>
parents:
23832
diff
changeset
|
338 older releases don't have */ |
|
18954
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
339 #undef HAVE_GETADDRINFO |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
340 #endif |
|
37934
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
341 |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
342 #ifdef HAVE_INET_ATON |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
343 #define USE_INET_ATON_WEAKLINK |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
344 #endif |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
345 |
|
24078
702a5900df7d
Mac OS X Jaguar (developer preview) seems to have a working getaddrinfo().
Jack Jansen <jack.jansen@cwi.nl>
parents:
23832
diff
changeset
|
346 #endif |
|
18954
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
347 |
|
18246
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
348 /* I know this is a bad practice, but it is the easiest... */ |
|
18954
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
349 #if !defined(HAVE_GETADDRINFO) |
|
28913
b04c074586aa
Patch #725942: Always rename emulation functions.
Martin v. Löwis <martin@v.loewis.de>
parents:
28818
diff
changeset
|
350 /* avoid clashes with the C library definition of the symbol. */ |
|
b04c074586aa
Patch #725942: Always rename emulation functions.
Martin v. Löwis <martin@v.loewis.de>
parents:
28818
diff
changeset
|
351 #define getaddrinfo fake_getaddrinfo |
|
b04c074586aa
Patch #725942: Always rename emulation functions.
Martin v. Löwis <martin@v.loewis.de>
parents:
28818
diff
changeset
|
352 #define gai_strerror fake_gai_strerror |
|
b04c074586aa
Patch #725942: Always rename emulation functions.
Martin v. Löwis <martin@v.loewis.de>
parents:
28818
diff
changeset
|
353 #define freeaddrinfo fake_freeaddrinfo |
|
18246
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
354 #include "getaddrinfo.c" |
|
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
355 #endif |
|
18954
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
356 #if !defined(HAVE_GETNAMEINFO) |
|
28913
b04c074586aa
Patch #725942: Always rename emulation functions.
Martin v. Löwis <martin@v.loewis.de>
parents:
28818
diff
changeset
|
357 #define getnameinfo fake_getnameinfo |
|
18246
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
358 #include "getnameinfo.c" |
|
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
359 #endif |
|
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
360 |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
361 #if defined(MS_WINDOWS) || defined(__BEOS__) |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
362 /* BeOS suffers from the same socket dichotomy as Win32... - [cjh] */ |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
363 /* seem to be a few differences in the API */ |
|
12436
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
364 #define SOCKETCLOSE closesocket |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
365 #define NO_DUP /* Actually it exists on NT 3.5, but what the heck... */ |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
366 #endif |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
367 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
368 #ifdef MS_WIN32 |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
369 #define EAFNOSUPPORT WSAEAFNOSUPPORT |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
370 #define snprintf _snprintf |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
371 #endif |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
372 |
|
22115
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
373 #if defined(PYOS_OS2) && !defined(PYCC_GCC) |
|
12436
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
374 #define SOCKETCLOSE soclose |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
375 #define NO_DUP /* Sockets are Not Actual File Handles under OS/2 */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
376 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
377 |
|
12436
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
378 #ifndef SOCKETCLOSE |
|
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
379 #define SOCKETCLOSE close |
|
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
380 #endif |
|
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
381 |
|
52549
87171283d02f
Apply patch for netbsd multiprocessing support
Jesse Noller <jnoller@gmail.com>
parents:
51538
diff
changeset
|
382 #if defined(HAVE_BLUETOOTH_H) || defined(HAVE_BLUETOOTH_BLUETOOTH_H) && !defined(__NetBSD__) |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
383 #define USE_BLUETOOTH 1 |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
384 #if defined(__FreeBSD__) |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
385 #define BTPROTO_L2CAP BLUETOOTH_PROTO_L2CAP |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
386 #define BTPROTO_RFCOMM BLUETOOTH_PROTO_RFCOMM |
|
40842
90e22fea8363
Patch #1432399: Add HCI sockets.
Martin v. Löwis <martin@v.loewis.de>
parents:
40837
diff
changeset
|
387 #define BTPROTO_HCI BLUETOOTH_PROTO_HCI |
|
41946
c36ac67eef5b
Fix build on FreeBSD. Bluetooth HCI API in FreeBSD is quite different
Hye-Shik Chang <hyeshik@gmail.com>
parents:
41341
diff
changeset
|
388 #define SOL_HCI SOL_HCI_RAW |
|
c36ac67eef5b
Fix build on FreeBSD. Bluetooth HCI API in FreeBSD is quite different
Hye-Shik Chang <hyeshik@gmail.com>
parents:
41341
diff
changeset
|
389 #define HCI_FILTER SO_HCI_RAW_FILTER |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
390 #define sockaddr_l2 sockaddr_l2cap |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
391 #define sockaddr_rc sockaddr_rfcomm |
|
41946
c36ac67eef5b
Fix build on FreeBSD. Bluetooth HCI API in FreeBSD is quite different
Hye-Shik Chang <hyeshik@gmail.com>
parents:
41341
diff
changeset
|
392 #define hci_dev hci_node |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
393 #define _BT_L2_MEMB(sa, memb) ((sa)->l2cap_##memb) |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
394 #define _BT_RC_MEMB(sa, memb) ((sa)->rfcomm_##memb) |
|
40842
90e22fea8363
Patch #1432399: Add HCI sockets.
Martin v. Löwis <martin@v.loewis.de>
parents:
40837
diff
changeset
|
395 #define _BT_HCI_MEMB(sa, memb) ((sa)->hci_##memb) |
|
39242
0e9a269a2189
Allow socketmodule to compile on NetBSD -current, whose bluetooth API
Matt Fleming <mattjfleming@googlemail.com>
parents:
39059
diff
changeset
|
396 #elif defined(__NetBSD__) |
|
0e9a269a2189
Allow socketmodule to compile on NetBSD -current, whose bluetooth API
Matt Fleming <mattjfleming@googlemail.com>
parents:
39059
diff
changeset
|
397 #define sockaddr_l2 sockaddr_bt |
|
0e9a269a2189
Allow socketmodule to compile on NetBSD -current, whose bluetooth API
Matt Fleming <mattjfleming@googlemail.com>
parents:
39059
diff
changeset
|
398 #define sockaddr_rc sockaddr_bt |
|
40842
90e22fea8363
Patch #1432399: Add HCI sockets.
Martin v. Löwis <martin@v.loewis.de>
parents:
40837
diff
changeset
|
399 #define sockaddr_hci sockaddr_bt |
|
39242
0e9a269a2189
Allow socketmodule to compile on NetBSD -current, whose bluetooth API
Matt Fleming <mattjfleming@googlemail.com>
parents:
39059
diff
changeset
|
400 #define sockaddr_sco sockaddr_bt |
|
0e9a269a2189
Allow socketmodule to compile on NetBSD -current, whose bluetooth API
Matt Fleming <mattjfleming@googlemail.com>
parents:
39059
diff
changeset
|
401 #define _BT_L2_MEMB(sa, memb) ((sa)->bt_##memb) |
|
0e9a269a2189
Allow socketmodule to compile on NetBSD -current, whose bluetooth API
Matt Fleming <mattjfleming@googlemail.com>
parents:
39059
diff
changeset
|
402 #define _BT_RC_MEMB(sa, memb) ((sa)->bt_##memb) |
|
40842
90e22fea8363
Patch #1432399: Add HCI sockets.
Martin v. Löwis <martin@v.loewis.de>
parents:
40837
diff
changeset
|
403 #define _BT_HCI_MEMB(sa, memb) ((sa)->bt_##memb) |
|
39242
0e9a269a2189
Allow socketmodule to compile on NetBSD -current, whose bluetooth API
Matt Fleming <mattjfleming@googlemail.com>
parents:
39059
diff
changeset
|
404 #define _BT_SCO_MEMB(sa, memb) ((sa)->bt_##memb) |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
405 #else |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
406 #define _BT_L2_MEMB(sa, memb) ((sa)->l2_##memb) |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
407 #define _BT_RC_MEMB(sa, memb) ((sa)->rc_##memb) |
|
40842
90e22fea8363
Patch #1432399: Add HCI sockets.
Martin v. Löwis <martin@v.loewis.de>
parents:
40837
diff
changeset
|
408 #define _BT_HCI_MEMB(sa, memb) ((sa)->hci_##memb) |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
409 #define _BT_SCO_MEMB(sa, memb) ((sa)->sco_##memb) |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
410 #endif |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
411 #endif |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
412 |
|
39043
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
413 #ifdef __VMS |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
414 /* TCP/IP Services for VMS uses a maximum send/recv buffer length */ |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
415 #define SEGMENT_SIZE (32 * 1024 -1) |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
416 #endif |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
417 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
418 #define SAS2SA(x) ((struct sockaddr *)(x)) |
|
40416
c43787e6d706
Patch #1544279: Improve thread-safety of the socket module by moving
Martin v. Löwis <martin@v.loewis.de>
parents:
39502
diff
changeset
|
419 |
|
28953
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
420 /* |
|
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
421 * Constants for getnameinfo() |
|
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
422 */ |
|
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
423 #if !defined(NI_MAXHOST) |
|
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
424 #define NI_MAXHOST 1025 |
|
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
425 #endif |
|
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
426 #if !defined(NI_MAXSERV) |
|
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
427 #define NI_MAXSERV 32 |
|
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
428 #endif |
|
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
429 |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
430 /* XXX There's a problem here: *static* functions are not supposed to have |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
431 a Py prefix (or use CapitalizedWords). Later... */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
432 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
433 /* Global variable holding the exception type for errors detected |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
434 by this module (but not argument type or memory errors, etc.). */ |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
435 static PyObject *socket_error; |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
436 static PyObject *socket_herror; |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
437 static PyObject *socket_gaierror; |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
438 static PyObject *socket_timeout; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
439 |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
440 #ifdef RISCOS |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
441 /* Global variable which is !=0 if Python is running in a RISC OS taskwindow */ |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
442 static int taskwindow; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
443 #endif |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
444 |
|
21970
b1a871dc5196
Moved the declaration of PySocketSock_Type from socketmodule.h to
Tim Peters <tim.peters@gmail.com>
parents:
21964
diff
changeset
|
445 /* A forward reference to the socket type object. |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
446 The sock_type variable contains pointers to various functions, |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
447 some of which call new_sockobject(), which uses sock_type, so |
|
21970
b1a871dc5196
Moved the declaration of PySocketSock_Type from socketmodule.h to
Tim Peters <tim.peters@gmail.com>
parents:
21964
diff
changeset
|
448 there has to be a circular reference. */ |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24078
diff
changeset
|
449 static PyTypeObject sock_type; |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
450 |
|
39059
52a8738f5ab4
#1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents:
39043
diff
changeset
|
451 #if defined(HAVE_POLL_H) |
|
52a8738f5ab4
#1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents:
39043
diff
changeset
|
452 #include <poll.h> |
|
52a8738f5ab4
#1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents:
39043
diff
changeset
|
453 #elif defined(HAVE_SYS_POLL_H) |
|
52a8738f5ab4
#1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents:
39043
diff
changeset
|
454 #include <sys/poll.h> |
|
52a8738f5ab4
#1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents:
39043
diff
changeset
|
455 #endif |
|
52a8738f5ab4
#1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents:
39043
diff
changeset
|
456 |
|
36476
c073dffbe70e
Introduce Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE.
Martin v. Löwis <martin@v.loewis.de>
parents:
36452
diff
changeset
|
457 #ifdef Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE |
|
c073dffbe70e
Introduce Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE.
Martin v. Löwis <martin@v.loewis.de>
parents:
36452
diff
changeset
|
458 /* Platform can select file descriptors beyond FD_SETSIZE */ |
|
c073dffbe70e
Introduce Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE.
Martin v. Löwis <martin@v.loewis.de>
parents:
36452
diff
changeset
|
459 #define IS_SELECTABLE(s) 1 |
|
39059
52a8738f5ab4
#1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents:
39043
diff
changeset
|
460 #elif defined(HAVE_POLL) |
|
52a8738f5ab4
#1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents:
39043
diff
changeset
|
461 /* Instead of select(), we'll use poll() since poll() works on any fd. */ |
|
52a8738f5ab4
#1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents:
39043
diff
changeset
|
462 #define IS_SELECTABLE(s) 1 |
|
52a8738f5ab4
#1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents:
39043
diff
changeset
|
463 /* Can we call select() with this socket without a buffer overrun? */ |
|
36476
c073dffbe70e
Introduce Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE.
Martin v. Löwis <martin@v.loewis.de>
parents:
36452
diff
changeset
|
464 #else |
|
c073dffbe70e
Introduce Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE.
Martin v. Löwis <martin@v.loewis.de>
parents:
36452
diff
changeset
|
465 /* POSIX says selecting file descriptors beyond FD_SETSIZE |
|
39059
52a8738f5ab4
#1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents:
39043
diff
changeset
|
466 has undefined behaviour. If there's no timeout left, we don't have to |
|
52a8738f5ab4
#1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents:
39043
diff
changeset
|
467 call select, so it's a safe, little white lie. */ |
|
52a8738f5ab4
#1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents:
39043
diff
changeset
|
468 #define IS_SELECTABLE(s) ((s)->sock_fd < FD_SETSIZE || s->sock_timeout <= 0.0) |
|
36476
c073dffbe70e
Introduce Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE.
Martin v. Löwis <martin@v.loewis.de>
parents:
36452
diff
changeset
|
469 #endif |
|
36452
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
470 |
|
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
471 static PyObject* |
|
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
472 select_error(void) |
|
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
473 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
474 PyErr_SetString(socket_error, "unable to select on socket"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
475 return NULL; |
|
36452
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
476 } |
|
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
477 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
478 /* Convenience function to raise an error according to errno |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
479 and return a NULL pointer from a function. */ |
| 294 | 480 |
| 1970 | 481 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
482 set_error(void) |
| 294 | 483 { |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
484 #ifdef MS_WINDOWS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
485 int err_no = WSAGetLastError(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
486 /* PyErr_SetExcFromWindowsErr() invokes FormatMessage() which |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
487 recognizes the error codes used by both GetLastError() and |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
488 WSAGetLastError */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
489 if (err_no) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
490 return PyErr_SetExcFromWindowsErr(socket_error, err_no); |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
491 #endif |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
492 |
|
22115
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
493 #if defined(PYOS_OS2) && !defined(PYCC_GCC) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
494 if (sock_errno() != NO_ERROR) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
495 APIRET rc; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
496 ULONG msglen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
497 char outbuf[100]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
498 int myerrorcode = sock_errno(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
499 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
500 /* Retrieve socket-related error message from MPTN.MSG file */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
501 rc = DosGetMessage(NULL, 0, outbuf, sizeof(outbuf), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
502 myerrorcode - SOCBASEERR + 26, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
503 "mptn.msg", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
504 &msglen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
505 if (rc == NO_ERROR) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
506 PyObject *v; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
507 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
508 /* OS/2 doesn't guarantee a terminator */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
509 outbuf[msglen] = '\0'; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
510 if (strlen(outbuf) > 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
511 /* If non-empty msg, trim CRLF */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
512 char *lastc = &outbuf[ strlen(outbuf)-1 ]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
513 while (lastc > outbuf && |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
514 isspace(Py_CHARMASK(*lastc))) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
515 /* Trim trailing whitespace (CRLF) */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
516 *lastc-- = '\0'; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
517 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
518 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
519 v = Py_BuildValue("(is)", myerrorcode, outbuf); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
520 if (v != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
521 PyErr_SetObject(socket_error, v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
522 Py_DECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
523 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
524 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
525 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
526 } |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
527 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
528 |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
529 #if defined(RISCOS) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
530 if (_inet_error.errnum != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
531 PyObject *v; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
532 v = Py_BuildValue("(is)", errno, _inet_err()); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
533 if (v != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
534 PyErr_SetObject(socket_error, v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
535 Py_DECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
536 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
537 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
538 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
539 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
540 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
541 return PyErr_SetFromErrno(socket_error); |
| 294 | 542 } |
| 543 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
544 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
545 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
546 set_herror(int h_error) |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
547 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
548 PyObject *v; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
549 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
550 #ifdef HAVE_HSTRERROR |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
551 v = Py_BuildValue("(is)", h_error, (char *)hstrerror(h_error)); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
552 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
553 v = Py_BuildValue("(is)", h_error, "host not found"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
554 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
555 if (v != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
556 PyErr_SetObject(socket_herror, v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
557 Py_DECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
558 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
559 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
560 return NULL; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
561 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
562 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
563 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
564 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
565 set_gaierror(int error) |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
566 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
567 PyObject *v; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
568 |
|
22096
9e5ff6747437
Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents:
21970
diff
changeset
|
569 #ifdef EAI_SYSTEM |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
570 /* EAI_SYSTEM is not available on Windows XP. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
571 if (error == EAI_SYSTEM) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
572 return set_error(); |
|
22096
9e5ff6747437
Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents:
21970
diff
changeset
|
573 #endif |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
574 |
|
19278
1afc3116c602
Fix portability problems with glibc 2.0, as reported in #449157.
Martin v. Löwis <martin@v.loewis.de>
parents:
19197
diff
changeset
|
575 #ifdef HAVE_GAI_STRERROR |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
576 v = Py_BuildValue("(is)", error, gai_strerror(error)); |
|
19278
1afc3116c602
Fix portability problems with glibc 2.0, as reported in #449157.
Martin v. Löwis <martin@v.loewis.de>
parents:
19197
diff
changeset
|
577 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
578 v = Py_BuildValue("(is)", error, "getaddrinfo failed"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
579 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
580 if (v != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
581 PyErr_SetObject(socket_gaierror, v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
582 Py_DECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
583 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
584 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
585 return NULL; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
586 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
587 |
|
39043
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
588 #ifdef __VMS |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
589 /* Function to send in segments */ |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
590 static int |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
591 sendsegmented(int sock_fd, char *buf, int len, int flags) |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
592 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
593 int n = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
594 int remaining = len; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
595 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
596 while (remaining > 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
597 unsigned int segment; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
598 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
599 segment = (remaining >= SEGMENT_SIZE ? SEGMENT_SIZE : remaining); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
600 n = send(sock_fd, buf, segment, flags); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
601 if (n < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
602 return n; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
603 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
604 remaining -= segment; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
605 buf += segment; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
606 } /* end while */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
607 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
608 return len; |
|
39043
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
609 } |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
610 #endif |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
611 |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
612 /* Function to perform the setting of socket blocking mode |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
613 internally. block = (1 | 0). */ |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
614 static int |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
615 internal_setblocking(PySocketSockObject *s, int block) |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
616 { |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
617 #ifndef RISCOS |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
618 #ifndef MS_WINDOWS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
619 int delay_flag; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
620 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
621 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
622 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
623 Py_BEGIN_ALLOW_THREADS |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
624 #ifdef __BEOS__ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
625 block = !block; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
626 setsockopt(s->sock_fd, SOL_SOCKET, SO_NONBLOCK, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
627 (void *)(&block), sizeof(int)); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
628 #else |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
629 #ifndef RISCOS |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
630 #ifndef MS_WINDOWS |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
631 #if defined(PYOS_OS2) && !defined(PYCC_GCC) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
632 block = !block; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
633 ioctl(s->sock_fd, FIONBIO, (caddr_t)&block, sizeof(block)); |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25994
diff
changeset
|
634 #elif defined(__VMS) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
635 block = !block; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
636 ioctl(s->sock_fd, FIONBIO, (unsigned int *)&block); |
|
39043
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
637 #else /* !PYOS_OS2 && !__VMS */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
638 delay_flag = fcntl(s->sock_fd, F_GETFL, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
639 if (block) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
640 delay_flag &= (~O_NONBLOCK); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
641 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
642 delay_flag |= O_NONBLOCK; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
643 fcntl(s->sock_fd, F_SETFL, delay_flag); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
644 #endif /* !PYOS_OS2 */ |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
645 #else /* MS_WINDOWS */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
646 block = !block; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
647 ioctlsocket(s->sock_fd, FIONBIO, (u_long*)&block); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
648 #endif /* MS_WINDOWS */ |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
649 #else /* RISCOS */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
650 block = !block; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
651 socketioctl(s->sock_fd, FIONBIO, (u_long*)&block); |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
652 #endif /* RISCOS */ |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
653 #endif /* __BEOS__ */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
654 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
655 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
656 /* Since these don't return anything */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
657 return 1; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
658 } |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
659 |
|
39059
52a8738f5ab4
#1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents:
39043
diff
changeset
|
660 /* Do a select()/poll() on the socket, if necessary (sock_timeout > 0). |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
661 The argument writing indicates the direction. |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
662 This does not raise an exception; we'll let our caller do that |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
663 after they've reacquired the interpreter lock. |
|
39354
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
39251
diff
changeset
|
664 Returns 1 on timeout, -1 on error, 0 otherwise. */ |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
665 static int |
|
23722
75c51999c8d5
Correct several blunders in the timeout code, mostly my own fault (for
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
666 internal_select(PySocketSockObject *s, int writing) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
667 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
668 int n; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
669 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
670 /* Nothing to do unless we're in timeout mode (not non-blocking) */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
671 if (s->sock_timeout <= 0.0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
672 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
673 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
674 /* Guard against closed socket */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
675 if (s->sock_fd < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
676 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
677 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
678 /* Prefer poll, if available, since you can poll() any fd |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
679 * which can't be done with select(). */ |
|
39059
52a8738f5ab4
#1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents:
39043
diff
changeset
|
680 #ifdef HAVE_POLL |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
681 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
682 struct pollfd pollfd; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
683 int timeout; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
684 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
685 pollfd.fd = s->sock_fd; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
686 pollfd.events = writing ? POLLOUT : POLLIN; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
687 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
688 /* s->sock_timeout is in seconds, timeout in ms */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
689 timeout = (int)(s->sock_timeout * 1000 + 0.5); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
690 n = poll(&pollfd, 1, timeout); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
691 } |
|
39059
52a8738f5ab4
#1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents:
39043
diff
changeset
|
692 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
693 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
694 /* Construct the arguments to select */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
695 fd_set fds; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
696 struct timeval tv; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
697 tv.tv_sec = (int)s->sock_timeout; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
698 tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
699 FD_ZERO(&fds); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
700 FD_SET(s->sock_fd, &fds); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
701 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
702 /* See if the socket is ready */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
703 if (writing) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
704 n = select(s->sock_fd+1, NULL, &fds, NULL, &tv); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
705 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
706 n = select(s->sock_fd+1, &fds, NULL, NULL, &tv); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
707 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
708 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
709 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
710 if (n < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
711 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
712 if (n == 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
713 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
714 return 0; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
715 } |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
716 |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
717 /* Initialize a new socket object. */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
718 |
|
24305
428cbbf05639
A Python float is a C double; redeclare defaulttimeout as such; stops
Tim Peters <tim.peters@gmail.com>
parents:
24303
diff
changeset
|
719 static double defaulttimeout = -1.0; /* Default timeout for new sockets */ |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
720 |
|
24363
979ff5d0ae07
Replace DL_IMPORT with PyMODINIT_FUNC and remove "/export:init..." link
Mark Hammond <mhammond@skippinet.com.au>
parents:
24317
diff
changeset
|
721 PyMODINIT_FUNC |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
722 init_sockobject(PySocketSockObject *s, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
723 SOCKET_T fd, int family, int type, int proto) |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
724 { |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
725 #ifdef RISCOS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
726 int block = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
727 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
728 s->sock_fd = fd; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
729 s->sock_family = family; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
730 s->sock_type = type; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
731 s->sock_proto = proto; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
732 s->sock_timeout = defaulttimeout; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
733 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
734 s->errorhandler = &set_error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
735 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
736 if (defaulttimeout >= 0.0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
737 internal_setblocking(s, 0); |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
738 |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
739 #ifdef RISCOS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
740 if (taskwindow) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
741 socketioctl(s->sock_fd, 0x80046679, (u_long*)&block); |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
742 #endif |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
743 } |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
744 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
745 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
746 /* Create a new socket object. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
747 This just creates the object and initializes it. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
748 If the creation fails, return NULL and set an exception (implicit |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
749 in NEWOBJ()). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
750 |
| 1970 | 751 static PySocketSockObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
752 new_sockobject(SOCKET_T fd, int family, int type, int proto) |
| 294 | 753 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
754 PySocketSockObject *s; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
755 s = (PySocketSockObject *) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
756 PyType_GenericNew(&sock_type, NULL, NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
757 if (s != NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
758 init_sockobject(s, fd, family, type, proto); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
759 return s; |
| 294 | 760 } |
| 761 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
762 |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
763 /* Lock to allow python interpreter to continue, but only allow one |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
764 thread to be in gethostbyname or getaddrinfo */ |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
765 #if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK) |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
766 PyThread_type_lock netdb_lock; |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
767 #endif |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
768 |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
769 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
770 /* Convert a string specifying a host name or one of a few symbolic |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
771 names to a numeric IP address. This usually calls gethostbyname() |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
772 to do the work; the names "" and "<broadcast>" are special. |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
773 Return the length (IPv4 should be 4 bytes), or negative if |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
774 an error occurred; then an exception is raised. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
775 |
| 294 | 776 static int |
|
24411
8e266d0acd10
Pass length of result structure into setipaddr. Fixes bug #565747.
Martin v. Löwis <martin@v.loewis.de>
parents:
24380
diff
changeset
|
777 setipaddr(char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int af) |
| 294 | 778 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
779 struct addrinfo hints, *res; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
780 int error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
781 int d1, d2, d3, d4; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
782 char ch; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
783 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
784 memset((void *) addr_ret, '\0', sizeof(*addr_ret)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
785 if (name[0] == '\0') { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
786 int siz; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
787 memset(&hints, 0, sizeof(hints)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
788 hints.ai_family = af; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
789 hints.ai_socktype = SOCK_DGRAM; /*dummy*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
790 hints.ai_flags = AI_PASSIVE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
791 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
792 ACQUIRE_GETADDRINFO_LOCK |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
793 error = getaddrinfo(NULL, "0", &hints, &res); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
794 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
795 /* We assume that those thread-unsafe getaddrinfo() versions |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
796 *are* safe regarding their return value, ie. that a |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
797 subsequent call to getaddrinfo() does not destroy the |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
798 outcome of the first call. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
799 RELEASE_GETADDRINFO_LOCK |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
800 if (error) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
801 set_gaierror(error); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
802 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
803 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
804 switch (res->ai_family) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
805 case AF_INET: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
806 siz = 4; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
807 break; |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
808 #ifdef ENABLE_IPV6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
809 case AF_INET6: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
810 siz = 16; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
811 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
812 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
813 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
814 freeaddrinfo(res); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
815 PyErr_SetString(socket_error, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
816 "unsupported address family"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
817 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
818 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
819 if (res->ai_next) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
820 freeaddrinfo(res); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
821 PyErr_SetString(socket_error, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
822 "wildcard resolved to multiple address"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
823 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
824 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
825 if (res->ai_addrlen < addr_ret_size) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
826 addr_ret_size = res->ai_addrlen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
827 memcpy(addr_ret, res->ai_addr, addr_ret_size); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
828 freeaddrinfo(res); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
829 return siz; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
830 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
831 if (name[0] == '<' && strcmp(name, "<broadcast>") == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
832 struct sockaddr_in *sin; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
833 if (af != AF_INET && af != AF_UNSPEC) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
834 PyErr_SetString(socket_error, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
835 "address family mismatched"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
836 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
837 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
838 sin = (struct sockaddr_in *)addr_ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
839 memset((void *) sin, '\0', sizeof(*sin)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
840 sin->sin_family = AF_INET; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
841 #ifdef HAVE_SOCKADDR_SA_LEN |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
842 sin->sin_len = sizeof(*sin); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
843 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
844 sin->sin_addr.s_addr = INADDR_BROADCAST; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
845 return sizeof(sin->sin_addr); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
846 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
847 if (sscanf(name, "%d.%d.%d.%d%c", &d1, &d2, &d3, &d4, &ch) == 4 && |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
848 0 <= d1 && d1 <= 255 && 0 <= d2 && d2 <= 255 && |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
849 0 <= d3 && d3 <= 255 && 0 <= d4 && d4 <= 255) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
850 struct sockaddr_in *sin; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
851 sin = (struct sockaddr_in *)addr_ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
852 sin->sin_addr.s_addr = htonl( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
853 ((long) d1 << 24) | ((long) d2 << 16) | |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
854 ((long) d3 << 8) | ((long) d4 << 0)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
855 sin->sin_family = AF_INET; |
|
28925
a769e079bb12
Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents:
28913
diff
changeset
|
856 #ifdef HAVE_SOCKADDR_SA_LEN |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
857 sin->sin_len = sizeof(*sin); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
858 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
859 return 4; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
860 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
861 memset(&hints, 0, sizeof(hints)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
862 hints.ai_family = af; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
863 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
864 ACQUIRE_GETADDRINFO_LOCK |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
865 error = getaddrinfo(name, NULL, &hints, &res); |
|
20661
f7009167dd67
After discussion with itojun, it was clarified that Tru64 is in error,
Martin v. Löwis <martin@v.loewis.de>
parents:
20654
diff
changeset
|
866 #if defined(__digital__) && defined(__unix__) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
867 if (error == EAI_NONAME && af == AF_UNSPEC) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
868 /* On Tru64 V5.1, numeric-to-addr conversion fails |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
869 if no address family is given. Assume IPv4 for now.*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
870 hints.ai_family = AF_INET; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
871 error = getaddrinfo(name, NULL, &hints, &res); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
872 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
873 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
874 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
875 RELEASE_GETADDRINFO_LOCK /* see comment in setipaddr() */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
876 if (error) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
877 set_gaierror(error); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
878 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
879 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
880 if (res->ai_addrlen < addr_ret_size) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
881 addr_ret_size = res->ai_addrlen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
882 memcpy((char *) addr_ret, res->ai_addr, addr_ret_size); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
883 freeaddrinfo(res); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
884 switch (addr_ret->sa_family) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
885 case AF_INET: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
886 return 4; |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
887 #ifdef ENABLE_IPV6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
888 case AF_INET6: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
889 return 16; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
890 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
891 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
892 PyErr_SetString(socket_error, "unknown address family"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
893 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
894 } |
| 294 | 895 } |
| 896 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
897 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
898 /* Create a string object representing an IP address. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
899 This is always a string of the form 'dd.dd.dd.dd' (with variable |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
900 size numbers). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
901 |
| 1970 | 902 static PyObject * |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
903 makeipaddr(struct sockaddr *addr, int addrlen) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
904 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
905 char buf[NI_MAXHOST]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
906 int error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
907 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
908 error = getnameinfo(addr, addrlen, buf, sizeof(buf), NULL, 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
909 NI_NUMERICHOST); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
910 if (error) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
911 set_gaierror(error); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
912 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
913 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
914 return PyString_FromString(buf); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
915 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
916 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
917 |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
918 #ifdef USE_BLUETOOTH |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
919 /* Convert a string representation of a Bluetooth address into a numeric |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
920 address. Returns the length (6), or raises an exception and returns -1 if |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
921 an error occurred. */ |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
922 |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
923 static int |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
924 setbdaddr(char *name, bdaddr_t *bdaddr) |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
925 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
926 unsigned int b0, b1, b2, b3, b4, b5; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
927 char ch; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
928 int n; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
929 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
930 n = sscanf(name, "%X:%X:%X:%X:%X:%X%c", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
931 &b5, &b4, &b3, &b2, &b1, &b0, &ch); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
932 if (n == 6 && (b0 | b1 | b2 | b3 | b4 | b5) < 256) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
933 bdaddr->b[0] = b0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
934 bdaddr->b[1] = b1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
935 bdaddr->b[2] = b2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
936 bdaddr->b[3] = b3; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
937 bdaddr->b[4] = b4; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
938 bdaddr->b[5] = b5; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
939 return 6; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
940 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
941 PyErr_SetString(socket_error, "bad bluetooth address"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
942 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
943 } |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
944 } |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
945 |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
946 /* Create a string representation of the Bluetooth address. This is always a |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
947 string of the form 'XX:XX:XX:XX:XX:XX' where XX is a two digit hexadecimal |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
948 value (zero padded if necessary). */ |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
949 |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
950 static PyObject * |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
951 makebdaddr(bdaddr_t *bdaddr) |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
952 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
953 char buf[(6 * 2) + 5 + 1]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
954 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
955 sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
956 bdaddr->b[5], bdaddr->b[4], bdaddr->b[3], |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
957 bdaddr->b[2], bdaddr->b[1], bdaddr->b[0]); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
958 return PyString_FromString(buf); |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
959 } |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
960 #endif |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
961 |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
962 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
963 /* Create an object representing the given socket address, |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
964 suitable for passing it back to bind(), connect() etc. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
965 The family field of the sockaddr structure is inspected |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
966 to determine what kind of address it really is. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
967 |
| 294 | 968 /*ARGSUSED*/ |
| 1970 | 969 static PyObject * |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
970 makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto) |
| 294 | 971 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
972 if (addrlen == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
973 /* No address -- may be recvfrom() from known socket */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
974 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
975 return Py_None; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
976 } |
|
925
61143bf03b44
Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
977 |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
978 #ifdef __BEOS__ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
979 /* XXX: BeOS version of accept() doesn't set family correctly */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
980 addr->sa_family = AF_INET; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
981 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
982 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
983 switch (addr->sa_family) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
984 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
985 case AF_INET: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
986 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
987 struct sockaddr_in *a; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
988 PyObject *addrobj = makeipaddr(addr, sizeof(*a)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
989 PyObject *ret = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
990 if (addrobj) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
991 a = (struct sockaddr_in *)addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
992 ret = Py_BuildValue("Oi", addrobj, ntohs(a->sin_port)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
993 Py_DECREF(addrobj); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
994 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
995 return ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
996 } |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
997 |
|
31867
51aaceeaabe1
OS/2's TCP/IP stack supports AF_UNIX sockets, with the limitation that
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
31790
diff
changeset
|
998 #if defined(AF_UNIX) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
999 case AF_UNIX: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1000 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1001 struct sockaddr_un *a = (struct sockaddr_un *) addr; |
|
37853
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37732
diff
changeset
|
1002 #ifdef linux |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1003 if (a->sun_path[0] == 0) { /* Linux abstract namespace */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1004 addrlen -= offsetof(struct sockaddr_un, sun_path); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1005 return PyString_FromStringAndSize(a->sun_path, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1006 addrlen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1007 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1008 else |
|
37853
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37732
diff
changeset
|
1009 #endif /* linux */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1010 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1011 /* regular NULL-terminated string */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1012 return PyString_FromString(a->sun_path); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1013 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1014 } |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1015 #endif /* AF_UNIX */ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1016 |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1017 #if defined(AF_NETLINK) |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1018 case AF_NETLINK: |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1019 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1020 struct sockaddr_nl *a = (struct sockaddr_nl *) addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1021 return Py_BuildValue("II", a->nl_pid, a->nl_groups); |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1022 } |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1023 #endif /* AF_NETLINK */ |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1024 |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
1025 #ifdef ENABLE_IPV6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1026 case AF_INET6: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1027 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1028 struct sockaddr_in6 *a; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1029 PyObject *addrobj = makeipaddr(addr, sizeof(*a)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1030 PyObject *ret = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1031 if (addrobj) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1032 a = (struct sockaddr_in6 *)addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1033 ret = Py_BuildValue("Oiii", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1034 addrobj, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1035 ntohs(a->sin6_port), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1036 a->sin6_flowinfo, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1037 a->sin6_scope_id); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1038 Py_DECREF(addrobj); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1039 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1040 return ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1041 } |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1042 #endif |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1043 |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1044 #ifdef USE_BLUETOOTH |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1045 case AF_BLUETOOTH: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1046 switch (proto) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1047 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1048 case BTPROTO_L2CAP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1049 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1050 struct sockaddr_l2 *a = (struct sockaddr_l2 *) addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1051 PyObject *addrobj = makebdaddr(&_BT_L2_MEMB(a, bdaddr)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1052 PyObject *ret = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1053 if (addrobj) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1054 ret = Py_BuildValue("Oi", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1055 addrobj, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1056 _BT_L2_MEMB(a, psm)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1057 Py_DECREF(addrobj); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1058 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1059 return ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1060 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1061 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1062 case BTPROTO_RFCOMM: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1063 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1064 struct sockaddr_rc *a = (struct sockaddr_rc *) addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1065 PyObject *addrobj = makebdaddr(&_BT_RC_MEMB(a, bdaddr)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1066 PyObject *ret = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1067 if (addrobj) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1068 ret = Py_BuildValue("Oi", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1069 addrobj, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1070 _BT_RC_MEMB(a, channel)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1071 Py_DECREF(addrobj); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1072 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1073 return ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1074 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1075 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1076 case BTPROTO_HCI: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1077 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1078 struct sockaddr_hci *a = (struct sockaddr_hci *) addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1079 PyObject *ret = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1080 ret = Py_BuildValue("i", _BT_HCI_MEMB(a, dev)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1081 return ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1082 } |
|
40842
90e22fea8363
Patch #1432399: Add HCI sockets.
Martin v. Löwis <martin@v.loewis.de>
parents:
40837
diff
changeset
|
1083 |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1084 #if !defined(__FreeBSD__) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1085 case BTPROTO_SCO: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1086 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1087 struct sockaddr_sco *a = (struct sockaddr_sco *) addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1088 return makebdaddr(&_BT_SCO_MEMB(a, bdaddr)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1089 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1090 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1091 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1092 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1093 PyErr_SetString(PyExc_ValueError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1094 "Unknown Bluetooth protocol"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1095 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1096 } |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1097 #endif |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1098 |
|
19151
cd44254360b6
Autotest for netpacket/packet.h, as it is not available on all Linux versions.
Martin v. Löwis <martin@v.loewis.de>
parents:
18997
diff
changeset
|
1099 #ifdef HAVE_NETPACKET_PACKET_H |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1100 case AF_PACKET: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1101 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1102 struct sockaddr_ll *a = (struct sockaddr_ll *)addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1103 char *ifname = ""; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1104 struct ifreq ifr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1105 /* need to look up interface name give index */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1106 if (a->sll_ifindex) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1107 ifr.ifr_ifindex = a->sll_ifindex; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1108 if (ioctl(sockfd, SIOCGIFNAME, &ifr) == 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1109 ifname = ifr.ifr_name; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1110 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1111 return Py_BuildValue("shbhs#", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1112 ifname, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1113 ntohs(a->sll_protocol), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1114 a->sll_pkttype, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1115 a->sll_hatype, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1116 a->sll_addr, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1117 a->sll_halen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1118 } |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1119 #endif |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1120 |
|
44561
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44474
diff
changeset
|
1121 #ifdef HAVE_LINUX_TIPC_H |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1122 case AF_TIPC: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1123 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1124 struct sockaddr_tipc *a = (struct sockaddr_tipc *) addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1125 if (a->addrtype == TIPC_ADDR_NAMESEQ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1126 return Py_BuildValue("IIIII", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1127 a->addrtype, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1128 a->addr.nameseq.type, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1129 a->addr.nameseq.lower, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1130 a->addr.nameseq.upper, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1131 a->scope); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1132 } else if (a->addrtype == TIPC_ADDR_NAME) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1133 return Py_BuildValue("IIIII", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1134 a->addrtype, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1135 a->addr.name.name.type, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1136 a->addr.name.name.instance, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1137 a->addr.name.name.instance, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1138 a->scope); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1139 } else if (a->addrtype == TIPC_ADDR_ID) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1140 return Py_BuildValue("IIIII", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1141 a->addrtype, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1142 a->addr.id.node, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1143 a->addr.id.ref, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1144 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1145 a->scope); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1146 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1147 PyErr_SetString(PyExc_ValueError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1148 "Invalid address type"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1149 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1150 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1151 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1152 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1153 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1154 /* More cases here... */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1155 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1156 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1157 /* If we don't know the address family, don't raise an |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1158 exception -- return it as a tuple. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1159 return Py_BuildValue("is#", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1160 addr->sa_family, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1161 addr->sa_data, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1162 sizeof(addr->sa_data)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1163 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1164 } |
| 294 | 1165 } |
| 1166 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1167 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1168 /* Parse a socket address argument according to the socket object's |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1169 address family. Return 1 if the address was in the proper format, |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1170 0 of not. The address is returned through addr_ret, its length |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1171 through len_ret. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1172 |
| 294 | 1173 static int |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1174 getsockaddrarg(PySocketSockObject *s, PyObject *args, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1175 struct sockaddr *addr_ret, int *len_ret) |
| 294 | 1176 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1177 switch (s->sock_family) { |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1178 |
|
31867
51aaceeaabe1
OS/2's TCP/IP stack supports AF_UNIX sockets, with the limitation that
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
31790
diff
changeset
|
1179 #if defined(AF_UNIX) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1180 case AF_UNIX: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1181 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1182 struct sockaddr_un* addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1183 char *path; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1184 int len; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1185 if (!PyArg_Parse(args, "t#", &path, &len)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1186 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1187 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1188 addr = (struct sockaddr_un*)addr_ret; |
|
37853
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37732
diff
changeset
|
1189 #ifdef linux |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1190 if (len > 0 && path[0] == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1191 /* Linux abstract namespace extension */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1192 if (len > sizeof addr->sun_path) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1193 PyErr_SetString(socket_error, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1194 "AF_UNIX path too long"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1195 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1196 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1197 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1198 else |
|
37853
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37732
diff
changeset
|
1199 #endif /* linux */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1200 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1201 /* regular NULL-terminated string */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1202 if (len >= sizeof addr->sun_path) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1203 PyErr_SetString(socket_error, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1204 "AF_UNIX path too long"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1205 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1206 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1207 addr->sun_path[len] = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1208 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1209 addr->sun_family = s->sock_family; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1210 memcpy(addr->sun_path, path, len); |
|
31896
ca2fb5cf2fd5
Fixes for AF_UNIX support on OS/2:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
31867
diff
changeset
|
1211 #if defined(PYOS_OS2) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1212 *len_ret = sizeof(*addr); |
|
31896
ca2fb5cf2fd5
Fixes for AF_UNIX support on OS/2:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
31867
diff
changeset
|
1213 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1214 *len_ret = len + offsetof(struct sockaddr_un, sun_path); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1215 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1216 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1217 } |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1218 #endif /* AF_UNIX */ |
| 294 | 1219 |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1220 #if defined(AF_NETLINK) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1221 case AF_NETLINK: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1222 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1223 struct sockaddr_nl* addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1224 int pid, groups; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1225 addr = (struct sockaddr_nl *)addr_ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1226 if (!PyTuple_Check(args)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1227 PyErr_Format( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1228 PyExc_TypeError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1229 "getsockaddrarg: " |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1230 "AF_NETLINK address must be tuple, not %.500s", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1231 Py_TYPE(args)->tp_name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1232 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1233 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1234 if (!PyArg_ParseTuple(args, "II:getsockaddrarg", &pid, &groups)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1235 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1236 addr->nl_family = AF_NETLINK; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1237 addr->nl_pid = pid; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1238 addr->nl_groups = groups; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1239 *len_ret = sizeof(*addr); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1240 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1241 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1242 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1243 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1244 case AF_INET: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1245 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1246 struct sockaddr_in* addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1247 char *host; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1248 int port, result; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1249 if (!PyTuple_Check(args)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1250 PyErr_Format( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1251 PyExc_TypeError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1252 "getsockaddrarg: " |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1253 "AF_INET address must be tuple, not %.500s", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1254 Py_TYPE(args)->tp_name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1255 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1256 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1257 if (!PyArg_ParseTuple(args, "eti:getsockaddrarg", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1258 "idna", &host, &port)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1259 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1260 addr=(struct sockaddr_in*)addr_ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1261 result = setipaddr(host, (struct sockaddr *)addr, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1262 sizeof(*addr), AF_INET); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1263 PyMem_Free(host); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1264 if (result < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1265 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1266 if (port < 0 || port > 0xffff) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1267 PyErr_SetString( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1268 PyExc_OverflowError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1269 "getsockaddrarg: port must be 0-65535."); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1270 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1271 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1272 addr->sin_family = AF_INET; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1273 addr->sin_port = htons((short)port); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1274 *len_ret = sizeof *addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1275 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1276 } |
| 294 | 1277 |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
1278 #ifdef ENABLE_IPV6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1279 case AF_INET6: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1280 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1281 struct sockaddr_in6* addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1282 char *host; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1283 int port, flowinfo, scope_id, result; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1284 flowinfo = scope_id = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1285 if (!PyTuple_Check(args)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1286 PyErr_Format( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1287 PyExc_TypeError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1288 "getsockaddrarg: " |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1289 "AF_INET6 address must be tuple, not %.500s", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1290 Py_TYPE(args)->tp_name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1291 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1292 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1293 if (!PyArg_ParseTuple(args, "eti|ii", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1294 "idna", &host, &port, &flowinfo, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1295 &scope_id)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1296 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1297 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1298 addr = (struct sockaddr_in6*)addr_ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1299 result = setipaddr(host, (struct sockaddr *)addr, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1300 sizeof(*addr), AF_INET6); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1301 PyMem_Free(host); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1302 if (result < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1303 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1304 if (port < 0 || port > 0xffff) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1305 PyErr_SetString( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1306 PyExc_OverflowError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1307 "getsockaddrarg: port must be 0-65535."); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1308 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1309 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1310 addr->sin6_family = s->sock_family; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1311 addr->sin6_port = htons((short)port); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1312 addr->sin6_flowinfo = flowinfo; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1313 addr->sin6_scope_id = scope_id; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1314 *len_ret = sizeof *addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1315 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1316 } |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1317 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1318 |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
1319 #ifdef USE_BLUETOOTH |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1320 case AF_BLUETOOTH: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1321 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1322 switch (s->sock_proto) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1323 case BTPROTO_L2CAP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1324 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1325 struct sockaddr_l2 *addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1326 char *straddr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1327 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1328 addr = (struct sockaddr_l2 *)addr_ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1329 memset(addr, 0, sizeof(struct sockaddr_l2)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1330 _BT_L2_MEMB(addr, family) = AF_BLUETOOTH; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1331 if (!PyArg_ParseTuple(args, "si", &straddr, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1332 &_BT_L2_MEMB(addr, psm))) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1333 PyErr_SetString(socket_error, "getsockaddrarg: " |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1334 "wrong format"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1335 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1336 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1337 if (setbdaddr(straddr, &_BT_L2_MEMB(addr, bdaddr)) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1338 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1339 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1340 *len_ret = sizeof *addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1341 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1342 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1343 case BTPROTO_RFCOMM: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1344 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1345 struct sockaddr_rc *addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1346 char *straddr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1347 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1348 addr = (struct sockaddr_rc *)addr_ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1349 _BT_RC_MEMB(addr, family) = AF_BLUETOOTH; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1350 if (!PyArg_ParseTuple(args, "si", &straddr, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1351 &_BT_RC_MEMB(addr, channel))) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1352 PyErr_SetString(socket_error, "getsockaddrarg: " |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1353 "wrong format"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1354 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1355 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1356 if (setbdaddr(straddr, &_BT_RC_MEMB(addr, bdaddr)) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1357 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1358 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1359 *len_ret = sizeof *addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1360 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1361 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1362 case BTPROTO_HCI: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1363 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1364 struct sockaddr_hci *addr = (struct sockaddr_hci *)addr_ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1365 _BT_HCI_MEMB(addr, family) = AF_BLUETOOTH; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1366 if (!PyArg_ParseTuple(args, "i", &_BT_HCI_MEMB(addr, dev))) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1367 PyErr_SetString(socket_error, "getsockaddrarg: " |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1368 "wrong format"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1369 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1370 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1371 *len_ret = sizeof *addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1372 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1373 } |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1374 #if !defined(__FreeBSD__) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1375 case BTPROTO_SCO: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1376 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1377 struct sockaddr_sco *addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1378 char *straddr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1379 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1380 addr = (struct sockaddr_sco *)addr_ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1381 _BT_SCO_MEMB(addr, family) = AF_BLUETOOTH; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1382 straddr = PyString_AsString(args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1383 if (straddr == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1384 PyErr_SetString(socket_error, "getsockaddrarg: " |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1385 "wrong format"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1386 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1387 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1388 if (setbdaddr(straddr, &_BT_SCO_MEMB(addr, bdaddr)) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1389 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1390 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1391 *len_ret = sizeof *addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1392 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1393 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1394 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1395 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1396 PyErr_SetString(socket_error, "getsockaddrarg: unknown Bluetooth protocol"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1397 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1398 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1399 } |
|
31441
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1400 #endif |
|
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1401 |
|
19151
cd44254360b6
Autotest for netpacket/packet.h, as it is not available on all Linux versions.
Martin v. Löwis <martin@v.loewis.de>
parents:
18997
diff
changeset
|
1402 #ifdef HAVE_NETPACKET_PACKET_H |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1403 case AF_PACKET: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1404 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1405 struct sockaddr_ll* addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1406 struct ifreq ifr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1407 char *interfaceName; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1408 int protoNumber; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1409 int hatype = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1410 int pkttype = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1411 char *haddr = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1412 unsigned int halen = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1413 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1414 if (!PyTuple_Check(args)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1415 PyErr_Format( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1416 PyExc_TypeError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1417 "getsockaddrarg: " |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1418 "AF_PACKET address must be tuple, not %.500s", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1419 Py_TYPE(args)->tp_name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1420 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1421 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1422 if (!PyArg_ParseTuple(args, "si|iis#", &interfaceName, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1423 &protoNumber, &pkttype, &hatype, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1424 &haddr, &halen)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1425 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1426 strncpy(ifr.ifr_name, interfaceName, sizeof(ifr.ifr_name)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1427 ifr.ifr_name[(sizeof(ifr.ifr_name))-1] = '\0'; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1428 if (ioctl(s->sock_fd, SIOCGIFINDEX, &ifr) < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1429 s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1430 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1431 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1432 if (halen > 8) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1433 PyErr_SetString(PyExc_ValueError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1434 "Hardware address must be 8 bytes or less"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1435 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1436 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1437 if (protoNumber < 0 || protoNumber > 0xffff) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1438 PyErr_SetString( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1439 PyExc_OverflowError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1440 "getsockaddrarg: protoNumber must be 0-65535."); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1441 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1442 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1443 addr = (struct sockaddr_ll*)addr_ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1444 addr->sll_family = AF_PACKET; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1445 addr->sll_protocol = htons((short)protoNumber); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1446 addr->sll_ifindex = ifr.ifr_ifindex; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1447 addr->sll_pkttype = pkttype; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1448 addr->sll_hatype = hatype; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1449 if (halen != 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1450 memcpy(&addr->sll_addr, haddr, halen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1451 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1452 addr->sll_halen = halen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1453 *len_ret = sizeof *addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1454 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1455 } |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1456 #endif |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1457 |
|
44561
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44474
diff
changeset
|
1458 #ifdef HAVE_LINUX_TIPC_H |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1459 case AF_TIPC: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1460 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1461 unsigned int atype, v1, v2, v3; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1462 unsigned int scope = TIPC_CLUSTER_SCOPE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1463 struct sockaddr_tipc *addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1464 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1465 if (!PyTuple_Check(args)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1466 PyErr_Format( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1467 PyExc_TypeError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1468 "getsockaddrarg: " |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1469 "AF_TIPC address must be tuple, not %.500s", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1470 Py_TYPE(args)->tp_name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1471 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1472 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1473 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1474 if (!PyArg_ParseTuple(args, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1475 "IIII|I;Invalid TIPC address format", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1476 &atype, &v1, &v2, &v3, &scope)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1477 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1478 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1479 addr = (struct sockaddr_tipc *) addr_ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1480 memset(addr, 0, sizeof(struct sockaddr_tipc)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1481 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1482 addr->family = AF_TIPC; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1483 addr->scope = scope; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1484 addr->addrtype = atype; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1485 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1486 if (atype == TIPC_ADDR_NAMESEQ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1487 addr->addr.nameseq.type = v1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1488 addr->addr.nameseq.lower = v2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1489 addr->addr.nameseq.upper = v3; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1490 } else if (atype == TIPC_ADDR_NAME) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1491 addr->addr.name.name.type = v1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1492 addr->addr.name.name.instance = v2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1493 } else if (atype == TIPC_ADDR_ID) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1494 addr->addr.id.node = v1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1495 addr->addr.id.ref = v2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1496 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1497 /* Shouldn't happen */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1498 PyErr_SetString(PyExc_TypeError, "Invalid address type"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1499 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1500 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1501 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1502 *len_ret = sizeof(*addr); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1503 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1504 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1505 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1506 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1507 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1508 /* More cases here... */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1509 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1510 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1511 PyErr_SetString(socket_error, "getsockaddrarg: bad family"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1512 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1513 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1514 } |
| 294 | 1515 } |
| 1516 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1517 |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1518 /* Get the address length according to the socket object's address family. |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1519 Return 1 if the family is known, 0 otherwise. The length is returned |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1520 through len_ret. */ |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1521 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1522 static int |
|
13554
906efc1da247
Errare humanum est.
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13538
diff
changeset
|
1523 getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret) |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1524 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1525 switch (s->sock_family) { |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1526 |
|
31867
51aaceeaabe1
OS/2's TCP/IP stack supports AF_UNIX sockets, with the limitation that
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
31790
diff
changeset
|
1527 #if defined(AF_UNIX) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1528 case AF_UNIX: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1529 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1530 *len_ret = sizeof (struct sockaddr_un); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1531 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1532 } |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1533 #endif /* AF_UNIX */ |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1534 #if defined(AF_NETLINK) |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1535 case AF_NETLINK: |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1536 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1537 *len_ret = sizeof (struct sockaddr_nl); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1538 return 1; |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1539 } |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1540 #endif |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1541 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1542 case AF_INET: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1543 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1544 *len_ret = sizeof (struct sockaddr_in); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1545 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1546 } |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1547 |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
1548 #ifdef ENABLE_IPV6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1549 case AF_INET6: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1550 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1551 *len_ret = sizeof (struct sockaddr_in6); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1552 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1553 } |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1554 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1555 |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
1556 #ifdef USE_BLUETOOTH |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1557 case AF_BLUETOOTH: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1558 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1559 switch(s->sock_proto) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1560 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1561 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1562 case BTPROTO_L2CAP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1563 *len_ret = sizeof (struct sockaddr_l2); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1564 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1565 case BTPROTO_RFCOMM: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1566 *len_ret = sizeof (struct sockaddr_rc); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1567 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1568 case BTPROTO_HCI: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1569 *len_ret = sizeof (struct sockaddr_hci); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1570 return 1; |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
1571 #if !defined(__FreeBSD__) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1572 case BTPROTO_SCO: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1573 *len_ret = sizeof (struct sockaddr_sco); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1574 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1575 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1576 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1577 PyErr_SetString(socket_error, "getsockaddrlen: " |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1578 "unknown BT protocol"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1579 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1580 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1581 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1582 } |
|
31441
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1583 #endif |
|
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1584 |
|
19151
cd44254360b6
Autotest for netpacket/packet.h, as it is not available on all Linux versions.
Martin v. Löwis <martin@v.loewis.de>
parents:
18997
diff
changeset
|
1585 #ifdef HAVE_NETPACKET_PACKET_H |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1586 case AF_PACKET: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1587 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1588 *len_ret = sizeof (struct sockaddr_ll); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1589 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1590 } |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1591 #endif |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1592 |
|
44561
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44474
diff
changeset
|
1593 #ifdef HAVE_LINUX_TIPC_H |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1594 case AF_TIPC: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1595 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1596 *len_ret = sizeof (struct sockaddr_tipc); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1597 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1598 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1599 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1600 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1601 /* More cases here... */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1602 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1603 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1604 PyErr_SetString(socket_error, "getsockaddrlen: bad family"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1605 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1606 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1607 } |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1608 } |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1609 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1610 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1611 /* s.accept() method */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1612 |
| 1970 | 1613 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1614 sock_accept(PySocketSockObject *s) |
| 294 | 1615 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1616 sock_addr_t addrbuf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1617 SOCKET_T newfd; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1618 socklen_t addrlen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1619 PyObject *sock = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1620 PyObject *addr = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1621 PyObject *res = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1622 int timeout; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1623 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1624 if (!getsockaddrlen(s, &addrlen)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1625 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1626 memset(&addrbuf, 0, addrlen); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1627 |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1628 #ifdef MS_WINDOWS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1629 newfd = INVALID_SOCKET; |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1630 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1631 newfd = -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1632 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1633 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1634 if (!IS_SELECTABLE(s)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1635 return select_error(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1636 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1637 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1638 timeout = internal_select(s, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1639 if (!timeout) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1640 newfd = accept(s->sock_fd, SAS2SA(&addrbuf), &addrlen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1641 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1642 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1643 if (timeout == 1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1644 PyErr_SetString(socket_timeout, "timed out"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1645 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1646 } |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1647 |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1648 #ifdef MS_WINDOWS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1649 if (newfd == INVALID_SOCKET) |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1650 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1651 if (newfd < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1652 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1653 return s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1654 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1655 /* Create the new object with unspecified family, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1656 to avoid calls to bind() etc. on it. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1657 sock = (PyObject *) new_sockobject(newfd, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1658 s->sock_family, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1659 s->sock_type, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1660 s->sock_proto); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1661 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1662 if (sock == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1663 SOCKETCLOSE(newfd); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1664 goto finally; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1665 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1666 addr = makesockaddr(s->sock_fd, SAS2SA(&addrbuf), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1667 addrlen, s->sock_proto); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1668 if (addr == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1669 goto finally; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1670 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1671 res = PyTuple_Pack(2, sock, addr); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1672 |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1673 finally: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1674 Py_XDECREF(sock); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1675 Py_XDECREF(addr); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1676 return res; |
| 294 | 1677 } |
| 1678 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1679 PyDoc_STRVAR(accept_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1680 "accept() -> (socket object, address info)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1681 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1682 Wait for an incoming connection. Return a new socket representing the\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1683 connection, and the address of the client. For IP sockets, the address\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1684 info is a pair (hostaddr, port)."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1685 |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1686 /* s.setblocking(flag) method. Argument: |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1687 False -- non-blocking mode; same as settimeout(0) |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1688 True -- blocking mode; same as settimeout(None) |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1689 */ |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
1690 |
| 1970 | 1691 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1692 sock_setblocking(PySocketSockObject *s, PyObject *arg) |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
1693 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1694 int block; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1695 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1696 block = PyInt_AsLong(arg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1697 if (block == -1 && PyErr_Occurred()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1698 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1699 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1700 s->sock_timeout = block ? -1.0 : 0.0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1701 internal_setblocking(s, block); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1702 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1703 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1704 return Py_None; |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
1705 } |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
1706 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1707 PyDoc_STRVAR(setblocking_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1708 "setblocking(flag)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1709 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1710 Set the socket to blocking (flag is true) or non-blocking (false).\n\ |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1711 setblocking(True) is equivalent to settimeout(None);\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1712 setblocking(False) is equivalent to settimeout(0.0)."); |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1713 |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1714 /* s.settimeout(timeout) method. Argument: |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1715 None -- no timeout, blocking mode; same as setblocking(True) |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1716 0.0 -- non-blocking mode; same as setblocking(False) |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1717 > 0 -- timeout mode; operations time out after timeout seconds |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1718 < 0 -- illegal; raises an exception |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1719 */ |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1720 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1721 sock_settimeout(PySocketSockObject *s, PyObject *arg) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1722 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1723 double timeout; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1724 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1725 if (arg == Py_None) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1726 timeout = -1.0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1727 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1728 timeout = PyFloat_AsDouble(arg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1729 if (timeout < 0.0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1730 if (!PyErr_Occurred()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1731 PyErr_SetString(PyExc_ValueError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1732 "Timeout value out of range"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1733 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1734 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1735 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1736 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1737 s->sock_timeout = timeout; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1738 internal_setblocking(s, timeout < 0.0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1739 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1740 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1741 return Py_None; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1742 } |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1743 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1744 PyDoc_STRVAR(settimeout_doc, |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1745 "settimeout(timeout)\n\ |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1746 \n\ |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1747 Set a timeout on socket operations. 'timeout' can be a float,\n\ |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1748 giving in seconds, or None. Setting a timeout of None disables\n\ |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1749 the timeout feature and is equivalent to setblocking(1).\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1750 Setting a timeout of zero is the same as setblocking(0)."); |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1751 |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1752 /* s.gettimeout() method. |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1753 Returns the timeout associated with a socket. */ |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1754 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1755 sock_gettimeout(PySocketSockObject *s) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1756 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1757 if (s->sock_timeout < 0.0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1758 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1759 return Py_None; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1760 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1761 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1762 return PyFloat_FromDouble(s->sock_timeout); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1763 } |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1764 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1765 PyDoc_STRVAR(gettimeout_doc, |
|
24676
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
1766 "gettimeout() -> timeout\n\ |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1767 \n\ |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1768 Returns the timeout in floating seconds associated with socket \n\ |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1769 operations. A timeout of None indicates that timeouts on socket \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1770 operations are disabled."); |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
1771 |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1772 #ifdef RISCOS |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1773 /* s.sleeptaskw(1 | 0) method */ |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1774 |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1775 static PyObject * |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
1776 sock_sleeptaskw(PySocketSockObject *s,PyObject *arg) |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1777 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1778 int block; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1779 block = PyInt_AsLong(arg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1780 if (block == -1 && PyErr_Occurred()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1781 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1782 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1783 socketioctl(s->sock_fd, 0x80046679, (u_long*)&block); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1784 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1785 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1786 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1787 return Py_None; |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1788 } |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1789 PyDoc_STRVAR(sleeptaskw_doc, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1790 "sleeptaskw(flag)\n\ |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1791 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1792 Allow sleeps in taskwindows."); |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1793 #endif |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1794 |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1795 |
|
1039
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1796 /* s.setsockopt() method. |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1797 With an integer third argument, sets an integer option. |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1798 With a string third argument, sets an option from a buffer; |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1799 use optional built-in module 'struct' to encode the string. */ |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1800 |
| 1970 | 1801 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1802 sock_setsockopt(PySocketSockObject *s, PyObject *args) |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1803 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1804 int level; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1805 int optname; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1806 int res; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1807 char *buf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1808 int buflen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1809 int flag; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1810 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1811 if (PyArg_ParseTuple(args, "iii:setsockopt", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1812 &level, &optname, &flag)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1813 buf = (char *) &flag; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1814 buflen = sizeof flag; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1815 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1816 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1817 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1818 if (!PyArg_ParseTuple(args, "iis#:setsockopt", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1819 &level, &optname, &buf, &buflen)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1820 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1821 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1822 res = setsockopt(s->sock_fd, level, optname, (void *)buf, buflen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1823 if (res < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1824 return s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1825 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1826 return Py_None; |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1827 } |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1828 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1829 PyDoc_STRVAR(setsockopt_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1830 "setsockopt(level, option, value)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1831 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1832 Set a socket option. See the Unix manual for level and option.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1833 The value argument can either be an integer or a string."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1834 |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1835 |
|
1039
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1836 /* s.getsockopt() method. |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1837 With two arguments, retrieves an integer option. |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1838 With a third integer argument, retrieves a string buffer of that size; |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
1839 use optional built-in module 'struct' to decode the string. */ |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1840 |
| 1970 | 1841 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1842 sock_getsockopt(PySocketSockObject *s, PyObject *args) |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1843 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1844 int level; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1845 int optname; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1846 int res; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1847 PyObject *buf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1848 socklen_t buflen = 0; |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1849 |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
1850 #ifdef __BEOS__ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1851 /* We have incomplete socket support. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1852 PyErr_SetString(socket_error, "getsockopt not supported"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1853 return NULL; |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
1854 #else |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
1855 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1856 if (!PyArg_ParseTuple(args, "ii|i:getsockopt", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1857 &level, &optname, &buflen)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1858 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1859 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1860 if (buflen == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1861 int flag = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1862 socklen_t flagsize = sizeof flag; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1863 res = getsockopt(s->sock_fd, level, optname, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1864 (void *)&flag, &flagsize); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1865 if (res < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1866 return s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1867 return PyInt_FromLong(flag); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1868 } |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25994
diff
changeset
|
1869 #ifdef __VMS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1870 /* socklen_t is unsigned so no negative test is needed, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1871 test buflen == 0 is previously done */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1872 if (buflen > 1024) { |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25994
diff
changeset
|
1873 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1874 if (buflen <= 0 || buflen > 1024) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1875 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1876 PyErr_SetString(socket_error, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1877 "getsockopt buflen out of range"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1878 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1879 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1880 buf = PyString_FromStringAndSize((char *)NULL, buflen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1881 if (buf == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1882 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1883 res = getsockopt(s->sock_fd, level, optname, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1884 (void *)PyString_AS_STRING(buf), &buflen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1885 if (res < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1886 Py_DECREF(buf); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1887 return s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1888 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1889 _PyString_Resize(&buf, buflen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1890 return buf; |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
1891 #endif /* __BEOS__ */ |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1892 } |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1893 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1894 PyDoc_STRVAR(getsockopt_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1895 "getsockopt(level, option[, buffersize]) -> value\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1896 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1897 Get a socket option. See the Unix manual for level and option.\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1898 If a nonzero buffersize argument is given, the return value is a\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1899 string of that length; otherwise it is an integer."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1900 |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1901 |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
1902 /* s.bind(sockaddr) method */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1903 |
| 1970 | 1904 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1905 sock_bind(PySocketSockObject *s, PyObject *addro) |
| 294 | 1906 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1907 sock_addr_t addrbuf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1908 int addrlen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1909 int res; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1910 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1911 if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf), &addrlen)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1912 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1913 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1914 res = bind(s->sock_fd, SAS2SA(&addrbuf), addrlen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1915 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1916 if (res < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1917 return s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1918 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1919 return Py_None; |
| 294 | 1920 } |
| 1921 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1922 PyDoc_STRVAR(bind_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1923 "bind(address)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1924 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1925 Bind the socket to a local address. For IP sockets, the address is a\n\ |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1926 pair (host, port); the host must refer to the local host. For raw packet\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1927 sockets the address is a tuple (ifname, proto [,pkttype [,hatype]])"); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1928 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1929 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1930 /* s.close() method. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1931 Set the file descriptor to -1 so operations tried subsequently |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1932 will surely fail. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1933 |
| 1970 | 1934 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1935 sock_close(PySocketSockObject *s) |
| 294 | 1936 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1937 SOCKET_T fd; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1938 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1939 if ((fd = s->sock_fd) != -1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1940 s->sock_fd = -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1941 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1942 (void) SOCKETCLOSE(fd); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1943 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1944 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1945 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1946 return Py_None; |
| 294 | 1947 } |
| 1948 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1949 PyDoc_STRVAR(close_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1950 "close()\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1951 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1952 Close the socket. It cannot be used after this call."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1953 |
|
23818
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1954 static int |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1955 internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1956 int *timeoutp) |
|
23818
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1957 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1958 int res, timeout; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1959 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1960 timeout = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1961 res = connect(s->sock_fd, addr, addrlen); |
|
23818
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1962 |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1963 #ifdef MS_WINDOWS |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1964 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1965 if (s->sock_timeout > 0.0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1966 if (res < 0 && WSAGetLastError() == WSAEWOULDBLOCK && |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1967 IS_SELECTABLE(s)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1968 /* This is a mess. Best solution: trust select */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1969 fd_set fds; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1970 fd_set fds_exc; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1971 struct timeval tv; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1972 tv.tv_sec = (int)s->sock_timeout; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1973 tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1974 FD_ZERO(&fds); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1975 FD_SET(s->sock_fd, &fds); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1976 FD_ZERO(&fds_exc); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1977 FD_SET(s->sock_fd, &fds_exc); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1978 res = select(s->sock_fd+1, NULL, &fds, &fds_exc, &tv); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1979 if (res == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1980 res = WSAEWOULDBLOCK; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1981 timeout = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1982 } else if (res > 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1983 if (FD_ISSET(s->sock_fd, &fds)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1984 /* The socket is in the writeable set - this |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1985 means connected */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1986 res = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1987 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1988 /* As per MS docs, we need to call getsockopt() |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1989 to get the underlying error */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1990 int res_size = sizeof res; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1991 /* It must be in the exception set */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1992 assert(FD_ISSET(s->sock_fd, &fds_exc)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1993 if (0 == getsockopt(s->sock_fd, SOL_SOCKET, SO_ERROR, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1994 (char *)&res, &res_size)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1995 /* getsockopt also clears WSAGetLastError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1996 so reset it back. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1997 WSASetLastError(res); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1998 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
1999 res = WSAGetLastError(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2000 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2001 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2002 /* else if (res < 0) an error occurred */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2003 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2004 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2005 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2006 if (res < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2007 res = WSAGetLastError(); |
|
23818
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
2008 |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
2009 #else |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
2010 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2011 if (s->sock_timeout > 0.0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2012 if (res < 0 && errno == EINPROGRESS && IS_SELECTABLE(s)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2013 timeout = internal_select(s, 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2014 if (timeout == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2015 /* Bug #1019808: in case of an EINPROGRESS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2016 use getsockopt(SO_ERROR) to get the real |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2017 error. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2018 socklen_t res_size = sizeof res; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2019 (void)getsockopt(s->sock_fd, SOL_SOCKET, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2020 SO_ERROR, &res, &res_size); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2021 if (res == EISCONN) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2022 res = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2023 errno = res; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2024 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2025 else if (timeout == -1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2026 res = errno; /* had error */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2027 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2028 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2029 res = EWOULDBLOCK; /* timed out */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2030 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2031 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2032 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2033 if (res < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2034 res = errno; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2035 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2036 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2037 *timeoutp = timeout; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2038 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2039 return res; |
|
23818
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
2040 } |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2041 |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
2042 /* s.connect(sockaddr) method */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2043 |
| 1970 | 2044 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2045 sock_connect(PySocketSockObject *s, PyObject *addro) |
| 294 | 2046 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2047 sock_addr_t addrbuf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2048 int addrlen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2049 int res; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2050 int timeout; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2051 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2052 if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf), &addrlen)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2053 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2054 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2055 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2056 res = internal_connect(s, SAS2SA(&addrbuf), addrlen, &timeout); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2057 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2058 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2059 if (timeout == 1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2060 PyErr_SetString(socket_timeout, "timed out"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2061 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2062 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2063 if (res != 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2064 return s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2065 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2066 return Py_None; |
| 294 | 2067 } |
| 2068 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2069 PyDoc_STRVAR(connect_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2070 "connect(address)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2071 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2072 Connect the socket to a remote address. For IP sockets, the address\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2073 is a pair (host, port)."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2074 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2075 |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
2076 /* s.connect_ex(sockaddr) method */ |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
2077 |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
2078 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2079 sock_connect_ex(PySocketSockObject *s, PyObject *addro) |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
2080 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2081 sock_addr_t addrbuf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2082 int addrlen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2083 int res; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2084 int timeout; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2085 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2086 if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf), &addrlen)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2087 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2088 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2089 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2090 res = internal_connect(s, SAS2SA(&addrbuf), addrlen, &timeout); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2091 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2092 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2093 /* Signals are not errors (though they may raise exceptions). Adapted |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2094 from PyErr_SetFromErrnoWithFilenameObject(). */ |
|
39354
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
39251
diff
changeset
|
2095 #ifdef EINTR |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2096 if (res == EINTR && PyErr_CheckSignals()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2097 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2098 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2099 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2100 return PyInt_FromLong((long) res); |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
2101 } |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
2102 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2103 PyDoc_STRVAR(connect_ex_doc, |
|
24676
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
2104 "connect_ex(address) -> errno\n\ |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2105 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2106 This is like connect(address), but returns an error code (the errno value)\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2107 instead of raising an exception when an error occurs."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2108 |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
2109 |
|
902
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
900
diff
changeset
|
2110 /* s.fileno() method */ |
|
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
900
diff
changeset
|
2111 |
| 1970 | 2112 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2113 sock_fileno(PySocketSockObject *s) |
|
902
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
900
diff
changeset
|
2114 { |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
2115 #if SIZEOF_SOCKET_T <= SIZEOF_LONG |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2116 return PyInt_FromLong((long) s->sock_fd); |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
2117 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2118 return PyLong_FromLongLong((PY_LONG_LONG)s->sock_fd); |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
2119 #endif |
|
902
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
900
diff
changeset
|
2120 } |
|
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
900
diff
changeset
|
2121 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2122 PyDoc_STRVAR(fileno_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2123 "fileno() -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2124 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2125 Return the integer file descriptor of the socket."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2126 |
|
902
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
900
diff
changeset
|
2127 |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2128 #ifndef NO_DUP |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2129 /* s.dup() method */ |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2130 |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2131 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2132 sock_dup(PySocketSockObject *s) |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2133 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2134 SOCKET_T newfd; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2135 PyObject *sock; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2136 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2137 newfd = dup(s->sock_fd); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2138 if (newfd < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2139 return s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2140 sock = (PyObject *) new_sockobject(newfd, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2141 s->sock_family, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2142 s->sock_type, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2143 s->sock_proto); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2144 if (sock == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2145 SOCKETCLOSE(newfd); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2146 return sock; |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2147 } |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2148 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2149 PyDoc_STRVAR(dup_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2150 "dup() -> socket object\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2151 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2152 Return a new socket object connected to the same system resource."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2153 |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2154 #endif |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2155 |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2156 |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2157 /* s.getsockname() method */ |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2158 |
| 1970 | 2159 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2160 sock_getsockname(PySocketSockObject *s) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2161 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2162 sock_addr_t addrbuf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2163 int res; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2164 socklen_t addrlen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2165 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2166 if (!getsockaddrlen(s, &addrlen)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2167 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2168 memset(&addrbuf, 0, addrlen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2169 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2170 res = getsockname(s->sock_fd, SAS2SA(&addrbuf), &addrlen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2171 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2172 if (res < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2173 return s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2174 return makesockaddr(s->sock_fd, SAS2SA(&addrbuf), addrlen, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2175 s->sock_proto); |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2176 } |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2177 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2178 PyDoc_STRVAR(getsockname_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2179 "getsockname() -> address info\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2180 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2181 Return the address of the local endpoint. For IP sockets, the address\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2182 info is a pair (hostaddr, port)."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2183 |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2184 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2185 #ifdef HAVE_GETPEERNAME /* Cray APP doesn't have this :-( */ |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2186 /* s.getpeername() method */ |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2187 |
| 1970 | 2188 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2189 sock_getpeername(PySocketSockObject *s) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2190 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2191 sock_addr_t addrbuf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2192 int res; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2193 socklen_t addrlen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2194 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2195 if (!getsockaddrlen(s, &addrlen)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2196 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2197 memset(&addrbuf, 0, addrlen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2198 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2199 res = getpeername(s->sock_fd, SAS2SA(&addrbuf), &addrlen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2200 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2201 if (res < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2202 return s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2203 return makesockaddr(s->sock_fd, SAS2SA(&addrbuf), addrlen, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2204 s->sock_proto); |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2205 } |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2206 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2207 PyDoc_STRVAR(getpeername_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2208 "getpeername() -> address info\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2209 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2210 Return the address of the remote endpoint. For IP sockets, the address\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2211 info is a pair (hostaddr, port)."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2212 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
2213 #endif /* HAVE_GETPEERNAME */ |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2214 |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2215 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2216 /* s.listen(n) method */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2217 |
| 1970 | 2218 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2219 sock_listen(PySocketSockObject *s, PyObject *arg) |
| 294 | 2220 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2221 int backlog; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2222 int res; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2223 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2224 backlog = PyInt_AsLong(arg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2225 if (backlog == -1 && PyErr_Occurred()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2226 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2227 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2228 if (backlog < 1) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2229 backlog = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2230 res = listen(s->sock_fd, backlog); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2231 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2232 if (res < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2233 return s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2234 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2235 return Py_None; |
| 294 | 2236 } |
| 2237 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2238 PyDoc_STRVAR(listen_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2239 "listen(backlog)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2240 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2241 Enable a server to accept connections. The backlog argument must be at\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2242 least 1; it specifies the number of unaccepted connection that the system\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2243 will allow before refusing new connections."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2244 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2245 |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
2246 #ifndef NO_DUP |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2247 /* s.makefile(mode) method. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2248 Create a new open file object referring to a dupped version of |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2249 the socket's file descriptor. (The dup() call is necessary so |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2250 that the open file and socket objects may be closed independent |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2251 of each other.) |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2252 The mode argument specifies 'r' or 'w' passed to fdopen(). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2253 |
| 1970 | 2254 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2255 sock_makefile(PySocketSockObject *s, PyObject *args) |
| 294 | 2256 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2257 extern int fclose(FILE *); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2258 char *mode = "r"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2259 int bufsize = -1; |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
2260 #ifdef MS_WIN32 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2261 Py_intptr_t fd; |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
2262 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2263 int fd; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2264 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2265 FILE *fp; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2266 PyObject *f; |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25994
diff
changeset
|
2267 #ifdef __VMS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2268 char *mode_r = "r"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2269 char *mode_w = "w"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2270 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2271 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2272 if (!PyArg_ParseTuple(args, "|si:makefile", &mode, &bufsize)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2273 return NULL; |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25994
diff
changeset
|
2274 #ifdef __VMS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2275 if (strcmp(mode,"rb") == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2276 mode = mode_r; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2277 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2278 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2279 if (strcmp(mode,"wb") == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2280 mode = mode_w; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2281 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2282 } |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25994
diff
changeset
|
2283 #endif |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
2284 #ifdef MS_WIN32 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2285 if (((fd = _open_osfhandle(s->sock_fd, _O_BINARY)) < 0) || |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2286 ((fd = dup(fd)) < 0) || ((fp = fdopen(fd, mode)) == NULL)) |
|
2736
37c48fde61b8
add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents:
2565
diff
changeset
|
2287 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2288 if ((fd = dup(s->sock_fd)) < 0 || (fp = fdopen(fd, mode)) == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2289 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2290 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2291 if (fd >= 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2292 SOCKETCLOSE(fd); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2293 return s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2294 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2295 f = PyFile_FromFile(fp, "<socket>", mode, fclose); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2296 if (f != NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2297 PyFile_SetBufSize(f, bufsize); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2298 return f; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2299 } |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2300 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2301 PyDoc_STRVAR(makefile_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2302 "makefile([mode[, buffersize]]) -> file object\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2303 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2304 Return a regular file object corresponding to the socket.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2305 The mode and buffersize arguments are as for the built-in open() function."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2306 |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
2307 #endif /* NO_DUP */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2308 |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2309 /* |
|
38580
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38498
diff
changeset
|
2310 * This is the guts of the recv() and recv_into() methods, which reads into a |
| 40475 | 2311 * char buffer. If you have any inc/dec ref to do to the objects that contain |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2312 * the buffer, do it in the caller. This function returns the number of bytes |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2313 * succesfully read. If there was an error, it returns -1. Note that it is |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2314 * also possible that we return a number of bytes smaller than the request |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2315 * bytes. |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2316 */ |
|
38580
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38498
diff
changeset
|
2317 static ssize_t |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2318 sock_recv_guts(PySocketSockObject *s, char* cbuf, int len, int flags) |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2319 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2320 ssize_t outlen = -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2321 int timeout; |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2322 #ifdef __VMS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2323 int remaining; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2324 char *read_buf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2325 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2326 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2327 if (!IS_SELECTABLE(s)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2328 select_error(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2329 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2330 } |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2331 |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2332 #ifndef __VMS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2333 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2334 timeout = internal_select(s, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2335 if (!timeout) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2336 outlen = recv(s->sock_fd, cbuf, len, flags); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2337 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2338 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2339 if (timeout == 1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2340 PyErr_SetString(socket_timeout, "timed out"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2341 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2342 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2343 if (outlen < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2344 /* Note: the call to errorhandler() ALWAYS indirectly returned |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2345 NULL, so ignore its return value */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2346 s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2347 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2348 } |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2349 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2350 read_buf = cbuf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2351 remaining = len; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2352 while (remaining != 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2353 unsigned int segment; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2354 int nread = -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2355 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2356 segment = remaining /SEGMENT_SIZE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2357 if (segment != 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2358 segment = SEGMENT_SIZE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2359 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2360 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2361 segment = remaining; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2362 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2363 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2364 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2365 timeout = internal_select(s, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2366 if (!timeout) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2367 nread = recv(s->sock_fd, read_buf, segment, flags); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2368 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2369 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2370 if (timeout == 1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2371 PyErr_SetString(socket_timeout, "timed out"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2372 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2373 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2374 if (nread < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2375 s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2376 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2377 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2378 if (nread != remaining) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2379 read_buf += nread; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2380 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2381 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2382 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2383 remaining -= segment; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2384 read_buf += segment; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2385 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2386 outlen = read_buf - cbuf; |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2387 #endif /* !__VMS */ |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2388 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2389 return outlen; |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2390 } |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2391 |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2392 |
|
1293
ac3c80abbf43
* classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
2393 /* s.recv(nbytes [,flags]) method */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2394 |
| 1970 | 2395 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2396 sock_recv(PySocketSockObject *s, PyObject *args) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2397 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2398 int recvlen, flags = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2399 ssize_t outlen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2400 PyObject *buf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2401 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2402 if (!PyArg_ParseTuple(args, "i|i:recv", &recvlen, &flags)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2403 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2404 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2405 if (recvlen < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2406 PyErr_SetString(PyExc_ValueError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2407 "negative buffersize in recv"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2408 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2409 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2410 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2411 /* Allocate a new string. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2412 buf = PyString_FromStringAndSize((char *) 0, recvlen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2413 if (buf == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2414 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2415 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2416 /* Call the guts */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2417 outlen = sock_recv_guts(s, PyString_AS_STRING(buf), recvlen, flags); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2418 if (outlen < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2419 /* An error occurred, release the string and return an |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2420 error. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2421 Py_DECREF(buf); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2422 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2423 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2424 if (outlen != recvlen) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2425 /* We did not read as many bytes as we anticipated, resize the |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2426 string if possible and be succesful. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2427 if (_PyString_Resize(&buf, outlen) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2428 /* Oopsy, not so succesful after all. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2429 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2430 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2431 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2432 return buf; |
| 294 | 2433 } |
| 2434 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2435 PyDoc_STRVAR(recv_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2436 "recv(buffersize[, flags]) -> data\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2437 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2438 Receive up to buffersize bytes from the socket. For the optional flags\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2439 argument, see the Unix manual. When no data is available, block until\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2440 at least one byte is available or until the remote end is closed. When\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2441 the remote end is closed and all data is read, return the empty string."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2442 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2443 |
|
38580
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38498
diff
changeset
|
2444 /* s.recv_into(buffer, [nbytes [,flags]]) method */ |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2445 |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2446 static PyObject* |
|
38580
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38498
diff
changeset
|
2447 sock_recv_into(PySocketSockObject *s, PyObject *args, PyObject *kwds) |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2448 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2449 static char *kwlist[] = {"buffer", "nbytes", "flags", 0}; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2450 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2451 int recvlen = 0, flags = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2452 ssize_t readlen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2453 Py_buffer buf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2454 Py_ssize_t buflen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2455 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2456 /* Get the buffer's memory */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2457 if (!PyArg_ParseTupleAndKeywords(args, kwds, "w*|ii:recv_into", kwlist, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2458 &buf, &recvlen, &flags)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2459 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2460 buflen = buf.len; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2461 assert(buf.buf != 0 && buflen > 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2462 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2463 if (recvlen < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2464 PyErr_SetString(PyExc_ValueError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2465 "negative buffersize in recv_into"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2466 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2467 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2468 if (recvlen == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2469 /* If nbytes was not specified, use the buffer's length */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2470 recvlen = buflen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2471 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2472 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2473 /* Check if the buffer is large enough */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2474 if (buflen < recvlen) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2475 PyErr_SetString(PyExc_ValueError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2476 "buffer too small for requested bytes"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2477 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2478 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2479 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2480 /* Call the guts */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2481 readlen = sock_recv_guts(s, buf.buf, recvlen, flags); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2482 if (readlen < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2483 /* Return an error. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2484 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2485 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2486 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2487 PyBuffer_Release(&buf); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2488 /* Return the number of bytes read. Note that we do not do anything |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2489 special here in the case that readlen < recvlen. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2490 return PyInt_FromSsize_t(readlen); |
|
59676
435fa215d33f
Issue #8104: socket.recv_into() and socket.recvfrom_into() now support
Antoine Pitrou <solipsis@pitrou.net>
parents:
58695
diff
changeset
|
2491 |
|
435fa215d33f
Issue #8104: socket.recv_into() and socket.recvfrom_into() now support
Antoine Pitrou <solipsis@pitrou.net>
parents:
58695
diff
changeset
|
2492 error: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2493 PyBuffer_Release(&buf); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2494 return NULL; |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2495 } |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2496 |
|
38580
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38498
diff
changeset
|
2497 PyDoc_STRVAR(recv_into_doc, |
|
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38498
diff
changeset
|
2498 "recv_into(buffer, [nbytes[, flags]]) -> nbytes_read\n\ |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2499 \n\ |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2500 A version of recv() that stores its data into a buffer rather than creating \n\ |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2501 a new string. Receive up to buffersize bytes from the socket. If buffersize \n\ |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2502 is not specified (or 0), receive up to the size available in the given buffer.\n\ |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2503 \n\ |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2504 See recv() for documentation about the flags."); |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2505 |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2506 |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2507 /* |
|
44337
b59c328bfa62
Issue #1645 by Alberto Bertogli. Fix a comment.
Guido van Rossum <guido@python.org>
parents:
43972
diff
changeset
|
2508 * This is the guts of the recvfrom() and recvfrom_into() methods, which reads |
|
b59c328bfa62
Issue #1645 by Alberto Bertogli. Fix a comment.
Guido van Rossum <guido@python.org>
parents:
43972
diff
changeset
|
2509 * into a char buffer. If you have any inc/def ref to do to the objects that |
|
b59c328bfa62
Issue #1645 by Alberto Bertogli. Fix a comment.
Guido van Rossum <guido@python.org>
parents:
43972
diff
changeset
|
2510 * contain the buffer, do it in the caller. This function returns the number |
|
b59c328bfa62
Issue #1645 by Alberto Bertogli. Fix a comment.
Guido van Rossum <guido@python.org>
parents:
43972
diff
changeset
|
2511 * of bytes succesfully read. If there was an error, it returns -1. Note |
|
b59c328bfa62
Issue #1645 by Alberto Bertogli. Fix a comment.
Guido van Rossum <guido@python.org>
parents:
43972
diff
changeset
|
2512 * that it is also possible that we return a number of bytes smaller than the |
|
b59c328bfa62
Issue #1645 by Alberto Bertogli. Fix a comment.
Guido van Rossum <guido@python.org>
parents:
43972
diff
changeset
|
2513 * request bytes. |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2514 * |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2515 * 'addr' is a return value for the address object. Note that you must decref |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2516 * it yourself. |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2517 */ |
|
38580
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38498
diff
changeset
|
2518 static ssize_t |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2519 sock_recvfrom_guts(PySocketSockObject *s, char* cbuf, int len, int flags, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2520 PyObject** addr) |
| 294 | 2521 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2522 sock_addr_t addrbuf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2523 int timeout; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2524 ssize_t n = -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2525 socklen_t addrlen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2526 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2527 *addr = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2528 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2529 if (!getsockaddrlen(s, &addrlen)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2530 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2531 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2532 if (!IS_SELECTABLE(s)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2533 select_error(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2534 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2535 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2536 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2537 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2538 memset(&addrbuf, 0, addrlen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2539 timeout = internal_select(s, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2540 if (!timeout) { |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
2541 #ifndef MS_WINDOWS |
|
22115
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
2542 #if defined(PYOS_OS2) && !defined(PYCC_GCC) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2543 n = recvfrom(s->sock_fd, cbuf, len, flags, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2544 SAS2SA(&addrbuf), &addrlen); |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
2545 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2546 n = recvfrom(s->sock_fd, cbuf, len, flags, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2547 (void *) &addrbuf, &addrlen); |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
2548 #endif |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
2549 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2550 n = recvfrom(s->sock_fd, cbuf, len, flags, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2551 SAS2SA(&addrbuf), &addrlen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2552 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2553 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2554 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2555 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2556 if (timeout == 1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2557 PyErr_SetString(socket_timeout, "timed out"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2558 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2559 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2560 if (n < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2561 s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2562 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2563 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2564 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2565 if (!(*addr = makesockaddr(s->sock_fd, SAS2SA(&addrbuf), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2566 addrlen, s->sock_proto))) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2567 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2568 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2569 return n; |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2570 } |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2571 |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2572 /* s.recvfrom(nbytes [,flags]) method */ |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2573 |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2574 static PyObject * |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2575 sock_recvfrom(PySocketSockObject *s, PyObject *args) |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2576 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2577 PyObject *buf = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2578 PyObject *addr = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2579 PyObject *ret = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2580 int recvlen, flags = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2581 ssize_t outlen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2582 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2583 if (!PyArg_ParseTuple(args, "i|i:recvfrom", &recvlen, &flags)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2584 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2585 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2586 if (recvlen < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2587 PyErr_SetString(PyExc_ValueError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2588 "negative buffersize in recvfrom"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2589 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2590 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2591 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2592 buf = PyString_FromStringAndSize((char *) 0, recvlen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2593 if (buf == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2594 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2595 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2596 outlen = sock_recvfrom_guts(s, PyString_AS_STRING(buf), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2597 recvlen, flags, &addr); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2598 if (outlen < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2599 goto finally; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2600 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2601 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2602 if (outlen != recvlen) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2603 /* We did not read as many bytes as we anticipated, resize the |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2604 string if possible and be succesful. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2605 if (_PyString_Resize(&buf, outlen) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2606 /* Oopsy, not so succesful after all. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2607 goto finally; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2608 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2609 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2610 ret = PyTuple_Pack(2, buf, addr); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2611 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2612 finally: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2613 Py_XDECREF(buf); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2614 Py_XDECREF(addr); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2615 return ret; |
| 294 | 2616 } |
| 2617 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2618 PyDoc_STRVAR(recvfrom_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2619 "recvfrom(buffersize[, flags]) -> (data, address info)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2620 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2621 Like recv(buffersize, flags) but also return the sender's address info."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2622 |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2623 |
|
38580
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38498
diff
changeset
|
2624 /* s.recvfrom_into(buffer[, nbytes [,flags]]) method */ |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2625 |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2626 static PyObject * |
|
38580
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38498
diff
changeset
|
2627 sock_recvfrom_into(PySocketSockObject *s, PyObject *args, PyObject* kwds) |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2628 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2629 static char *kwlist[] = {"buffer", "nbytes", "flags", 0}; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2630 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2631 int recvlen = 0, flags = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2632 ssize_t readlen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2633 Py_buffer buf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2634 int buflen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2635 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2636 PyObject *addr = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2637 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2638 if (!PyArg_ParseTupleAndKeywords(args, kwds, "w*|ii:recvfrom_into", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2639 kwlist, &buf, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2640 &recvlen, &flags)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2641 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2642 buflen = buf.len; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2643 assert(buf.buf != 0 && buflen > 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2644 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2645 if (recvlen < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2646 PyErr_SetString(PyExc_ValueError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2647 "negative buffersize in recvfrom_into"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2648 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2649 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2650 if (recvlen == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2651 /* If nbytes was not specified, use the buffer's length */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2652 recvlen = buflen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2653 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2654 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2655 readlen = sock_recvfrom_guts(s, buf.buf, recvlen, flags, &addr); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2656 if (readlen < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2657 /* Return an error */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2658 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2659 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2660 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2661 PyBuffer_Release(&buf); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2662 /* Return the number of bytes read and the address. Note that we do |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2663 not do anything special here in the case that readlen < recvlen. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2664 return Py_BuildValue("lN", readlen, addr); |
|
59676
435fa215d33f
Issue #8104: socket.recv_into() and socket.recvfrom_into() now support
Antoine Pitrou <solipsis@pitrou.net>
parents:
58695
diff
changeset
|
2665 |
|
435fa215d33f
Issue #8104: socket.recv_into() and socket.recvfrom_into() now support
Antoine Pitrou <solipsis@pitrou.net>
parents:
58695
diff
changeset
|
2666 error: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2667 Py_XDECREF(addr); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2668 PyBuffer_Release(&buf); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2669 return NULL; |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2670 } |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2671 |
|
38580
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38498
diff
changeset
|
2672 PyDoc_STRVAR(recvfrom_into_doc, |
|
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38498
diff
changeset
|
2673 "recvfrom_into(buffer[, nbytes[, flags]]) -> (nbytes, address info)\n\ |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2674 \n\ |
|
38580
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38498
diff
changeset
|
2675 Like recv_into(buffer[, nbytes[, flags]]) but also return the sender's address info."); |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2676 |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
2677 |
|
1293
ac3c80abbf43
* classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
2678 /* s.send(data [,flags]) method */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2679 |
| 1970 | 2680 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2681 sock_send(PySocketSockObject *s, PyObject *args) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2682 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2683 char *buf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2684 int len, n = -1, flags = 0, timeout; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2685 Py_buffer pbuf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2686 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2687 if (!PyArg_ParseTuple(args, "s*|i:send", &pbuf, &flags)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2688 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2689 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2690 if (!IS_SELECTABLE(s)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2691 PyBuffer_Release(&pbuf); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2692 return select_error(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2693 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2694 buf = pbuf.buf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2695 len = pbuf.len; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2696 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2697 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2698 timeout = internal_select(s, 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2699 if (!timeout) |
|
39043
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
2700 #ifdef __VMS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2701 n = sendsegmented(s->sock_fd, buf, len, flags); |
|
39043
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
2702 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2703 n = send(s->sock_fd, buf, len, flags); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2704 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2705 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2706 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2707 PyBuffer_Release(&pbuf); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2708 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2709 if (timeout == 1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2710 PyErr_SetString(socket_timeout, "timed out"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2711 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2712 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2713 if (n < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2714 return s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2715 return PyInt_FromLong((long)n); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2716 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2717 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2718 PyDoc_STRVAR(send_doc, |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2719 "send(data[, flags]) -> count\n\ |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2720 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2721 Send a data string to the socket. For the optional flags\n\ |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2722 argument, see the Unix manual. Return the number of bytes\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2723 sent; this may be less than len(data) if the network is busy."); |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2724 |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2725 |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2726 /* s.sendall(data [,flags]) method */ |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2727 |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2728 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2729 sock_sendall(PySocketSockObject *s, PyObject *args) |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2730 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2731 char *buf; |
|
64962
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2732 int len, n = -1, flags = 0, timeout, saved_errno; |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2733 Py_buffer pbuf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2734 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2735 if (!PyArg_ParseTuple(args, "s*|i:sendall", &pbuf, &flags)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2736 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2737 buf = pbuf.buf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2738 len = pbuf.len; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2739 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2740 if (!IS_SELECTABLE(s)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2741 PyBuffer_Release(&pbuf); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2742 return select_error(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2743 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2744 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2745 do { |
|
64962
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2746 Py_BEGIN_ALLOW_THREADS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2747 timeout = internal_select(s, 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2748 n = -1; |
|
64962
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2749 if (!timeout) { |
|
39043
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
2750 #ifdef __VMS |
|
64962
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2751 n = sendsegmented(s->sock_fd, buf, len, flags); |
|
39043
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
2752 #else |
|
64962
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2753 n = send(s->sock_fd, buf, len, flags); |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2754 #endif |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2755 } |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2756 Py_END_ALLOW_THREADS |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2757 if (timeout == 1) { |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2758 PyBuffer_Release(&pbuf); |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2759 PyErr_SetString(socket_timeout, "timed out"); |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2760 return NULL; |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2761 } |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2762 /* PyErr_CheckSignals() might change errno */ |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2763 saved_errno = errno; |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2764 /* We must run our signal handlers before looping again. |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2765 send() can return a successful partial write when it is |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2766 interrupted, so we can't restrict ourselves to EINTR. */ |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2767 if (PyErr_CheckSignals()) { |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2768 PyBuffer_Release(&pbuf); |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2769 return NULL; |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2770 } |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2771 if (n < 0) { |
|
64962
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2772 /* If interrupted, try again */ |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2773 if (saved_errno == EINTR) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2774 continue; |
|
64962
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2775 else |
|
1dc2b50d344f
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
2776 break; |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2777 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2778 buf += n; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2779 len -= n; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2780 } while (len > 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2781 PyBuffer_Release(&pbuf); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2782 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2783 if (n < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2784 return s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2785 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2786 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2787 return Py_None; |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2788 } |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2789 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2790 PyDoc_STRVAR(sendall_doc, |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2791 "sendall(data[, flags])\n\ |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2792 \n\ |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2793 Send a data string to the socket. For the optional flags\n\ |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2794 argument, see the Unix manual. This calls send() repeatedly\n\ |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2795 until all data is sent. If an error occurs, it's impossible\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2796 to tell how much data has been sent."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2797 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2798 |
|
1293
ac3c80abbf43
* classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
2799 /* s.sendto(data, [flags,] sockaddr) method */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2800 |
| 1970 | 2801 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2802 sock_sendto(PySocketSockObject *s, PyObject *args) |
| 294 | 2803 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2804 Py_buffer pbuf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2805 PyObject *addro; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2806 char *buf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2807 Py_ssize_t len; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2808 sock_addr_t addrbuf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2809 int addrlen, n = -1, flags, timeout; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2810 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2811 flags = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2812 if (!PyArg_ParseTuple(args, "s*O:sendto", &pbuf, &addro)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2813 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2814 if (!PyArg_ParseTuple(args, "s*iO:sendto", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2815 &pbuf, &flags, &addro)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2816 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2817 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2818 buf = pbuf.buf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2819 len = pbuf.len; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2820 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2821 if (!IS_SELECTABLE(s)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2822 PyBuffer_Release(&pbuf); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2823 return select_error(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2824 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2825 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2826 if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf), &addrlen)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2827 PyBuffer_Release(&pbuf); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2828 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2829 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2830 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2831 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2832 timeout = internal_select(s, 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2833 if (!timeout) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2834 n = sendto(s->sock_fd, buf, len, flags, SAS2SA(&addrbuf), addrlen); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2835 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2836 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2837 PyBuffer_Release(&pbuf); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2838 if (timeout == 1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2839 PyErr_SetString(socket_timeout, "timed out"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2840 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2841 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2842 if (n < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2843 return s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2844 return PyInt_FromLong((long)n); |
| 294 | 2845 } |
| 2846 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2847 PyDoc_STRVAR(sendto_doc, |
|
24676
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
2848 "sendto(data[, flags], address) -> count\n\ |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2849 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2850 Like send(data, flags) but allows specifying the destination address.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2851 For IP sockets, the address is a pair (hostaddr, port)."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2852 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2853 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2854 /* s.shutdown(how) method */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2855 |
| 1970 | 2856 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2857 sock_shutdown(PySocketSockObject *s, PyObject *arg) |
| 294 | 2858 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2859 int how; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2860 int res; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2861 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2862 how = PyInt_AsLong(arg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2863 if (how == -1 && PyErr_Occurred()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2864 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2865 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2866 res = shutdown(s->sock_fd, how); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2867 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2868 if (res < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2869 return s->errorhandler(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2870 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2871 return Py_None; |
| 294 | 2872 } |
| 2873 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2874 PyDoc_STRVAR(shutdown_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2875 "shutdown(flag)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2876 \n\ |
|
31027
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
2877 Shut down the reading side of the socket (flag == SHUT_RD), the writing side\n\ |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
2878 of the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR)."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2879 |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
2880 #if defined(MS_WINDOWS) && defined(SIO_RCVALL) |
|
44474
bfed70277ab3
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
2881 static PyObject* |
|
bfed70277ab3
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
2882 sock_ioctl(PySocketSockObject *s, PyObject *arg) |
|
bfed70277ab3
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
2883 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2884 unsigned long cmd = SIO_RCVALL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2885 PyObject *argO; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2886 DWORD recv; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2887 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2888 if (!PyArg_ParseTuple(arg, "kO:ioctl", &cmd, &argO)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2889 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2890 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2891 switch (cmd) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2892 case SIO_RCVALL: { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2893 unsigned int option = RCVALL_ON; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2894 if (!PyArg_ParseTuple(arg, "kI:ioctl", &cmd, &option)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2895 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2896 if (WSAIoctl(s->sock_fd, cmd, &option, sizeof(option), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2897 NULL, 0, &recv, NULL, NULL) == SOCKET_ERROR) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2898 return set_error(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2899 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2900 return PyLong_FromUnsignedLong(recv); } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2901 case SIO_KEEPALIVE_VALS: { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2902 struct tcp_keepalive ka; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2903 if (!PyArg_ParseTuple(arg, "k(kkk):ioctl", &cmd, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2904 &ka.onoff, &ka.keepalivetime, &ka.keepaliveinterval)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2905 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2906 if (WSAIoctl(s->sock_fd, cmd, &ka, sizeof(ka), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2907 NULL, 0, &recv, NULL, NULL) == SOCKET_ERROR) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2908 return set_error(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2909 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2910 return PyLong_FromUnsignedLong(recv); } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2911 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2912 PyErr_Format(PyExc_ValueError, "invalid ioctl command %d", cmd); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2913 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2914 } |
|
44474
bfed70277ab3
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
2915 } |
|
bfed70277ab3
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
2916 PyDoc_STRVAR(sock_ioctl_doc, |
|
bfed70277ab3
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
2917 "ioctl(cmd, option) -> long\n\ |
|
bfed70277ab3
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
2918 \n\ |
|
56212
3def952b515c
http://bugs.python.org/issue6971
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
56107
diff
changeset
|
2919 Control the socket with WSAIoctl syscall. Currently supported 'cmd' values are\n\ |
|
3def952b515c
http://bugs.python.org/issue6971
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
56107
diff
changeset
|
2920 SIO_RCVALL: 'option' must be one of the socket.RCVALL_* constants.\n\ |
|
3def952b515c
http://bugs.python.org/issue6971
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
56107
diff
changeset
|
2921 SIO_KEEPALIVE_VALS: 'option' is a tuple of (onoff, timeout, interval)."); |
|
44474
bfed70277ab3
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
2922 |
|
bfed70277ab3
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
2923 #endif |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2924 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2925 /* List of methods for socket objects */ |
| 294 | 2926 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2927 static PyMethodDef sock_methods[] = { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2928 {"accept", (PyCFunction)sock_accept, METH_NOARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2929 accept_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2930 {"bind", (PyCFunction)sock_bind, METH_O, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2931 bind_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2932 {"close", (PyCFunction)sock_close, METH_NOARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2933 close_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2934 {"connect", (PyCFunction)sock_connect, METH_O, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2935 connect_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2936 {"connect_ex", (PyCFunction)sock_connect_ex, METH_O, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2937 connect_ex_doc}, |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2938 #ifndef NO_DUP |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2939 {"dup", (PyCFunction)sock_dup, METH_NOARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2940 dup_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2941 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2942 {"fileno", (PyCFunction)sock_fileno, METH_NOARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2943 fileno_doc}, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2944 #ifdef HAVE_GETPEERNAME |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2945 {"getpeername", (PyCFunction)sock_getpeername, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2946 METH_NOARGS, getpeername_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2947 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2948 {"getsockname", (PyCFunction)sock_getsockname, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2949 METH_NOARGS, getsockname_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2950 {"getsockopt", (PyCFunction)sock_getsockopt, METH_VARARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2951 getsockopt_doc}, |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
2952 #if defined(MS_WINDOWS) && defined(SIO_RCVALL) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2953 {"ioctl", (PyCFunction)sock_ioctl, METH_VARARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2954 sock_ioctl_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2955 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2956 {"listen", (PyCFunction)sock_listen, METH_O, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2957 listen_doc}, |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
2958 #ifndef NO_DUP |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2959 {"makefile", (PyCFunction)sock_makefile, METH_VARARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2960 makefile_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2961 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2962 {"recv", (PyCFunction)sock_recv, METH_VARARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2963 recv_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2964 {"recv_into", (PyCFunction)sock_recv_into, METH_VARARGS | METH_KEYWORDS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2965 recv_into_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2966 {"recvfrom", (PyCFunction)sock_recvfrom, METH_VARARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2967 recvfrom_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2968 {"recvfrom_into", (PyCFunction)sock_recvfrom_into, METH_VARARGS | METH_KEYWORDS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2969 recvfrom_into_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2970 {"send", (PyCFunction)sock_send, METH_VARARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2971 send_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2972 {"sendall", (PyCFunction)sock_sendall, METH_VARARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2973 sendall_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2974 {"sendto", (PyCFunction)sock_sendto, METH_VARARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2975 sendto_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2976 {"setblocking", (PyCFunction)sock_setblocking, METH_O, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2977 setblocking_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2978 {"settimeout", (PyCFunction)sock_settimeout, METH_O, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2979 settimeout_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2980 {"gettimeout", (PyCFunction)sock_gettimeout, METH_NOARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2981 gettimeout_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2982 {"setsockopt", (PyCFunction)sock_setsockopt, METH_VARARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2983 setsockopt_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2984 {"shutdown", (PyCFunction)sock_shutdown, METH_O, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2985 shutdown_doc}, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2986 #ifdef RISCOS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2987 {"sleeptaskw", (PyCFunction)sock_sleeptaskw, METH_O, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2988 sleeptaskw_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2989 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
2990 {NULL, NULL} /* sentinel */ |
| 294 | 2991 }; |
| 2992 | |
|
37069
dd49847a60d3
RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents:
36684
diff
changeset
|
2993 /* SockObject members */ |
|
dd49847a60d3
RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents:
36684
diff
changeset
|
2994 static PyMemberDef sock_memberlist[] = { |
|
dd49847a60d3
RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents:
36684
diff
changeset
|
2995 {"family", T_INT, offsetof(PySocketSockObject, sock_family), READONLY, "the socket family"}, |
|
dd49847a60d3
RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents:
36684
diff
changeset
|
2996 {"type", T_INT, offsetof(PySocketSockObject, sock_type), READONLY, "the socket type"}, |
|
dd49847a60d3
RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents:
36684
diff
changeset
|
2997 {"proto", T_INT, offsetof(PySocketSockObject, sock_proto), READONLY, "the socket protocol"}, |
|
dd49847a60d3
RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents:
36684
diff
changeset
|
2998 {"timeout", T_DOUBLE, offsetof(PySocketSockObject, sock_timeout), READONLY, "the socket timeout"}, |
|
dd49847a60d3
RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents:
36684
diff
changeset
|
2999 {0}, |
|
dd49847a60d3
RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents:
36684
diff
changeset
|
3000 }; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3001 |
| 1970 | 3002 /* Deallocate a socket object in response to the last Py_DECREF(). |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3003 First close the file description. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3004 |
| 294 | 3005 static void |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3006 sock_dealloc(PySocketSockObject *s) |
| 294 | 3007 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3008 if (s->sock_fd != -1) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3009 (void) SOCKETCLOSE(s->sock_fd); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3010 Py_TYPE(s)->tp_free((PyObject *)s); |
| 294 | 3011 } |
| 3012 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3013 |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3014 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3015 sock_repr(PySocketSockObject *s) |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3016 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3017 char buf[512]; |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
3018 #if SIZEOF_SOCKET_T > SIZEOF_LONG |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3019 if (s->sock_fd > LONG_MAX) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3020 /* this can occur on Win64, and actually there is a special |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3021 ugly printf formatter for decimal pointer length integer |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3022 printing, only bother if necessary*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3023 PyErr_SetString(PyExc_OverflowError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3024 "no printf formatter to display " |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3025 "the socket descriptor in decimal"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3026 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3027 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3028 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3029 PyOS_snprintf( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3030 buf, sizeof(buf), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3031 "<socket object, fd=%ld, family=%d, type=%d, protocol=%d>", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3032 (long)s->sock_fd, s->sock_family, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3033 s->sock_type, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3034 s->sock_proto); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3035 return PyString_FromString(buf); |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3036 } |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3037 |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3038 |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
3039 /* Create a new, uninitialized socket object. */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
3040 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
3041 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3042 sock_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
3043 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3044 PyObject *new; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3045 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3046 new = type->tp_alloc(type, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3047 if (new != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3048 ((PySocketSockObject *)new)->sock_fd = -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3049 ((PySocketSockObject *)new)->sock_timeout = -1.0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3050 ((PySocketSockObject *)new)->errorhandler = &set_error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3051 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3052 return new; |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
3053 } |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
3054 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
3055 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
3056 /* Initialize a new socket object. */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
3057 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
3058 /*ARGSUSED*/ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
3059 static int |
|
23807
cc65b5bcfc38
work around name clash with OS/2 TCPIP routine sock_init()
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
23736
diff
changeset
|
3060 sock_initobj(PyObject *self, PyObject *args, PyObject *kwds) |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
3061 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3062 PySocketSockObject *s = (PySocketSockObject *)self; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3063 SOCKET_T fd; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3064 int family = AF_INET, type = SOCK_STREAM, proto = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3065 static char *keywords[] = {"family", "type", "proto", 0}; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3066 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3067 if (!PyArg_ParseTupleAndKeywords(args, kwds, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3068 "|iii:socket", keywords, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3069 &family, &type, &proto)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3070 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3071 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3072 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3073 fd = socket(family, type, proto); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3074 Py_END_ALLOW_THREADS |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3075 |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
3076 #ifdef MS_WINDOWS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3077 if (fd == INVALID_SOCKET) |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
3078 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3079 if (fd < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3080 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3081 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3082 set_error(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3083 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3084 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3085 init_sockobject(s, fd, family, type, proto); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3086 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3087 return 0; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3088 |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
3089 } |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
3090 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
3091 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
3092 /* Type object for socket objects. */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3093 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3094 static PyTypeObject sock_type = { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3095 PyVarObject_HEAD_INIT(0, 0) /* Must fill in type value later */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3096 "_socket.socket", /* tp_name */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3097 sizeof(PySocketSockObject), /* tp_basicsize */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3098 0, /* tp_itemsize */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3099 (destructor)sock_dealloc, /* tp_dealloc */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3100 0, /* tp_print */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3101 0, /* tp_getattr */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3102 0, /* tp_setattr */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3103 0, /* tp_compare */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3104 (reprfunc)sock_repr, /* tp_repr */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3105 0, /* tp_as_number */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3106 0, /* tp_as_sequence */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3107 0, /* tp_as_mapping */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3108 0, /* tp_hash */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3109 0, /* tp_call */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3110 0, /* tp_str */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3111 PyObject_GenericGetAttr, /* tp_getattro */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3112 0, /* tp_setattro */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3113 0, /* tp_as_buffer */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3114 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3115 sock_doc, /* tp_doc */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3116 0, /* tp_traverse */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3117 0, /* tp_clear */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3118 0, /* tp_richcompare */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3119 0, /* tp_weaklistoffset */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3120 0, /* tp_iter */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3121 0, /* tp_iternext */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3122 sock_methods, /* tp_methods */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3123 sock_memberlist, /* tp_members */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3124 0, /* tp_getset */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3125 0, /* tp_base */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3126 0, /* tp_dict */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3127 0, /* tp_descr_get */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3128 0, /* tp_descr_set */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3129 0, /* tp_dictoffset */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3130 sock_initobj, /* tp_init */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3131 PyType_GenericAlloc, /* tp_alloc */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3132 sock_new, /* tp_new */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3133 PyObject_Del, /* tp_free */ |
| 294 | 3134 }; |
| 3135 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3136 |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
3137 /* Python interface to gethostname(). */ |
|
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
3138 |
|
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
3139 /*ARGSUSED*/ |
| 1970 | 3140 static PyObject * |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38476
diff
changeset
|
3141 socket_gethostname(PyObject *self, PyObject *unused) |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
3142 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3143 char buf[1024]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3144 int res; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3145 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3146 res = gethostname(buf, (int) sizeof buf - 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3147 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3148 if (res < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3149 return set_error(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3150 buf[sizeof buf - 1] = '\0'; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3151 return PyString_FromString(buf); |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
3152 } |
| 926 | 3153 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3154 PyDoc_STRVAR(gethostname_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3155 "gethostname() -> string\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3156 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3157 Return the current host name."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3158 |
| 926 | 3159 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3160 /* Python interface to gethostbyname(name). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3161 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3162 /*ARGSUSED*/ |
| 1970 | 3163 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3164 socket_gethostbyname(PyObject *self, PyObject *args) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3165 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3166 char *name; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3167 sock_addr_t addrbuf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3168 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3169 if (!PyArg_ParseTuple(args, "s:gethostbyname", &name)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3170 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3171 if (setipaddr(name, SAS2SA(&addrbuf), sizeof(addrbuf), AF_INET) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3172 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3173 return makeipaddr(SAS2SA(&addrbuf), sizeof(struct sockaddr_in)); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3174 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3175 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3176 PyDoc_STRVAR(gethostbyname_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3177 "gethostbyname(host) -> address\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3178 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3179 Return the IP address (a string of the form '255.255.255.255') for a host."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3180 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3181 |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3182 /* Convenience function common to gethostbyname_ex and gethostbyaddr */ |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3183 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3184 static PyObject * |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3185 gethost_common(struct hostent *h, struct sockaddr *addr, int alen, int af) |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3186 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3187 char **pch; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3188 PyObject *rtn_tuple = (PyObject *)NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3189 PyObject *name_list = (PyObject *)NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3190 PyObject *addr_list = (PyObject *)NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3191 PyObject *tmp; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3192 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3193 if (h == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3194 /* Let's get real error message to return */ |
|
20654
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20648
diff
changeset
|
3195 #ifndef RISCOS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3196 set_herror(h_errno); |
|
20654
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20648
diff
changeset
|
3197 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3198 PyErr_SetString(socket_error, "host not found"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3199 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3200 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3201 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3202 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3203 if (h->h_addrtype != af) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3204 /* Let's get real error message to return */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3205 PyErr_SetString(socket_error, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3206 (char *)strerror(EAFNOSUPPORT)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3207 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3208 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3209 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3210 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3211 switch (af) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3212 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3213 case AF_INET: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3214 if (alen < sizeof(struct sockaddr_in)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3215 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3216 break; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3217 |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
3218 #ifdef ENABLE_IPV6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3219 case AF_INET6: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3220 if (alen < sizeof(struct sockaddr_in6)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3221 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3222 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3223 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3224 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3225 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3226 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3227 if ((name_list = PyList_New(0)) == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3228 goto err; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3229 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3230 if ((addr_list = PyList_New(0)) == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3231 goto err; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3232 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3233 /* SF #1511317: h_aliases can be NULL */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3234 if (h->h_aliases) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3235 for (pch = h->h_aliases; *pch != NULL; pch++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3236 int status; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3237 tmp = PyString_FromString(*pch); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3238 if (tmp == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3239 goto err; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3240 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3241 status = PyList_Append(name_list, tmp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3242 Py_DECREF(tmp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3243 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3244 if (status) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3245 goto err; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3246 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3247 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3248 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3249 for (pch = h->h_addr_list; *pch != NULL; pch++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3250 int status; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3251 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3252 switch (af) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3253 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3254 case AF_INET: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3255 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3256 struct sockaddr_in sin; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3257 memset(&sin, 0, sizeof(sin)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3258 sin.sin_family = af; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3259 #ifdef HAVE_SOCKADDR_SA_LEN |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3260 sin.sin_len = sizeof(sin); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3261 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3262 memcpy(&sin.sin_addr, *pch, sizeof(sin.sin_addr)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3263 tmp = makeipaddr((struct sockaddr *)&sin, sizeof(sin)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3264 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3265 if (pch == h->h_addr_list && alen >= sizeof(sin)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3266 memcpy((char *) addr, &sin, sizeof(sin)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3267 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3268 } |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3269 |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
3270 #ifdef ENABLE_IPV6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3271 case AF_INET6: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3272 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3273 struct sockaddr_in6 sin6; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3274 memset(&sin6, 0, sizeof(sin6)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3275 sin6.sin6_family = af; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3276 #ifdef HAVE_SOCKADDR_SA_LEN |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3277 sin6.sin6_len = sizeof(sin6); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3278 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3279 memcpy(&sin6.sin6_addr, *pch, sizeof(sin6.sin6_addr)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3280 tmp = makeipaddr((struct sockaddr *)&sin6, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3281 sizeof(sin6)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3282 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3283 if (pch == h->h_addr_list && alen >= sizeof(sin6)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3284 memcpy((char *) addr, &sin6, sizeof(sin6)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3285 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3286 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3287 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3288 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3289 default: /* can't happen */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3290 PyErr_SetString(socket_error, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3291 "unsupported address family"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3292 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3293 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3294 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3295 if (tmp == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3296 goto err; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3297 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3298 status = PyList_Append(addr_list, tmp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3299 Py_DECREF(tmp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3300 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3301 if (status) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3302 goto err; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3303 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3304 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3305 rtn_tuple = Py_BuildValue("sOO", h->h_name, name_list, addr_list); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3306 |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3307 err: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3308 Py_XDECREF(name_list); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3309 Py_XDECREF(addr_list); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3310 return rtn_tuple; |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3311 } |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3312 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3313 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3314 /* Python interface to gethostbyname_ex(name). */ |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3315 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3316 /*ARGSUSED*/ |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3317 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3318 socket_gethostbyname_ex(PyObject *self, PyObject *args) |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3319 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3320 char *name; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3321 struct hostent *h; |
|
28949
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
28925
diff
changeset
|
3322 #ifdef ENABLE_IPV6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3323 struct sockaddr_storage addr; |
|
28949
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
28925
diff
changeset
|
3324 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3325 struct sockaddr_in addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3326 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3327 struct sockaddr *sa; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3328 PyObject *ret; |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3329 #ifdef HAVE_GETHOSTBYNAME_R |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3330 struct hostent hp_allocated; |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3331 #ifdef HAVE_GETHOSTBYNAME_R_3_ARG |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3332 struct hostent_data data; |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3333 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3334 char buf[16384]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3335 int buf_len = (sizeof buf) - 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3336 int errnop; |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3337 #endif |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3338 #if defined(HAVE_GETHOSTBYNAME_R_3_ARG) || defined(HAVE_GETHOSTBYNAME_R_6_ARG) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3339 int result; |
|
10401
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
3340 #endif |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3341 #endif /* HAVE_GETHOSTBYNAME_R */ |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3342 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3343 if (!PyArg_ParseTuple(args, "s:gethostbyname_ex", &name)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3344 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3345 if (setipaddr(name, (struct sockaddr *)&addr, sizeof(addr), AF_INET) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3346 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3347 Py_BEGIN_ALLOW_THREADS |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3348 #ifdef HAVE_GETHOSTBYNAME_R |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3349 #if defined(HAVE_GETHOSTBYNAME_R_6_ARG) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3350 result = gethostbyname_r(name, &hp_allocated, buf, buf_len, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3351 &h, &errnop); |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3352 #elif defined(HAVE_GETHOSTBYNAME_R_5_ARG) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3353 h = gethostbyname_r(name, &hp_allocated, buf, buf_len, &errnop); |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3354 #else /* HAVE_GETHOSTBYNAME_R_3_ARG */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3355 memset((void *) &data, '\0', sizeof(data)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3356 result = gethostbyname_r(name, &hp_allocated, &data); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3357 h = (result != 0) ? NULL : &hp_allocated; |
|
10401
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
3358 #endif |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3359 #else /* not HAVE_GETHOSTBYNAME_R */ |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
3360 #ifdef USE_GETHOSTBYNAME_LOCK |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3361 PyThread_acquire_lock(netdb_lock, 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3362 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3363 h = gethostbyname(name); |
|
10441
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
3364 #endif /* HAVE_GETHOSTBYNAME_R */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3365 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3366 /* Some C libraries would require addr.__ss_family instead of |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3367 addr.ss_family. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3368 Therefore, we cast the sockaddr_storage into sockaddr to |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3369 access sa_family. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3370 sa = (struct sockaddr*)&addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3371 ret = gethost_common(h, (struct sockaddr *)&addr, sizeof(addr), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3372 sa->sa_family); |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
3373 #ifdef USE_GETHOSTBYNAME_LOCK |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3374 PyThread_release_lock(netdb_lock); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3375 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3376 return ret; |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3377 } |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3378 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3379 PyDoc_STRVAR(ghbn_ex_doc, |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3380 "gethostbyname_ex(host) -> (name, aliaslist, addresslist)\n\ |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3381 \n\ |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3382 Return the true host name, a list of aliases, and a list of IP addresses,\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3383 for a host. The host argument is a string giving a host name or IP number."); |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3384 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3385 |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3386 /* Python interface to gethostbyaddr(IP). */ |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3387 |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3388 /*ARGSUSED*/ |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3389 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3390 socket_gethostbyaddr(PyObject *self, PyObject *args) |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3391 { |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
3392 #ifdef ENABLE_IPV6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3393 struct sockaddr_storage addr; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3394 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3395 struct sockaddr_in addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3396 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3397 struct sockaddr *sa = (struct sockaddr *)&addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3398 char *ip_num; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3399 struct hostent *h; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3400 PyObject *ret; |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
3401 #ifdef HAVE_GETHOSTBYNAME_R |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3402 struct hostent hp_allocated; |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3403 #ifdef HAVE_GETHOSTBYNAME_R_3_ARG |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3404 struct hostent_data data; |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3405 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3406 /* glibcs up to 2.10 assume that the buf argument to |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3407 gethostbyaddr_r is 8-byte aligned, which at least llvm-gcc |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3408 does not ensure. The attribute below instructs the compiler |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3409 to maintain this alignment. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3410 char buf[16384] Py_ALIGNED(8); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3411 int buf_len = (sizeof buf) - 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3412 int errnop; |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3413 #endif |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3414 #if defined(HAVE_GETHOSTBYNAME_R_3_ARG) || defined(HAVE_GETHOSTBYNAME_R_6_ARG) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3415 int result; |
|
10401
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
3416 #endif |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
3417 #endif /* HAVE_GETHOSTBYNAME_R */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3418 char *ap; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3419 int al; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3420 int af; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3421 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3422 if (!PyArg_ParseTuple(args, "s:gethostbyaddr", &ip_num)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3423 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3424 af = AF_UNSPEC; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3425 if (setipaddr(ip_num, sa, sizeof(addr), af) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3426 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3427 af = sa->sa_family; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3428 ap = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3429 switch (af) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3430 case AF_INET: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3431 ap = (char *)&((struct sockaddr_in *)sa)->sin_addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3432 al = sizeof(((struct sockaddr_in *)sa)->sin_addr); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3433 break; |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
3434 #ifdef ENABLE_IPV6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3435 case AF_INET6: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3436 ap = (char *)&((struct sockaddr_in6 *)sa)->sin6_addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3437 al = sizeof(((struct sockaddr_in6 *)sa)->sin6_addr); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3438 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3439 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3440 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3441 PyErr_SetString(socket_error, "unsupported address family"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3442 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3443 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3444 Py_BEGIN_ALLOW_THREADS |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
3445 #ifdef HAVE_GETHOSTBYNAME_R |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3446 #if defined(HAVE_GETHOSTBYNAME_R_6_ARG) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3447 result = gethostbyaddr_r(ap, al, af, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3448 &hp_allocated, buf, buf_len, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3449 &h, &errnop); |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3450 #elif defined(HAVE_GETHOSTBYNAME_R_5_ARG) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3451 h = gethostbyaddr_r(ap, al, af, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3452 &hp_allocated, buf, buf_len, &errnop); |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3453 #else /* HAVE_GETHOSTBYNAME_R_3_ARG */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3454 memset((void *) &data, '\0', sizeof(data)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3455 result = gethostbyaddr_r(ap, al, af, &hp_allocated, &data); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3456 h = (result != 0) ? NULL : &hp_allocated; |
|
10401
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
3457 #endif |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
3458 #else /* not HAVE_GETHOSTBYNAME_R */ |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
3459 #ifdef USE_GETHOSTBYNAME_LOCK |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3460 PyThread_acquire_lock(netdb_lock, 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3461 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3462 h = gethostbyaddr(ap, al, af); |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
3463 #endif /* HAVE_GETHOSTBYNAME_R */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3464 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3465 ret = gethost_common(h, (struct sockaddr *)&addr, sizeof(addr), af); |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
3466 #ifdef USE_GETHOSTBYNAME_LOCK |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3467 PyThread_release_lock(netdb_lock); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3468 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3469 return ret; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3470 } |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3471 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3472 PyDoc_STRVAR(gethostbyaddr_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3473 "gethostbyaddr(host) -> (name, aliaslist, addresslist)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3474 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3475 Return the true host name, a list of aliases, and a list of IP addresses,\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3476 for a host. The host argument is a string giving a host name or IP number."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3477 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3478 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3479 /* Python interface to getservbyname(name). |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3480 This only returns the port number, since the other info is already |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3481 known or not useful (like the list of aliases). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3482 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3483 /*ARGSUSED*/ |
| 1970 | 3484 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3485 socket_getservbyname(PyObject *self, PyObject *args) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3486 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3487 char *name, *proto=NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3488 struct servent *sp; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3489 if (!PyArg_ParseTuple(args, "s|s:getservbyname", &name, &proto)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3490 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3491 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3492 sp = getservbyname(name, proto); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3493 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3494 if (sp == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3495 PyErr_SetString(socket_error, "service/proto not found"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3496 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3497 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3498 return PyInt_FromLong((long) ntohs(sp->s_port)); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3499 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3500 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3501 PyDoc_STRVAR(getservbyname_doc, |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3502 "getservbyname(servicename[, protocolname]) -> integer\n\ |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3503 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3504 Return a port number from a service name and protocol name.\n\ |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3505 The optional protocol name, if given, should be 'tcp' or 'udp',\n\ |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3506 otherwise any protocol will match."); |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3507 |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3508 |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3509 /* Python interface to getservbyport(port). |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3510 This only returns the service name, since the other info is already |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3511 known or not useful (like the list of aliases). */ |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3512 |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3513 /*ARGSUSED*/ |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3514 static PyObject * |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3515 socket_getservbyport(PyObject *self, PyObject *args) |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3516 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3517 int port; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3518 char *proto=NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3519 struct servent *sp; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3520 if (!PyArg_ParseTuple(args, "i|s:getservbyport", &port, &proto)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3521 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3522 if (port < 0 || port > 0xffff) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3523 PyErr_SetString( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3524 PyExc_OverflowError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3525 "getservbyport: port must be 0-65535."); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3526 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3527 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3528 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3529 sp = getservbyport(htons((short)port), proto); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3530 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3531 if (sp == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3532 PyErr_SetString(socket_error, "port/proto not found"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3533 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3534 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3535 return PyString_FromString(sp->s_name); |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3536 } |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3537 |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3538 PyDoc_STRVAR(getservbyport_doc, |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3539 "getservbyport(port[, protocolname]) -> string\n\ |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3540 \n\ |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3541 Return the service name from a port number and protocol name.\n\ |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3542 The optional protocol name, if given, should be 'tcp' or 'udp',\n\ |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3543 otherwise any protocol will match."); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3544 |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3545 /* Python interface to getprotobyname(name). |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3546 This only returns the protocol number, since the other info is |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3547 already known or not useful (like the list of aliases). */ |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3548 |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3549 /*ARGSUSED*/ |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3550 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3551 socket_getprotobyname(PyObject *self, PyObject *args) |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3552 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3553 char *name; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3554 struct protoent *sp; |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
3555 #ifdef __BEOS__ |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
3556 /* Not available in BeOS yet. - [cjh] */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3557 PyErr_SetString(socket_error, "getprotobyname not supported"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3558 return NULL; |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
3559 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3560 if (!PyArg_ParseTuple(args, "s:getprotobyname", &name)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3561 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3562 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3563 sp = getprotobyname(name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3564 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3565 if (sp == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3566 PyErr_SetString(socket_error, "protocol not found"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3567 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3568 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3569 return PyInt_FromLong((long) sp->p_proto); |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
3570 #endif |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3571 } |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3572 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3573 PyDoc_STRVAR(getprotobyname_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3574 "getprotobyname(name) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3575 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3576 Return the protocol number for the named protocol. (Rarely used.)"); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3577 |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3578 |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3579 #ifdef HAVE_SOCKETPAIR |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3580 /* Create a pair of sockets using the socketpair() function. |
|
33239
fb9869044bba
Updated the socketpair() docstring and documentation to explain that the
Dave Cole <djc@object-craft.com.au>
parents:
33238
diff
changeset
|
3581 Arguments as for socket() except the default family is AF_UNIX if |
|
33280
826ad896a7a5
Patch #1015012. Improve markup and punctuation in libsocket.tex
Dave Cole <djc@object-craft.com.au>
parents:
33260
diff
changeset
|
3582 defined on the platform; otherwise, the default is AF_INET. */ |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3583 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3584 /*ARGSUSED*/ |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3585 static PyObject * |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3586 socket_socketpair(PyObject *self, PyObject *args) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3587 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3588 PySocketSockObject *s0 = NULL, *s1 = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3589 SOCKET_T sv[2]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3590 int family, type = SOCK_STREAM, proto = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3591 PyObject *res = NULL; |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3592 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3593 #if defined(AF_UNIX) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3594 family = AF_UNIX; |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3595 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3596 family = AF_INET; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3597 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3598 if (!PyArg_ParseTuple(args, "|iii:socketpair", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3599 &family, &type, &proto)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3600 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3601 /* Create a pair of socket fds */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3602 if (socketpair(family, type, proto, sv) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3603 return set_error(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3604 s0 = new_sockobject(sv[0], family, type, proto); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3605 if (s0 == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3606 goto finally; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3607 s1 = new_sockobject(sv[1], family, type, proto); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3608 if (s1 == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3609 goto finally; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3610 res = PyTuple_Pack(2, s0, s1); |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3611 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3612 finally: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3613 if (res == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3614 if (s0 == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3615 SOCKETCLOSE(sv[0]); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3616 if (s1 == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3617 SOCKETCLOSE(sv[1]); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3618 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3619 Py_XDECREF(s0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3620 Py_XDECREF(s1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3621 return res; |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3622 } |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3623 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3624 PyDoc_STRVAR(socketpair_doc, |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3625 "socketpair([family[, type[, proto]]]) -> (socket object, socket object)\n\ |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3626 \n\ |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3627 Create a pair of socket objects from the sockets returned by the platform\n\ |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3628 socketpair() function.\n\ |
|
33239
fb9869044bba
Updated the socketpair() docstring and documentation to explain that the
Dave Cole <djc@object-craft.com.au>
parents:
33238
diff
changeset
|
3629 The arguments are the same as for socket() except the default family is\n\ |
|
33280
826ad896a7a5
Patch #1015012. Improve markup and punctuation in libsocket.tex
Dave Cole <djc@object-craft.com.au>
parents:
33260
diff
changeset
|
3630 AF_UNIX if defined on the platform; otherwise, the default is AF_INET."); |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3631 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3632 #endif /* HAVE_SOCKETPAIR */ |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3633 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3634 |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
3635 #ifndef NO_DUP |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
3636 /* Create a socket object from a numeric file description. |
|
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
3637 Useful e.g. if stdin is a socket. |
|
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
3638 Additional arguments as for socket(). */ |
|
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
3639 |
|
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
3640 /*ARGSUSED*/ |
| 1970 | 3641 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3642 socket_fromfd(PyObject *self, PyObject *args) |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
3643 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3644 PySocketSockObject *s; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3645 SOCKET_T fd; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3646 int family, type, proto = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3647 if (!PyArg_ParseTuple(args, "iii|i:fromfd", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3648 &fd, &family, &type, &proto)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3649 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3650 /* Dup the fd so it and the socket can be closed independently */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3651 fd = dup(fd); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3652 if (fd < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3653 return set_error(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3654 s = new_sockobject(fd, family, type, proto); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3655 return (PyObject *) s; |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
3656 } |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3657 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3658 PyDoc_STRVAR(fromfd_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3659 "fromfd(fd, family, type[, proto]) -> socket object\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3660 \n\ |
|
37371
492044034a87
Bug #1460564: document that socket.fromfd() duplicates the given
Georg Brandl <georg@python.org>
parents:
37069
diff
changeset
|
3661 Create a socket object from a duplicate of the given\n\ |
|
492044034a87
Bug #1460564: document that socket.fromfd() duplicates the given
Georg Brandl <georg@python.org>
parents:
37069
diff
changeset
|
3662 file descriptor.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3663 The remaining arguments are the same as for socket()."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3664 |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
3665 #endif /* NO_DUP */ |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
3666 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3667 |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3668 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3669 socket_ntohs(PyObject *self, PyObject *args) |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3670 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3671 int x1, x2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3672 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3673 if (!PyArg_ParseTuple(args, "i:ntohs", &x1)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3674 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3675 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3676 if (x1 < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3677 PyErr_SetString(PyExc_OverflowError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3678 "can't convert negative number to unsigned long"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3679 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3680 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3681 x2 = (unsigned int)ntohs((unsigned short)x1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3682 return PyInt_FromLong(x2); |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3683 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3684 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3685 PyDoc_STRVAR(ntohs_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3686 "ntohs(integer) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3687 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3688 Convert a 16-bit integer from network to host byte order."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3689 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3690 |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3691 static PyObject * |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3692 socket_ntohl(PyObject *self, PyObject *arg) |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3693 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3694 unsigned long x; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3695 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3696 if (PyInt_Check(arg)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3697 x = PyInt_AS_LONG(arg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3698 if (x == (unsigned long) -1 && PyErr_Occurred()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3699 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3700 if ((long)x < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3701 PyErr_SetString(PyExc_OverflowError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3702 "can't convert negative number to unsigned long"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3703 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3704 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3705 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3706 else if (PyLong_Check(arg)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3707 x = PyLong_AsUnsignedLong(arg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3708 if (x == (unsigned long) -1 && PyErr_Occurred()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3709 return NULL; |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3710 #if SIZEOF_LONG > 4 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3711 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3712 unsigned long y; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3713 /* only want the trailing 32 bits */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3714 y = x & 0xFFFFFFFFUL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3715 if (y ^ x) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3716 return PyErr_Format(PyExc_OverflowError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3717 "long int larger than 32 bits"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3718 x = y; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3719 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3720 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3721 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3722 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3723 return PyErr_Format(PyExc_TypeError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3724 "expected int/long, %s found", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3725 Py_TYPE(arg)->tp_name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3726 if (x == (unsigned long) -1 && PyErr_Occurred()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3727 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3728 return PyLong_FromUnsignedLong(ntohl(x)); |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3729 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3730 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3731 PyDoc_STRVAR(ntohl_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3732 "ntohl(integer) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3733 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3734 Convert a 32-bit integer from network to host byte order."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3735 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3736 |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3737 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3738 socket_htons(PyObject *self, PyObject *args) |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3739 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3740 int x1, x2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3741 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3742 if (!PyArg_ParseTuple(args, "i:htons", &x1)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3743 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3744 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3745 if (x1 < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3746 PyErr_SetString(PyExc_OverflowError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3747 "can't convert negative number to unsigned long"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3748 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3749 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3750 x2 = (unsigned int)htons((unsigned short)x1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3751 return PyInt_FromLong(x2); |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3752 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3753 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3754 PyDoc_STRVAR(htons_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3755 "htons(integer) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3756 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3757 Convert a 16-bit integer from host to network byte order."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3758 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3759 |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3760 static PyObject * |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3761 socket_htonl(PyObject *self, PyObject *arg) |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3762 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3763 unsigned long x; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3764 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3765 if (PyInt_Check(arg)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3766 x = PyInt_AS_LONG(arg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3767 if (x == (unsigned long) -1 && PyErr_Occurred()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3768 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3769 if ((long)x < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3770 PyErr_SetString(PyExc_OverflowError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3771 "can't convert negative number to unsigned long"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3772 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3773 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3774 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3775 else if (PyLong_Check(arg)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3776 x = PyLong_AsUnsignedLong(arg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3777 if (x == (unsigned long) -1 && PyErr_Occurred()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3778 return NULL; |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3779 #if SIZEOF_LONG > 4 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3780 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3781 unsigned long y; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3782 /* only want the trailing 32 bits */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3783 y = x & 0xFFFFFFFFUL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3784 if (y ^ x) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3785 return PyErr_Format(PyExc_OverflowError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3786 "long int larger than 32 bits"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3787 x = y; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3788 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3789 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3790 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3791 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3792 return PyErr_Format(PyExc_TypeError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3793 "expected int/long, %s found", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3794 Py_TYPE(arg)->tp_name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3795 return PyLong_FromUnsignedLong(htonl((unsigned long)x)); |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3796 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3797 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3798 PyDoc_STRVAR(htonl_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3799 "htonl(integer) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3800 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3801 Convert a 32-bit integer from host to network byte order."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3802 |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
3803 /* socket.inet_aton() and socket.inet_ntoa() functions. */ |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3804 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3805 PyDoc_STRVAR(inet_aton_doc, |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3806 "inet_aton(string) -> packed 32-bit IP representation\n\ |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3807 \n\ |
|
11219
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
3808 Convert an IP address in string format (123.45.67.89) to the 32-bit packed\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3809 binary format used in low-level network functions."); |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3810 |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3811 static PyObject* |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3812 socket_inet_aton(PyObject *self, PyObject *args) |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3813 { |
|
11268
3fe8d13328c8
It appears that inet_aton() doesn't really exist except in libresolv;
Guido van Rossum <guido@python.org>
parents:
11219
diff
changeset
|
3814 #ifndef INADDR_NONE |
|
3fe8d13328c8
It appears that inet_aton() doesn't really exist except in libresolv;
Guido van Rossum <guido@python.org>
parents:
11219
diff
changeset
|
3815 #define INADDR_NONE (-1) |
|
3fe8d13328c8
It appears that inet_aton() doesn't really exist except in libresolv;
Guido van Rossum <guido@python.org>
parents:
11219
diff
changeset
|
3816 #endif |
|
27858
9453d8cdd01e
Ummm, try to get it right this time
Neal Norwitz <nnorwitz@gmail.com>
parents:
27857
diff
changeset
|
3817 #ifdef HAVE_INET_ATON |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3818 struct in_addr buf; |
|
37934
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3819 #endif |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3820 |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3821 #if !defined(HAVE_INET_ATON) || defined(USE_INET_ATON_WEAKLINK) |
|
51538
edcf996f07e9
Issue #1008086: Fixes socket.inet_aton() to always return 4 bytes even
Gregory P. Smith <greg@mad-scientist.com>
parents:
51220
diff
changeset
|
3822 #if (SIZEOF_INT != 4) |
|
edcf996f07e9
Issue #1008086: Fixes socket.inet_aton() to always return 4 bytes even
Gregory P. Smith <greg@mad-scientist.com>
parents:
51220
diff
changeset
|
3823 #error "Not sure if in_addr_t exists and int is not 32-bits." |
|
edcf996f07e9
Issue #1008086: Fixes socket.inet_aton() to always return 4 bytes even
Gregory P. Smith <greg@mad-scientist.com>
parents:
51220
diff
changeset
|
3824 #endif |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3825 /* Have to use inet_addr() instead */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3826 unsigned int packed_addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3827 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3828 char *ip_addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3829 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3830 if (!PyArg_ParseTuple(args, "s:inet_aton", &ip_addr)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3831 return NULL; |
|
27861
f8440bb8ede5
socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents:
27858
diff
changeset
|
3832 |
|
f8440bb8ede5
socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents:
27858
diff
changeset
|
3833 |
|
f8440bb8ede5
socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents:
27858
diff
changeset
|
3834 #ifdef HAVE_INET_ATON |
|
37934
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3835 |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3836 #ifdef USE_INET_ATON_WEAKLINK |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3837 if (inet_aton != NULL) { |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3838 #endif |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3839 if (inet_aton(ip_addr, &buf)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3840 return PyString_FromStringAndSize((char *)(&buf), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3841 sizeof(buf)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3842 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3843 PyErr_SetString(socket_error, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3844 "illegal IP address string passed to inet_aton"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3845 return NULL; |
|
27854
81afca747caa
Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents:
27558
diff
changeset
|
3846 |
|
37934
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3847 #ifdef USE_INET_ATON_WEAKLINK |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3848 } else { |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3849 #endif |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3850 |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3851 #endif |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3852 |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3853 #if !defined(HAVE_INET_ATON) || defined(USE_INET_ATON_WEAKLINK) |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3854 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3855 /* special-case this address as inet_addr might return INADDR_NONE |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3856 * for this */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3857 if (strcmp(ip_addr, "255.255.255.255") == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3858 packed_addr = 0xFFFFFFFF; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3859 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3860 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3861 packed_addr = inet_addr(ip_addr); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3862 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3863 if (packed_addr == INADDR_NONE) { /* invalid address */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3864 PyErr_SetString(socket_error, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3865 "illegal IP address string passed to inet_aton"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3866 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3867 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3868 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3869 return PyString_FromStringAndSize((char *) &packed_addr, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3870 sizeof(packed_addr)); |
|
37934
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3871 |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3872 #ifdef USE_INET_ATON_WEAKLINK |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3873 } |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3874 #endif |
|
ea67628ddae5
Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
37853
diff
changeset
|
3875 |
|
27854
81afca747caa
Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents:
27558
diff
changeset
|
3876 #endif |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3877 } |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3878 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3879 PyDoc_STRVAR(inet_ntoa_doc, |
| 11937 | 3880 "inet_ntoa(packed_ip) -> ip_address_string\n\ |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3881 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3882 Convert an IP address from 32-bit packed binary format to string format"); |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3883 |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3884 static PyObject* |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3885 socket_inet_ntoa(PyObject *self, PyObject *args) |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3886 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3887 char *packed_str; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3888 int addr_len; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3889 struct in_addr packed_addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3890 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3891 if (!PyArg_ParseTuple(args, "s#:inet_ntoa", &packed_str, &addr_len)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3892 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3893 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3894 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3895 if (addr_len != sizeof(packed_addr)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3896 PyErr_SetString(socket_error, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3897 "packed IP wrong length for inet_ntoa"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3898 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3899 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3900 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3901 memcpy(&packed_addr, packed_str, addr_len); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3902 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3903 return PyString_FromString(inet_ntoa(packed_addr)); |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3904 } |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3905 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3906 #ifdef HAVE_INET_PTON |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3907 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3908 PyDoc_STRVAR(inet_pton_doc, |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3909 "inet_pton(af, ip) -> packed IP address string\n\ |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3910 \n\ |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3911 Convert an IP address from string format to a packed string suitable\n\ |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3912 for use with low-level network functions."); |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3913 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3914 static PyObject * |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3915 socket_inet_pton(PyObject *self, PyObject *args) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3916 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3917 int af; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3918 char* ip; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3919 int retval; |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
3920 #ifdef ENABLE_IPV6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3921 char packed[MAX(sizeof(struct in_addr), sizeof(struct in6_addr))]; |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
3922 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3923 char packed[sizeof(struct in_addr)]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3924 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3925 if (!PyArg_ParseTuple(args, "is:inet_pton", &af, &ip)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3926 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3927 } |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3928 |
|
32183
a799b0d1c568
Patch #924294: Do not check for AF_INET6 if it is not defined.
Martin v. Löwis <martin@v.loewis.de>
parents:
32149
diff
changeset
|
3929 #if !defined(ENABLE_IPV6) && defined(AF_INET6) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3930 if(af == AF_INET6) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3931 PyErr_SetString(socket_error, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3932 "can't use AF_INET6, IPv6 is disabled"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3933 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3934 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3935 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3936 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3937 retval = inet_pton(af, ip, packed); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3938 if (retval < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3939 PyErr_SetFromErrno(socket_error); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3940 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3941 } else if (retval == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3942 PyErr_SetString(socket_error, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3943 "illegal IP address string passed to inet_pton"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3944 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3945 } else if (af == AF_INET) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3946 return PyString_FromStringAndSize(packed, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3947 sizeof(struct in_addr)); |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
3948 #ifdef ENABLE_IPV6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3949 } else if (af == AF_INET6) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3950 return PyString_FromStringAndSize(packed, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3951 sizeof(struct in6_addr)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3952 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3953 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3954 PyErr_SetString(socket_error, "unknown address family"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3955 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3956 } |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3957 } |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37979
diff
changeset
|
3958 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3959 PyDoc_STRVAR(inet_ntop_doc, |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3960 "inet_ntop(af, packed_ip) -> string formatted IP address\n\ |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3961 \n\ |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3962 Convert a packed IP address of the given family to string format."); |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3963 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3964 static PyObject * |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3965 socket_inet_ntop(PyObject *self, PyObject *args) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3966 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3967 int af; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3968 char* packed; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3969 int len; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3970 const char* retval; |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
3971 #ifdef ENABLE_IPV6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3972 char ip[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN) + 1]; |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
3973 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3974 char ip[INET_ADDRSTRLEN + 1]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3975 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3976 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3977 /* Guarantee NUL-termination for PyString_FromString() below */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3978 memset((void *) &ip[0], '\0', sizeof(ip)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3979 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3980 if (!PyArg_ParseTuple(args, "is#:inet_ntop", &af, &packed, &len)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3981 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3982 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3983 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3984 if (af == AF_INET) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3985 if (len != sizeof(struct in_addr)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3986 PyErr_SetString(PyExc_ValueError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3987 "invalid length of packed IP address string"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3988 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3989 } |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
3990 #ifdef ENABLE_IPV6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3991 } else if (af == AF_INET6) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3992 if (len != sizeof(struct in6_addr)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3993 PyErr_SetString(PyExc_ValueError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3994 "invalid length of packed IP address string"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3995 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3996 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3997 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3998 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
3999 PyErr_Format(PyExc_ValueError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4000 "unknown address family %d", af); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4001 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4002 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4003 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4004 retval = inet_ntop(af, packed, ip, sizeof(ip)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4005 if (!retval) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4006 PyErr_SetFromErrno(socket_error); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4007 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4008 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4009 return PyString_FromString(retval); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4010 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4011 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4012 /* NOTREACHED */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4013 PyErr_SetString(PyExc_RuntimeError, "invalid handling of inet_ntop"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4014 return NULL; |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4015 } |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4016 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4017 #endif /* HAVE_INET_PTON */ |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4018 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4019 /* Python interface to getaddrinfo(host, port). */ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4020 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4021 /*ARGSUSED*/ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4022 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4023 socket_getaddrinfo(PyObject *self, PyObject *args) |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4024 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4025 struct addrinfo hints, *res; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4026 struct addrinfo *res0 = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4027 PyObject *hobj = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4028 PyObject *pobj = (PyObject *)NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4029 char pbuf[30]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4030 char *hptr, *pptr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4031 int family, socktype, protocol, flags; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4032 int error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4033 PyObject *all = (PyObject *)NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4034 PyObject *single = (PyObject *)NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4035 PyObject *idna = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4036 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4037 family = socktype = protocol = flags = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4038 family = AF_UNSPEC; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4039 if (!PyArg_ParseTuple(args, "OO|iiii:getaddrinfo", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4040 &hobj, &pobj, &family, &socktype, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4041 &protocol, &flags)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4042 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4043 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4044 if (hobj == Py_None) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4045 hptr = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4046 } else if (PyUnicode_Check(hobj)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4047 idna = PyObject_CallMethod(hobj, "encode", "s", "idna"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4048 if (!idna) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4049 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4050 hptr = PyString_AsString(idna); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4051 } else if (PyString_Check(hobj)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4052 hptr = PyString_AsString(hobj); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4053 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4054 PyErr_SetString(PyExc_TypeError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4055 "getaddrinfo() argument 1 must be string or None"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4056 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4057 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4058 if (PyInt_Check(pobj)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4059 PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", PyInt_AsLong(pobj)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4060 pptr = pbuf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4061 } else if (PyString_Check(pobj)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4062 pptr = PyString_AsString(pobj); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4063 } else if (pobj == Py_None) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4064 pptr = (char *)NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4065 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4066 PyErr_SetString(socket_error, "Int or String expected"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4067 goto err; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4068 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4069 memset(&hints, 0, sizeof(hints)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4070 hints.ai_family = family; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4071 hints.ai_socktype = socktype; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4072 hints.ai_protocol = protocol; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4073 hints.ai_flags = flags; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4074 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4075 ACQUIRE_GETADDRINFO_LOCK |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4076 error = getaddrinfo(hptr, pptr, &hints, &res0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4077 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4078 RELEASE_GETADDRINFO_LOCK /* see comment in setipaddr() */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4079 if (error) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4080 set_gaierror(error); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4081 goto err; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4082 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4083 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4084 if ((all = PyList_New(0)) == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4085 goto err; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4086 for (res = res0; res; res = res->ai_next) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4087 PyObject *addr = |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4088 makesockaddr(-1, res->ai_addr, res->ai_addrlen, protocol); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4089 if (addr == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4090 goto err; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4091 single = Py_BuildValue("iiisO", res->ai_family, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4092 res->ai_socktype, res->ai_protocol, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4093 res->ai_canonname ? res->ai_canonname : "", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4094 addr); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4095 Py_DECREF(addr); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4096 if (single == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4097 goto err; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4098 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4099 if (PyList_Append(all, single)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4100 goto err; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4101 Py_XDECREF(single); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4102 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4103 Py_XDECREF(idna); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4104 if (res0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4105 freeaddrinfo(res0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4106 return all; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4107 err: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4108 Py_XDECREF(single); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4109 Py_XDECREF(all); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4110 Py_XDECREF(idna); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4111 if (res0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4112 freeaddrinfo(res0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4113 return (PyObject *)NULL; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4114 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4115 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
4116 PyDoc_STRVAR(getaddrinfo_doc, |
|
24676
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
4117 "getaddrinfo(host, port [, family, socktype, proto, flags])\n\ |
|
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
4118 -> list of (family, socktype, proto, canonname, sockaddr)\n\ |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4119 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
4120 Resolve host and port into addrinfo struct."); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4121 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4122 /* Python interface to getnameinfo(sa, flags). */ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4123 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4124 /*ARGSUSED*/ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4125 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4126 socket_getnameinfo(PyObject *self, PyObject *args) |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4127 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4128 PyObject *sa = (PyObject *)NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4129 int flags; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4130 char *hostp; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4131 int port, flowinfo, scope_id; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4132 char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4133 struct addrinfo hints, *res = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4134 int error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4135 PyObject *ret = (PyObject *)NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4136 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4137 flags = flowinfo = scope_id = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4138 if (!PyArg_ParseTuple(args, "Oi:getnameinfo", &sa, &flags)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4139 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4140 if (!PyTuple_Check(sa)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4141 PyErr_SetString(PyExc_TypeError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4142 "getnameinfo() argument 1 must be a tuple"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4143 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4144 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4145 if (!PyArg_ParseTuple(sa, "si|ii", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4146 &hostp, &port, &flowinfo, &scope_id)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4147 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4148 PyOS_snprintf(pbuf, sizeof(pbuf), "%d", port); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4149 memset(&hints, 0, sizeof(hints)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4150 hints.ai_family = AF_UNSPEC; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4151 hints.ai_socktype = SOCK_DGRAM; /* make numeric port happy */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4152 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4153 ACQUIRE_GETADDRINFO_LOCK |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4154 error = getaddrinfo(hostp, pbuf, &hints, &res); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4155 Py_END_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4156 RELEASE_GETADDRINFO_LOCK /* see comment in setipaddr() */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4157 if (error) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4158 set_gaierror(error); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4159 goto fail; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4160 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4161 if (res->ai_next) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4162 PyErr_SetString(socket_error, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4163 "sockaddr resolved to multiple addresses"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4164 goto fail; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4165 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4166 switch (res->ai_family) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4167 case AF_INET: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4168 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4169 if (PyTuple_GET_SIZE(sa) != 2) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4170 PyErr_SetString(socket_error, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4171 "IPv4 sockaddr must be 2 tuple"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4172 goto fail; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4173 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4174 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4175 } |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
4176 #ifdef ENABLE_IPV6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4177 case AF_INET6: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4178 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4179 struct sockaddr_in6 *sin6; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4180 sin6 = (struct sockaddr_in6 *)res->ai_addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4181 sin6->sin6_flowinfo = flowinfo; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4182 sin6->sin6_scope_id = scope_id; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4183 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4184 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4185 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4186 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4187 error = getnameinfo(res->ai_addr, res->ai_addrlen, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4188 hbuf, sizeof(hbuf), pbuf, sizeof(pbuf), flags); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4189 if (error) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4190 set_gaierror(error); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4191 goto fail; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4192 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4193 ret = Py_BuildValue("ss", hbuf, pbuf); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4194 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4195 fail: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4196 if (res) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4197 freeaddrinfo(res); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4198 return ret; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4199 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4200 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
4201 PyDoc_STRVAR(getnameinfo_doc, |
|
24676
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
4202 "getnameinfo(sockaddr, flags) --> (host, port)\n\ |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4203 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
4204 Get host and port for a sockaddr."); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4205 |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4206 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4207 /* Python API to getting and setting the default timeout value. */ |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4208 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4209 static PyObject * |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4210 socket_getdefaulttimeout(PyObject *self) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4211 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4212 if (defaulttimeout < 0.0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4213 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4214 return Py_None; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4215 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4216 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4217 return PyFloat_FromDouble(defaulttimeout); |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4218 } |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4219 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4220 PyDoc_STRVAR(getdefaulttimeout_doc, |
|
24676
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
4221 "getdefaulttimeout() -> timeout\n\ |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4222 \n\ |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4223 Returns the default timeout in floating seconds for new socket objects.\n\ |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4224 A value of None indicates that new socket objects have no timeout.\n\ |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4225 When the socket module is first imported, the default is None."); |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4226 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4227 static PyObject * |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4228 socket_setdefaulttimeout(PyObject *self, PyObject *arg) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4229 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4230 double timeout; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4231 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4232 if (arg == Py_None) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4233 timeout = -1.0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4234 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4235 timeout = PyFloat_AsDouble(arg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4236 if (timeout < 0.0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4237 if (!PyErr_Occurred()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4238 PyErr_SetString(PyExc_ValueError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4239 "Timeout value out of range"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4240 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4241 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4242 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4243 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4244 defaulttimeout = timeout; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4245 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4246 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4247 return Py_None; |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4248 } |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4249 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4250 PyDoc_STRVAR(setdefaulttimeout_doc, |
|
24676
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
4251 "setdefaulttimeout(timeout)\n\ |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4252 \n\ |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4253 Set the default timeout in floating seconds for new socket objects.\n\ |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4254 A value of None indicates that new socket objects have no timeout.\n\ |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4255 When the socket module is first imported, the default is None."); |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4256 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4257 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
4258 /* List of functions exported by this module. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
4259 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4260 static PyMethodDef socket_methods[] = { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4261 {"gethostbyname", socket_gethostbyname, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4262 METH_VARARGS, gethostbyname_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4263 {"gethostbyname_ex", socket_gethostbyname_ex, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4264 METH_VARARGS, ghbn_ex_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4265 {"gethostbyaddr", socket_gethostbyaddr, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4266 METH_VARARGS, gethostbyaddr_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4267 {"gethostname", socket_gethostname, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4268 METH_NOARGS, gethostname_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4269 {"getservbyname", socket_getservbyname, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4270 METH_VARARGS, getservbyname_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4271 {"getservbyport", socket_getservbyport, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4272 METH_VARARGS, getservbyport_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4273 {"getprotobyname", socket_getprotobyname, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4274 METH_VARARGS, getprotobyname_doc}, |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
4275 #ifndef NO_DUP |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4276 {"fromfd", socket_fromfd, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4277 METH_VARARGS, fromfd_doc}, |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
4278 #endif |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
4279 #ifdef HAVE_SOCKETPAIR |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4280 {"socketpair", socket_socketpair, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4281 METH_VARARGS, socketpair_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4282 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4283 {"ntohs", socket_ntohs, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4284 METH_VARARGS, ntohs_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4285 {"ntohl", socket_ntohl, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4286 METH_O, ntohl_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4287 {"htons", socket_htons, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4288 METH_VARARGS, htons_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4289 {"htonl", socket_htonl, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4290 METH_O, htonl_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4291 {"inet_aton", socket_inet_aton, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4292 METH_VARARGS, inet_aton_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4293 {"inet_ntoa", socket_inet_ntoa, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4294 METH_VARARGS, inet_ntoa_doc}, |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4295 #ifdef HAVE_INET_PTON |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4296 {"inet_pton", socket_inet_pton, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4297 METH_VARARGS, inet_pton_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4298 {"inet_ntop", socket_inet_ntop, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4299 METH_VARARGS, inet_ntop_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4300 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4301 {"getaddrinfo", socket_getaddrinfo, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4302 METH_VARARGS, getaddrinfo_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4303 {"getnameinfo", socket_getnameinfo, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4304 METH_VARARGS, getnameinfo_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4305 {"getdefaulttimeout", (PyCFunction)socket_getdefaulttimeout, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4306 METH_NOARGS, getdefaulttimeout_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4307 {"setdefaulttimeout", socket_setdefaulttimeout, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4308 METH_O, setdefaulttimeout_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4309 {NULL, NULL} /* Sentinel */ |
| 294 | 4310 }; |
| 4311 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
4312 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4313 #ifdef RISCOS |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4314 #define OS_INIT_DEFINED |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4315 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4316 static int |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4317 os_init(void) |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4318 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4319 _kernel_swi_regs r; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4320 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4321 r.r[0] = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4322 _kernel_swi(0x43380, &r, &r); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4323 taskwindow = r.r[0]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4324 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4325 return 1; |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4326 } |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4327 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4328 #endif /* RISCOS */ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4329 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4330 |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
4331 #ifdef MS_WINDOWS |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4332 #define OS_INIT_DEFINED |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4333 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4334 /* Additional initialization and cleanup for Windows */ |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
4335 |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
4336 static void |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4337 os_cleanup(void) |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
4338 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4339 WSACleanup(); |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
4340 } |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
4341 |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
4342 static int |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4343 os_init(void) |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
4344 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4345 WSADATA WSAData; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4346 int ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4347 char buf[100]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4348 ret = WSAStartup(0x0101, &WSAData); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4349 switch (ret) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4350 case 0: /* No error */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4351 Py_AtExit(os_cleanup); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4352 return 1; /* Success */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4353 case WSASYSNOTREADY: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4354 PyErr_SetString(PyExc_ImportError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4355 "WSAStartup failed: network not ready"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4356 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4357 case WSAVERNOTSUPPORTED: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4358 case WSAEINVAL: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4359 PyErr_SetString( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4360 PyExc_ImportError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4361 "WSAStartup failed: requested version not supported"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4362 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4363 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4364 PyOS_snprintf(buf, sizeof(buf), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4365 "WSAStartup failed: error code %d", ret); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4366 PyErr_SetString(PyExc_ImportError, buf); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4367 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4368 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4369 return 0; /* Failure */ |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
4370 } |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
4371 |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
4372 #endif /* MS_WINDOWS */ |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
4373 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4374 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4375 #ifdef PYOS_OS2 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4376 #define OS_INIT_DEFINED |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4377 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4378 /* Additional initialization for OS/2 */ |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
4379 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
4380 static int |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4381 os_init(void) |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
4382 { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4383 #ifndef PYCC_GCC |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4384 char reason[64]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4385 int rc = sock_init(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4386 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4387 if (rc == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4388 return 1; /* Success */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4389 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4390 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4391 PyOS_snprintf(reason, sizeof(reason), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4392 "OS/2 TCP/IP Error# %d", sock_errno()); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4393 PyErr_SetString(PyExc_ImportError, reason); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4394 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4395 return 0; /* Failure */ |
|
22115
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
4396 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4397 /* No need to initialise sockets with GCC/EMX */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4398 return 1; /* Success */ |
|
22115
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
4399 #endif |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
4400 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
4401 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
4402 #endif /* PYOS_OS2 */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
4403 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4404 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4405 #ifndef OS_INIT_DEFINED |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4406 static int |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4407 os_init(void) |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4408 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4409 return 1; /* Success */ |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4410 } |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4411 #endif |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4412 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4413 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
4414 /* C API table - always add new things to the end for binary |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
4415 compatibility. */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
4416 static |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
4417 PySocketModule_APIObject PySocketModuleAPI = |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
4418 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4419 &sock_type, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4420 NULL |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
4421 }; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
4422 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4423 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4424 /* Initialize the _socket module. |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4425 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4426 This module is actually called "_socket", and there's a wrapper |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4427 "socket.py" which implements some additional functionality. On some |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4428 platforms (e.g. Windows and OS/2), socket.py also implements a |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4429 wrapper for the socket type that provides missing functionality such |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4430 as makefile(), dup() and fromfd(). The import of "_socket" may fail |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4431 with an ImportError exception if os-specific initialization fails. |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4432 On Windows, this does WINSOCK initialization. When WINSOCK is |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4433 initialized succesfully, a call to WSACleanup() is scheduled to be |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4434 made at exit time. |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4435 */ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4436 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
4437 PyDoc_STRVAR(socket_doc, |
|
24676
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
4438 "Implementation module for socket operations.\n\ |
|
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
4439 \n\ |
|
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
4440 See the socket module for documentation."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
4441 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24411
diff
changeset
|
4442 PyMODINIT_FUNC |
|
13694
b54f11ada91e
Create a new section of pyport.h to hold all external function declarations
Thomas Wouters <thomas@python.org>
parents:
13680
diff
changeset
|
4443 init_socket(void) |
| 294 | 4444 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4445 PyObject *m, *has_ipv6; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4446 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4447 if (!os_init()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4448 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4449 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4450 Py_TYPE(&sock_type) = &PyType_Type; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4451 m = Py_InitModule3(PySocket_MODULE_NAME, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4452 socket_methods, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4453 socket_doc); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4454 if (m == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4455 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4456 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4457 socket_error = PyErr_NewException("socket.error", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4458 PyExc_IOError, NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4459 if (socket_error == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4460 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4461 PySocketModuleAPI.error = socket_error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4462 Py_INCREF(socket_error); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4463 PyModule_AddObject(m, "error", socket_error); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4464 socket_herror = PyErr_NewException("socket.herror", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4465 socket_error, NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4466 if (socket_herror == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4467 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4468 Py_INCREF(socket_herror); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4469 PyModule_AddObject(m, "herror", socket_herror); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4470 socket_gaierror = PyErr_NewException("socket.gaierror", socket_error, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4471 NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4472 if (socket_gaierror == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4473 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4474 Py_INCREF(socket_gaierror); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4475 PyModule_AddObject(m, "gaierror", socket_gaierror); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4476 socket_timeout = PyErr_NewException("socket.timeout", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4477 socket_error, NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4478 if (socket_timeout == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4479 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4480 Py_INCREF(socket_timeout); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4481 PyModule_AddObject(m, "timeout", socket_timeout); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4482 Py_INCREF((PyObject *)&sock_type); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4483 if (PyModule_AddObject(m, "SocketType", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4484 (PyObject *)&sock_type) != 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4485 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4486 Py_INCREF((PyObject *)&sock_type); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4487 if (PyModule_AddObject(m, "socket", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4488 (PyObject *)&sock_type) != 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4489 return; |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4490 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4491 #ifdef ENABLE_IPV6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4492 has_ipv6 = Py_True; |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4493 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4494 has_ipv6 = Py_False; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4495 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4496 Py_INCREF(has_ipv6); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4497 PyModule_AddObject(m, "has_ipv6", has_ipv6); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4498 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4499 /* Export C API */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4500 if (PyModule_AddObject(m, PySocket_CAPI_NAME, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4501 PyCapsule_New(&PySocketModuleAPI, PySocket_CAPSULE_NAME, NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4502 ) != 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4503 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4504 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4505 /* Address families (we only support AF_INET and AF_UNIX) */ |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4506 #ifdef AF_UNSPEC |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4507 PyModule_AddIntConstant(m, "AF_UNSPEC", AF_UNSPEC); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4508 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4509 PyModule_AddIntConstant(m, "AF_INET", AF_INET); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4510 #ifdef AF_INET6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4511 PyModule_AddIntConstant(m, "AF_INET6", AF_INET6); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4512 #endif /* AF_INET6 */ |
|
31867
51aaceeaabe1
OS/2's TCP/IP stack supports AF_UNIX sockets, with the limitation that
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
31790
diff
changeset
|
4513 #if defined(AF_UNIX) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4514 PyModule_AddIntConstant(m, "AF_UNIX", AF_UNIX); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
4515 #endif /* AF_UNIX */ |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4516 #ifdef AF_AX25 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4517 /* Amateur Radio AX.25 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4518 PyModule_AddIntConstant(m, "AF_AX25", AF_AX25); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4519 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4520 #ifdef AF_IPX |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4521 PyModule_AddIntConstant(m, "AF_IPX", AF_IPX); /* Novell IPX */ |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4522 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4523 #ifdef AF_APPLETALK |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4524 /* Appletalk DDP */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4525 PyModule_AddIntConstant(m, "AF_APPLETALK", AF_APPLETALK); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4526 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4527 #ifdef AF_NETROM |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4528 /* Amateur radio NetROM */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4529 PyModule_AddIntConstant(m, "AF_NETROM", AF_NETROM); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4530 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4531 #ifdef AF_BRIDGE |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4532 /* Multiprotocol bridge */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4533 PyModule_AddIntConstant(m, "AF_BRIDGE", AF_BRIDGE); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4534 #endif |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4535 #ifdef AF_ATMPVC |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4536 /* ATM PVCs */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4537 PyModule_AddIntConstant(m, "AF_ATMPVC", AF_ATMPVC); |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4538 #endif |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4539 #ifdef AF_AAL5 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4540 /* Reserved for Werner's ATM */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4541 PyModule_AddIntConstant(m, "AF_AAL5", AF_AAL5); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4542 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4543 #ifdef AF_X25 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4544 /* Reserved for X.25 project */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4545 PyModule_AddIntConstant(m, "AF_X25", AF_X25); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4546 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4547 #ifdef AF_INET6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4548 PyModule_AddIntConstant(m, "AF_INET6", AF_INET6); /* IP version 6 */ |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4549 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4550 #ifdef AF_ROSE |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4551 /* Amateur Radio X.25 PLP */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4552 PyModule_AddIntConstant(m, "AF_ROSE", AF_ROSE); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4553 #endif |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4554 #ifdef AF_DECnet |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4555 /* Reserved for DECnet project */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4556 PyModule_AddIntConstant(m, "AF_DECnet", AF_DECnet); |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4557 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4558 #ifdef AF_NETBEUI |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4559 /* Reserved for 802.2LLC project */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4560 PyModule_AddIntConstant(m, "AF_NETBEUI", AF_NETBEUI); |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4561 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4562 #ifdef AF_SECURITY |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4563 /* Security callback pseudo AF */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4564 PyModule_AddIntConstant(m, "AF_SECURITY", AF_SECURITY); |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4565 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4566 #ifdef AF_KEY |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4567 /* PF_KEY key management API */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4568 PyModule_AddIntConstant(m, "AF_KEY", AF_KEY); |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4569 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4570 #ifdef AF_NETLINK |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4571 /* */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4572 PyModule_AddIntConstant(m, "AF_NETLINK", AF_NETLINK); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4573 PyModule_AddIntConstant(m, "NETLINK_ROUTE", NETLINK_ROUTE); |
|
37530
3c7ea50518be
Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents:
37371
diff
changeset
|
4574 #ifdef NETLINK_SKIP |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4575 PyModule_AddIntConstant(m, "NETLINK_SKIP", NETLINK_SKIP); |
|
37530
3c7ea50518be
Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents:
37371
diff
changeset
|
4576 #endif |
|
3c7ea50518be
Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents:
37371
diff
changeset
|
4577 #ifdef NETLINK_W1 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4578 PyModule_AddIntConstant(m, "NETLINK_W1", NETLINK_W1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4579 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4580 PyModule_AddIntConstant(m, "NETLINK_USERSOCK", NETLINK_USERSOCK); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4581 PyModule_AddIntConstant(m, "NETLINK_FIREWALL", NETLINK_FIREWALL); |
|
36632
4d988dda6478
NETLINK_TCPDIAG and NETLINK_NFLOG aren't defined on older Linux
Guido van Rossum <guido@python.org>
parents:
36610
diff
changeset
|
4582 #ifdef NETLINK_TCPDIAG |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4583 PyModule_AddIntConstant(m, "NETLINK_TCPDIAG", NETLINK_TCPDIAG); |
|
36632
4d988dda6478
NETLINK_TCPDIAG and NETLINK_NFLOG aren't defined on older Linux
Guido van Rossum <guido@python.org>
parents:
36610
diff
changeset
|
4584 #endif |
|
4d988dda6478
NETLINK_TCPDIAG and NETLINK_NFLOG aren't defined on older Linux
Guido van Rossum <guido@python.org>
parents:
36610
diff
changeset
|
4585 #ifdef NETLINK_NFLOG |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4586 PyModule_AddIntConstant(m, "NETLINK_NFLOG", NETLINK_NFLOG); |
|
36632
4d988dda6478
NETLINK_TCPDIAG and NETLINK_NFLOG aren't defined on older Linux
Guido van Rossum <guido@python.org>
parents:
36610
diff
changeset
|
4587 #endif |
|
36298
9eeaa33f9640
Get socketmodule to build after adding netlink support.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36289
diff
changeset
|
4588 #ifdef NETLINK_XFRM |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4589 PyModule_AddIntConstant(m, "NETLINK_XFRM", NETLINK_XFRM); |
|
36298
9eeaa33f9640
Get socketmodule to build after adding netlink support.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36289
diff
changeset
|
4590 #endif |
|
37530
3c7ea50518be
Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents:
37371
diff
changeset
|
4591 #ifdef NETLINK_ARPD |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4592 PyModule_AddIntConstant(m, "NETLINK_ARPD", NETLINK_ARPD); |
|
37530
3c7ea50518be
Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents:
37371
diff
changeset
|
4593 #endif |
|
3c7ea50518be
Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents:
37371
diff
changeset
|
4594 #ifdef NETLINK_ROUTE6 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4595 PyModule_AddIntConstant(m, "NETLINK_ROUTE6", NETLINK_ROUTE6); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4596 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4597 PyModule_AddIntConstant(m, "NETLINK_IP6_FW", NETLINK_IP6_FW); |
|
40837
3bbec91c5b8f
Patch #1657276: Make NETLINK_DNRTMSG conditional.
Martin v. Löwis <martin@v.loewis.de>
parents:
40632
diff
changeset
|
4598 #ifdef NETLINK_DNRTMSG |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4599 PyModule_AddIntConstant(m, "NETLINK_DNRTMSG", NETLINK_DNRTMSG); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4600 #endif |
|
37530
3c7ea50518be
Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents:
37371
diff
changeset
|
4601 #ifdef NETLINK_TAPBASE |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4602 PyModule_AddIntConstant(m, "NETLINK_TAPBASE", NETLINK_TAPBASE); |
|
37530
3c7ea50518be
Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents:
37371
diff
changeset
|
4603 #endif |
|
37371
492044034a87
Bug #1460564: document that socket.fromfd() duplicates the given
Georg Brandl <georg@python.org>
parents:
37069
diff
changeset
|
4604 #endif /* AF_NETLINK */ |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4605 #ifdef AF_ROUTE |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4606 /* Alias to emulate 4.4BSD */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4607 PyModule_AddIntConstant(m, "AF_ROUTE", AF_ROUTE); |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4608 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4609 #ifdef AF_ASH |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4610 /* Ash */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4611 PyModule_AddIntConstant(m, "AF_ASH", AF_ASH); |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4612 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4613 #ifdef AF_ECONET |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4614 /* Acorn Econet */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4615 PyModule_AddIntConstant(m, "AF_ECONET", AF_ECONET); |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4616 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4617 #ifdef AF_ATMSVC |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4618 /* ATM SVCs */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4619 PyModule_AddIntConstant(m, "AF_ATMSVC", AF_ATMSVC); |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4620 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4621 #ifdef AF_SNA |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4622 /* Linux SNA Project (nutters!) */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4623 PyModule_AddIntConstant(m, "AF_SNA", AF_SNA); |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4624 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4625 #ifdef AF_IRDA |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4626 /* IRDA sockets */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4627 PyModule_AddIntConstant(m, "AF_IRDA", AF_IRDA); |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4628 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4629 #ifdef AF_PPPOX |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4630 /* PPPoX sockets */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4631 PyModule_AddIntConstant(m, "AF_PPPOX", AF_PPPOX); |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4632 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4633 #ifdef AF_WANPIPE |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4634 /* Wanpipe API Sockets */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4635 PyModule_AddIntConstant(m, "AF_WANPIPE", AF_WANPIPE); |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4636 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4637 #ifdef AF_LLC |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4638 /* Linux LLC */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4639 PyModule_AddIntConstant(m, "AF_LLC", AF_LLC); |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4640 #endif |
|
31441
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
4641 |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
4642 #ifdef USE_BLUETOOTH |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4643 PyModule_AddIntConstant(m, "AF_BLUETOOTH", AF_BLUETOOTH); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4644 PyModule_AddIntConstant(m, "BTPROTO_L2CAP", BTPROTO_L2CAP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4645 PyModule_AddIntConstant(m, "BTPROTO_HCI", BTPROTO_HCI); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4646 PyModule_AddIntConstant(m, "SOL_HCI", SOL_HCI); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4647 PyModule_AddIntConstant(m, "HCI_FILTER", HCI_FILTER); |
|
41946
c36ac67eef5b
Fix build on FreeBSD. Bluetooth HCI API in FreeBSD is quite different
Hye-Shik Chang <hyeshik@gmail.com>
parents:
41341
diff
changeset
|
4648 #if !defined(__FreeBSD__) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4649 PyModule_AddIntConstant(m, "HCI_TIME_STAMP", HCI_TIME_STAMP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4650 PyModule_AddIntConstant(m, "HCI_DATA_DIR", HCI_DATA_DIR); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4651 PyModule_AddIntConstant(m, "BTPROTO_SCO", BTPROTO_SCO); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4652 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4653 PyModule_AddIntConstant(m, "BTPROTO_RFCOMM", BTPROTO_RFCOMM); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4654 PyModule_AddStringConstant(m, "BDADDR_ANY", "00:00:00:00:00:00"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4655 PyModule_AddStringConstant(m, "BDADDR_LOCAL", "00:00:00:FF:FF:FF"); |
|
31441
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
4656 #endif |
|
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
4657 |
|
19151
cd44254360b6
Autotest for netpacket/packet.h, as it is not available on all Linux versions.
Martin v. Löwis <martin@v.loewis.de>
parents:
18997
diff
changeset
|
4658 #ifdef HAVE_NETPACKET_PACKET_H |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4659 PyModule_AddIntConstant(m, "AF_PACKET", AF_PACKET); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4660 PyModule_AddIntConstant(m, "PF_PACKET", PF_PACKET); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4661 PyModule_AddIntConstant(m, "PACKET_HOST", PACKET_HOST); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4662 PyModule_AddIntConstant(m, "PACKET_BROADCAST", PACKET_BROADCAST); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4663 PyModule_AddIntConstant(m, "PACKET_MULTICAST", PACKET_MULTICAST); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4664 PyModule_AddIntConstant(m, "PACKET_OTHERHOST", PACKET_OTHERHOST); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4665 PyModule_AddIntConstant(m, "PACKET_OUTGOING", PACKET_OUTGOING); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4666 PyModule_AddIntConstant(m, "PACKET_LOOPBACK", PACKET_LOOPBACK); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4667 PyModule_AddIntConstant(m, "PACKET_FASTROUTE", PACKET_FASTROUTE); |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
4668 #endif |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4669 |
|
44561
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44474
diff
changeset
|
4670 #ifdef HAVE_LINUX_TIPC_H |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4671 PyModule_AddIntConstant(m, "AF_TIPC", AF_TIPC); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4672 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4673 /* for addresses */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4674 PyModule_AddIntConstant(m, "TIPC_ADDR_NAMESEQ", TIPC_ADDR_NAMESEQ); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4675 PyModule_AddIntConstant(m, "TIPC_ADDR_NAME", TIPC_ADDR_NAME); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4676 PyModule_AddIntConstant(m, "TIPC_ADDR_ID", TIPC_ADDR_ID); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4677 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4678 PyModule_AddIntConstant(m, "TIPC_ZONE_SCOPE", TIPC_ZONE_SCOPE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4679 PyModule_AddIntConstant(m, "TIPC_CLUSTER_SCOPE", TIPC_CLUSTER_SCOPE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4680 PyModule_AddIntConstant(m, "TIPC_NODE_SCOPE", TIPC_NODE_SCOPE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4681 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4682 /* for setsockopt() */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4683 PyModule_AddIntConstant(m, "SOL_TIPC", SOL_TIPC); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4684 PyModule_AddIntConstant(m, "TIPC_IMPORTANCE", TIPC_IMPORTANCE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4685 PyModule_AddIntConstant(m, "TIPC_SRC_DROPPABLE", TIPC_SRC_DROPPABLE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4686 PyModule_AddIntConstant(m, "TIPC_DEST_DROPPABLE", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4687 TIPC_DEST_DROPPABLE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4688 PyModule_AddIntConstant(m, "TIPC_CONN_TIMEOUT", TIPC_CONN_TIMEOUT); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4689 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4690 PyModule_AddIntConstant(m, "TIPC_LOW_IMPORTANCE", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4691 TIPC_LOW_IMPORTANCE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4692 PyModule_AddIntConstant(m, "TIPC_MEDIUM_IMPORTANCE", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4693 TIPC_MEDIUM_IMPORTANCE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4694 PyModule_AddIntConstant(m, "TIPC_HIGH_IMPORTANCE", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4695 TIPC_HIGH_IMPORTANCE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4696 PyModule_AddIntConstant(m, "TIPC_CRITICAL_IMPORTANCE", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4697 TIPC_CRITICAL_IMPORTANCE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4698 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4699 /* for subscriptions */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4700 PyModule_AddIntConstant(m, "TIPC_SUB_PORTS", TIPC_SUB_PORTS); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4701 PyModule_AddIntConstant(m, "TIPC_SUB_SERVICE", TIPC_SUB_SERVICE); |
|
44636
2ad3e35c5825
Guard definition of TIPC_SUB_CANCEL with an #ifdef.
Georg Brandl <georg@python.org>
parents:
44630
diff
changeset
|
4702 #ifdef TIPC_SUB_CANCEL |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4703 /* doesn't seem to be available everywhere */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4704 PyModule_AddIntConstant(m, "TIPC_SUB_CANCEL", TIPC_SUB_CANCEL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4705 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4706 PyModule_AddIntConstant(m, "TIPC_WAIT_FOREVER", TIPC_WAIT_FOREVER); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4707 PyModule_AddIntConstant(m, "TIPC_PUBLISHED", TIPC_PUBLISHED); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4708 PyModule_AddIntConstant(m, "TIPC_WITHDRAWN", TIPC_WITHDRAWN); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4709 PyModule_AddIntConstant(m, "TIPC_SUBSCR_TIMEOUT", TIPC_SUBSCR_TIMEOUT); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4710 PyModule_AddIntConstant(m, "TIPC_CFG_SRV", TIPC_CFG_SRV); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4711 PyModule_AddIntConstant(m, "TIPC_TOP_SRV", TIPC_TOP_SRV); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4712 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4713 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4714 /* Socket types */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4715 PyModule_AddIntConstant(m, "SOCK_STREAM", SOCK_STREAM); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4716 PyModule_AddIntConstant(m, "SOCK_DGRAM", SOCK_DGRAM); |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
4717 #ifndef __BEOS__ |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
4718 /* We have incomplete socket support. */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4719 PyModule_AddIntConstant(m, "SOCK_RAW", SOCK_RAW); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4720 PyModule_AddIntConstant(m, "SOCK_SEQPACKET", SOCK_SEQPACKET); |
|
26597
7ddea4dfa519
Patch #650422: Use Posix AF_ constants instead of PF_ ones.
Martin v. Löwis <martin@v.loewis.de>
parents:
26551
diff
changeset
|
4721 #if defined(SOCK_RDM) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4722 PyModule_AddIntConstant(m, "SOCK_RDM", SOCK_RDM); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4723 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4724 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4725 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4726 #ifdef SO_DEBUG |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4727 PyModule_AddIntConstant(m, "SO_DEBUG", SO_DEBUG); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4728 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4729 #ifdef SO_ACCEPTCONN |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4730 PyModule_AddIntConstant(m, "SO_ACCEPTCONN", SO_ACCEPTCONN); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4731 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4732 #ifdef SO_REUSEADDR |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4733 PyModule_AddIntConstant(m, "SO_REUSEADDR", SO_REUSEADDR); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4734 #endif |
|
32578
21fd6e62cd27
[Patch #982665 ] add SO_EXCLUSIVEADDRUSE constant
Andrew M. Kuchling <amk@amk.ca>
parents:
32521
diff
changeset
|
4735 #ifdef SO_EXCLUSIVEADDRUSE |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4736 PyModule_AddIntConstant(m, "SO_EXCLUSIVEADDRUSE", SO_EXCLUSIVEADDRUSE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4737 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4738 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4739 #ifdef SO_KEEPALIVE |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4740 PyModule_AddIntConstant(m, "SO_KEEPALIVE", SO_KEEPALIVE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4741 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4742 #ifdef SO_DONTROUTE |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4743 PyModule_AddIntConstant(m, "SO_DONTROUTE", SO_DONTROUTE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4744 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4745 #ifdef SO_BROADCAST |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4746 PyModule_AddIntConstant(m, "SO_BROADCAST", SO_BROADCAST); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4747 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4748 #ifdef SO_USELOOPBACK |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4749 PyModule_AddIntConstant(m, "SO_USELOOPBACK", SO_USELOOPBACK); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4750 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4751 #ifdef SO_LINGER |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4752 PyModule_AddIntConstant(m, "SO_LINGER", SO_LINGER); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4753 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4754 #ifdef SO_OOBINLINE |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4755 PyModule_AddIntConstant(m, "SO_OOBINLINE", SO_OOBINLINE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4756 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4757 #ifdef SO_REUSEPORT |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4758 PyModule_AddIntConstant(m, "SO_REUSEPORT", SO_REUSEPORT); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4759 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4760 #ifdef SO_SNDBUF |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4761 PyModule_AddIntConstant(m, "SO_SNDBUF", SO_SNDBUF); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4762 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4763 #ifdef SO_RCVBUF |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4764 PyModule_AddIntConstant(m, "SO_RCVBUF", SO_RCVBUF); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4765 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4766 #ifdef SO_SNDLOWAT |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4767 PyModule_AddIntConstant(m, "SO_SNDLOWAT", SO_SNDLOWAT); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4768 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4769 #ifdef SO_RCVLOWAT |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4770 PyModule_AddIntConstant(m, "SO_RCVLOWAT", SO_RCVLOWAT); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4771 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4772 #ifdef SO_SNDTIMEO |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4773 PyModule_AddIntConstant(m, "SO_SNDTIMEO", SO_SNDTIMEO); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4774 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4775 #ifdef SO_RCVTIMEO |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4776 PyModule_AddIntConstant(m, "SO_RCVTIMEO", SO_RCVTIMEO); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4777 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4778 #ifdef SO_ERROR |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4779 PyModule_AddIntConstant(m, "SO_ERROR", SO_ERROR); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4780 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4781 #ifdef SO_TYPE |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4782 PyModule_AddIntConstant(m, "SO_TYPE", SO_TYPE); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4783 #endif |
|
60159
1df34fa491bd
Issue #8235: _socket: Add the constant ``SO_SETFIB``. SO_SETFIB is
Larry Hastings <larry@hastings.org>
parents:
59998
diff
changeset
|
4784 #ifdef SO_SETFIB |
|
1df34fa491bd
Issue #8235: _socket: Add the constant ``SO_SETFIB``. SO_SETFIB is
Larry Hastings <larry@hastings.org>
parents:
59998
diff
changeset
|
4785 PyModule_AddIntConstant(m, "SO_SETFIB", SO_SETFIB); |
|
1df34fa491bd
Issue #8235: _socket: Add the constant ``SO_SETFIB``. SO_SETFIB is
Larry Hastings <larry@hastings.org>
parents:
59998
diff
changeset
|
4786 #endif |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4787 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4788 /* Maximum number of connections for "listen" */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4789 #ifdef SOMAXCONN |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4790 PyModule_AddIntConstant(m, "SOMAXCONN", SOMAXCONN); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4791 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4792 PyModule_AddIntConstant(m, "SOMAXCONN", 5); /* Common value */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4793 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4794 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4795 /* Flags for send, recv */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4796 #ifdef MSG_OOB |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4797 PyModule_AddIntConstant(m, "MSG_OOB", MSG_OOB); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4798 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4799 #ifdef MSG_PEEK |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4800 PyModule_AddIntConstant(m, "MSG_PEEK", MSG_PEEK); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4801 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4802 #ifdef MSG_DONTROUTE |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4803 PyModule_AddIntConstant(m, "MSG_DONTROUTE", MSG_DONTROUTE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4804 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4805 #ifdef MSG_DONTWAIT |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4806 PyModule_AddIntConstant(m, "MSG_DONTWAIT", MSG_DONTWAIT); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4807 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4808 #ifdef MSG_EOR |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4809 PyModule_AddIntConstant(m, "MSG_EOR", MSG_EOR); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4810 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4811 #ifdef MSG_TRUNC |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4812 PyModule_AddIntConstant(m, "MSG_TRUNC", MSG_TRUNC); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4813 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4814 #ifdef MSG_CTRUNC |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4815 PyModule_AddIntConstant(m, "MSG_CTRUNC", MSG_CTRUNC); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4816 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4817 #ifdef MSG_WAITALL |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4818 PyModule_AddIntConstant(m, "MSG_WAITALL", MSG_WAITALL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4819 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4820 #ifdef MSG_BTAG |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4821 PyModule_AddIntConstant(m, "MSG_BTAG", MSG_BTAG); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4822 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4823 #ifdef MSG_ETAG |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4824 PyModule_AddIntConstant(m, "MSG_ETAG", MSG_ETAG); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4825 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4826 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4827 /* Protocol level and numbers, usable for [gs]etsockopt */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4828 #ifdef SOL_SOCKET |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4829 PyModule_AddIntConstant(m, "SOL_SOCKET", SOL_SOCKET); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4830 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4831 #ifdef SOL_IP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4832 PyModule_AddIntConstant(m, "SOL_IP", SOL_IP); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4833 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4834 PyModule_AddIntConstant(m, "SOL_IP", 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4835 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4836 #ifdef SOL_IPX |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4837 PyModule_AddIntConstant(m, "SOL_IPX", SOL_IPX); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4838 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4839 #ifdef SOL_AX25 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4840 PyModule_AddIntConstant(m, "SOL_AX25", SOL_AX25); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4841 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4842 #ifdef SOL_ATALK |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4843 PyModule_AddIntConstant(m, "SOL_ATALK", SOL_ATALK); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4844 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4845 #ifdef SOL_NETROM |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4846 PyModule_AddIntConstant(m, "SOL_NETROM", SOL_NETROM); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4847 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4848 #ifdef SOL_ROSE |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4849 PyModule_AddIntConstant(m, "SOL_ROSE", SOL_ROSE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4850 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4851 #ifdef SOL_TCP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4852 PyModule_AddIntConstant(m, "SOL_TCP", SOL_TCP); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4853 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4854 PyModule_AddIntConstant(m, "SOL_TCP", 6); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4855 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4856 #ifdef SOL_UDP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4857 PyModule_AddIntConstant(m, "SOL_UDP", SOL_UDP); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4858 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4859 PyModule_AddIntConstant(m, "SOL_UDP", 17); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4860 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4861 #ifdef IPPROTO_IP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4862 PyModule_AddIntConstant(m, "IPPROTO_IP", IPPROTO_IP); |
|
8439
534602746079
Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents:
7942
diff
changeset
|
4863 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4864 PyModule_AddIntConstant(m, "IPPROTO_IP", 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4865 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4866 #ifdef IPPROTO_HOPOPTS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4867 PyModule_AddIntConstant(m, "IPPROTO_HOPOPTS", IPPROTO_HOPOPTS); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4868 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4869 #ifdef IPPROTO_ICMP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4870 PyModule_AddIntConstant(m, "IPPROTO_ICMP", IPPROTO_ICMP); |
|
8439
534602746079
Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents:
7942
diff
changeset
|
4871 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4872 PyModule_AddIntConstant(m, "IPPROTO_ICMP", 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4873 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4874 #ifdef IPPROTO_IGMP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4875 PyModule_AddIntConstant(m, "IPPROTO_IGMP", IPPROTO_IGMP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4876 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4877 #ifdef IPPROTO_GGP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4878 PyModule_AddIntConstant(m, "IPPROTO_GGP", IPPROTO_GGP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4879 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4880 #ifdef IPPROTO_IPV4 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4881 PyModule_AddIntConstant(m, "IPPROTO_IPV4", IPPROTO_IPV4); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4882 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4883 #ifdef IPPROTO_IPV6 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4884 PyModule_AddIntConstant(m, "IPPROTO_IPV6", IPPROTO_IPV6); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4885 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4886 #ifdef IPPROTO_IPIP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4887 PyModule_AddIntConstant(m, "IPPROTO_IPIP", IPPROTO_IPIP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4888 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4889 #ifdef IPPROTO_TCP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4890 PyModule_AddIntConstant(m, "IPPROTO_TCP", IPPROTO_TCP); |
|
8439
534602746079
Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents:
7942
diff
changeset
|
4891 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4892 PyModule_AddIntConstant(m, "IPPROTO_TCP", 6); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4893 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4894 #ifdef IPPROTO_EGP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4895 PyModule_AddIntConstant(m, "IPPROTO_EGP", IPPROTO_EGP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4896 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4897 #ifdef IPPROTO_PUP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4898 PyModule_AddIntConstant(m, "IPPROTO_PUP", IPPROTO_PUP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4899 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4900 #ifdef IPPROTO_UDP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4901 PyModule_AddIntConstant(m, "IPPROTO_UDP", IPPROTO_UDP); |
|
8439
534602746079
Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents:
7942
diff
changeset
|
4902 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4903 PyModule_AddIntConstant(m, "IPPROTO_UDP", 17); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4904 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4905 #ifdef IPPROTO_IDP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4906 PyModule_AddIntConstant(m, "IPPROTO_IDP", IPPROTO_IDP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4907 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4908 #ifdef IPPROTO_HELLO |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4909 PyModule_AddIntConstant(m, "IPPROTO_HELLO", IPPROTO_HELLO); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4910 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4911 #ifdef IPPROTO_ND |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4912 PyModule_AddIntConstant(m, "IPPROTO_ND", IPPROTO_ND); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4913 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4914 #ifdef IPPROTO_TP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4915 PyModule_AddIntConstant(m, "IPPROTO_TP", IPPROTO_TP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4916 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4917 #ifdef IPPROTO_IPV6 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4918 PyModule_AddIntConstant(m, "IPPROTO_IPV6", IPPROTO_IPV6); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4919 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4920 #ifdef IPPROTO_ROUTING |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4921 PyModule_AddIntConstant(m, "IPPROTO_ROUTING", IPPROTO_ROUTING); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4922 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4923 #ifdef IPPROTO_FRAGMENT |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4924 PyModule_AddIntConstant(m, "IPPROTO_FRAGMENT", IPPROTO_FRAGMENT); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4925 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4926 #ifdef IPPROTO_RSVP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4927 PyModule_AddIntConstant(m, "IPPROTO_RSVP", IPPROTO_RSVP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4928 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4929 #ifdef IPPROTO_GRE |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4930 PyModule_AddIntConstant(m, "IPPROTO_GRE", IPPROTO_GRE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4931 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4932 #ifdef IPPROTO_ESP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4933 PyModule_AddIntConstant(m, "IPPROTO_ESP", IPPROTO_ESP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4934 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4935 #ifdef IPPROTO_AH |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4936 PyModule_AddIntConstant(m, "IPPROTO_AH", IPPROTO_AH); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4937 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4938 #ifdef IPPROTO_MOBILE |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4939 PyModule_AddIntConstant(m, "IPPROTO_MOBILE", IPPROTO_MOBILE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4940 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4941 #ifdef IPPROTO_ICMPV6 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4942 PyModule_AddIntConstant(m, "IPPROTO_ICMPV6", IPPROTO_ICMPV6); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4943 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4944 #ifdef IPPROTO_NONE |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4945 PyModule_AddIntConstant(m, "IPPROTO_NONE", IPPROTO_NONE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4946 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4947 #ifdef IPPROTO_DSTOPTS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4948 PyModule_AddIntConstant(m, "IPPROTO_DSTOPTS", IPPROTO_DSTOPTS); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4949 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4950 #ifdef IPPROTO_XTP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4951 PyModule_AddIntConstant(m, "IPPROTO_XTP", IPPROTO_XTP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4952 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4953 #ifdef IPPROTO_EON |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4954 PyModule_AddIntConstant(m, "IPPROTO_EON", IPPROTO_EON); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4955 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4956 #ifdef IPPROTO_PIM |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4957 PyModule_AddIntConstant(m, "IPPROTO_PIM", IPPROTO_PIM); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4958 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4959 #ifdef IPPROTO_IPCOMP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4960 PyModule_AddIntConstant(m, "IPPROTO_IPCOMP", IPPROTO_IPCOMP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4961 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4962 #ifdef IPPROTO_VRRP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4963 PyModule_AddIntConstant(m, "IPPROTO_VRRP", IPPROTO_VRRP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4964 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4965 #ifdef IPPROTO_BIP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4966 PyModule_AddIntConstant(m, "IPPROTO_BIP", IPPROTO_BIP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4967 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4968 /**/ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4969 #ifdef IPPROTO_RAW |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4970 PyModule_AddIntConstant(m, "IPPROTO_RAW", IPPROTO_RAW); |
|
8439
534602746079
Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents:
7942
diff
changeset
|
4971 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4972 PyModule_AddIntConstant(m, "IPPROTO_RAW", 255); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4973 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4974 #ifdef IPPROTO_MAX |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4975 PyModule_AddIntConstant(m, "IPPROTO_MAX", IPPROTO_MAX); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4976 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4977 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4978 /* Some port configuration */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4979 #ifdef IPPORT_RESERVED |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4980 PyModule_AddIntConstant(m, "IPPORT_RESERVED", IPPORT_RESERVED); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4981 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4982 PyModule_AddIntConstant(m, "IPPORT_RESERVED", 1024); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4983 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4984 #ifdef IPPORT_USERRESERVED |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4985 PyModule_AddIntConstant(m, "IPPORT_USERRESERVED", IPPORT_USERRESERVED); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4986 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4987 PyModule_AddIntConstant(m, "IPPORT_USERRESERVED", 5000); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4988 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4989 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4990 /* Some reserved IP v.4 addresses */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4991 #ifdef INADDR_ANY |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4992 PyModule_AddIntConstant(m, "INADDR_ANY", INADDR_ANY); |
| 2369 | 4993 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4994 PyModule_AddIntConstant(m, "INADDR_ANY", 0x00000000); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4995 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4996 #ifdef INADDR_BROADCAST |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4997 PyModule_AddIntConstant(m, "INADDR_BROADCAST", INADDR_BROADCAST); |
| 2369 | 4998 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
4999 PyModule_AddIntConstant(m, "INADDR_BROADCAST", 0xffffffff); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5000 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5001 #ifdef INADDR_LOOPBACK |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5002 PyModule_AddIntConstant(m, "INADDR_LOOPBACK", INADDR_LOOPBACK); |
| 2369 | 5003 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5004 PyModule_AddIntConstant(m, "INADDR_LOOPBACK", 0x7F000001); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5005 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5006 #ifdef INADDR_UNSPEC_GROUP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5007 PyModule_AddIntConstant(m, "INADDR_UNSPEC_GROUP", INADDR_UNSPEC_GROUP); |
| 2369 | 5008 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5009 PyModule_AddIntConstant(m, "INADDR_UNSPEC_GROUP", 0xe0000000); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5010 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5011 #ifdef INADDR_ALLHOSTS_GROUP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5012 PyModule_AddIntConstant(m, "INADDR_ALLHOSTS_GROUP", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5013 INADDR_ALLHOSTS_GROUP); |
| 2369 | 5014 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5015 PyModule_AddIntConstant(m, "INADDR_ALLHOSTS_GROUP", 0xe0000001); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5016 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5017 #ifdef INADDR_MAX_LOCAL_GROUP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5018 PyModule_AddIntConstant(m, "INADDR_MAX_LOCAL_GROUP", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5019 INADDR_MAX_LOCAL_GROUP); |
| 2369 | 5020 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5021 PyModule_AddIntConstant(m, "INADDR_MAX_LOCAL_GROUP", 0xe00000ff); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5022 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5023 #ifdef INADDR_NONE |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5024 PyModule_AddIntConstant(m, "INADDR_NONE", INADDR_NONE); |
| 2369 | 5025 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5026 PyModule_AddIntConstant(m, "INADDR_NONE", 0xffffffff); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5027 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5028 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5029 /* IPv4 [gs]etsockopt options */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5030 #ifdef IP_OPTIONS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5031 PyModule_AddIntConstant(m, "IP_OPTIONS", IP_OPTIONS); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5032 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5033 #ifdef IP_HDRINCL |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5034 PyModule_AddIntConstant(m, "IP_HDRINCL", IP_HDRINCL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5035 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5036 #ifdef IP_TOS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5037 PyModule_AddIntConstant(m, "IP_TOS", IP_TOS); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5038 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5039 #ifdef IP_TTL |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5040 PyModule_AddIntConstant(m, "IP_TTL", IP_TTL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5041 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5042 #ifdef IP_RECVOPTS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5043 PyModule_AddIntConstant(m, "IP_RECVOPTS", IP_RECVOPTS); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5044 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5045 #ifdef IP_RECVRETOPTS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5046 PyModule_AddIntConstant(m, "IP_RECVRETOPTS", IP_RECVRETOPTS); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5047 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5048 #ifdef IP_RECVDSTADDR |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5049 PyModule_AddIntConstant(m, "IP_RECVDSTADDR", IP_RECVDSTADDR); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5050 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5051 #ifdef IP_RETOPTS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5052 PyModule_AddIntConstant(m, "IP_RETOPTS", IP_RETOPTS); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5053 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5054 #ifdef IP_MULTICAST_IF |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5055 PyModule_AddIntConstant(m, "IP_MULTICAST_IF", IP_MULTICAST_IF); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5056 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5057 #ifdef IP_MULTICAST_TTL |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5058 PyModule_AddIntConstant(m, "IP_MULTICAST_TTL", IP_MULTICAST_TTL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5059 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5060 #ifdef IP_MULTICAST_LOOP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5061 PyModule_AddIntConstant(m, "IP_MULTICAST_LOOP", IP_MULTICAST_LOOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5062 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5063 #ifdef IP_ADD_MEMBERSHIP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5064 PyModule_AddIntConstant(m, "IP_ADD_MEMBERSHIP", IP_ADD_MEMBERSHIP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5065 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5066 #ifdef IP_DROP_MEMBERSHIP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5067 PyModule_AddIntConstant(m, "IP_DROP_MEMBERSHIP", IP_DROP_MEMBERSHIP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5068 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5069 #ifdef IP_DEFAULT_MULTICAST_TTL |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5070 PyModule_AddIntConstant(m, "IP_DEFAULT_MULTICAST_TTL", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5071 IP_DEFAULT_MULTICAST_TTL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5072 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5073 #ifdef IP_DEFAULT_MULTICAST_LOOP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5074 PyModule_AddIntConstant(m, "IP_DEFAULT_MULTICAST_LOOP", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5075 IP_DEFAULT_MULTICAST_LOOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5076 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5077 #ifdef IP_MAX_MEMBERSHIPS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5078 PyModule_AddIntConstant(m, "IP_MAX_MEMBERSHIPS", IP_MAX_MEMBERSHIPS); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5079 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5080 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5081 /* IPv6 [gs]etsockopt options, defined in RFC2553 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5082 #ifdef IPV6_JOIN_GROUP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5083 PyModule_AddIntConstant(m, "IPV6_JOIN_GROUP", IPV6_JOIN_GROUP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5084 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5085 #ifdef IPV6_LEAVE_GROUP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5086 PyModule_AddIntConstant(m, "IPV6_LEAVE_GROUP", IPV6_LEAVE_GROUP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5087 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5088 #ifdef IPV6_MULTICAST_HOPS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5089 PyModule_AddIntConstant(m, "IPV6_MULTICAST_HOPS", IPV6_MULTICAST_HOPS); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5090 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5091 #ifdef IPV6_MULTICAST_IF |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5092 PyModule_AddIntConstant(m, "IPV6_MULTICAST_IF", IPV6_MULTICAST_IF); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5093 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5094 #ifdef IPV6_MULTICAST_LOOP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5095 PyModule_AddIntConstant(m, "IPV6_MULTICAST_LOOP", IPV6_MULTICAST_LOOP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5096 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5097 #ifdef IPV6_UNICAST_HOPS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5098 PyModule_AddIntConstant(m, "IPV6_UNICAST_HOPS", IPV6_UNICAST_HOPS); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5099 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5100 /* Additional IPV6 socket options, defined in RFC 3493 */ |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5101 #ifdef IPV6_V6ONLY |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5102 PyModule_AddIntConstant(m, "IPV6_V6ONLY", IPV6_V6ONLY); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5103 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5104 /* Advanced IPV6 socket options, from RFC 3542 */ |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5105 #ifdef IPV6_CHECKSUM |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5106 PyModule_AddIntConstant(m, "IPV6_CHECKSUM", IPV6_CHECKSUM); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5107 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5108 #ifdef IPV6_DONTFRAG |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5109 PyModule_AddIntConstant(m, "IPV6_DONTFRAG", IPV6_DONTFRAG); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5110 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5111 #ifdef IPV6_DSTOPTS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5112 PyModule_AddIntConstant(m, "IPV6_DSTOPTS", IPV6_DSTOPTS); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5113 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5114 #ifdef IPV6_HOPLIMIT |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5115 PyModule_AddIntConstant(m, "IPV6_HOPLIMIT", IPV6_HOPLIMIT); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5116 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5117 #ifdef IPV6_HOPOPTS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5118 PyModule_AddIntConstant(m, "IPV6_HOPOPTS", IPV6_HOPOPTS); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5119 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5120 #ifdef IPV6_NEXTHOP |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5121 PyModule_AddIntConstant(m, "IPV6_NEXTHOP", IPV6_NEXTHOP); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5122 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5123 #ifdef IPV6_PATHMTU |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5124 PyModule_AddIntConstant(m, "IPV6_PATHMTU", IPV6_PATHMTU); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5125 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5126 #ifdef IPV6_PKTINFO |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5127 PyModule_AddIntConstant(m, "IPV6_PKTINFO", IPV6_PKTINFO); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5128 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5129 #ifdef IPV6_RECVDSTOPTS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5130 PyModule_AddIntConstant(m, "IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5131 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5132 #ifdef IPV6_RECVHOPLIMIT |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5133 PyModule_AddIntConstant(m, "IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5134 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5135 #ifdef IPV6_RECVHOPOPTS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5136 PyModule_AddIntConstant(m, "IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5137 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5138 #ifdef IPV6_RECVPKTINFO |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5139 PyModule_AddIntConstant(m, "IPV6_RECVPKTINFO", IPV6_RECVPKTINFO); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5140 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5141 #ifdef IPV6_RECVRTHDR |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5142 PyModule_AddIntConstant(m, "IPV6_RECVRTHDR", IPV6_RECVRTHDR); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5143 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5144 #ifdef IPV6_RECVTCLASS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5145 PyModule_AddIntConstant(m, "IPV6_RECVTCLASS", IPV6_RECVTCLASS); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5146 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5147 #ifdef IPV6_RTHDR |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5148 PyModule_AddIntConstant(m, "IPV6_RTHDR", IPV6_RTHDR); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5149 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5150 #ifdef IPV6_RTHDRDSTOPTS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5151 PyModule_AddIntConstant(m, "IPV6_RTHDRDSTOPTS", IPV6_RTHDRDSTOPTS); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5152 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5153 #ifdef IPV6_RTHDR_TYPE_0 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5154 PyModule_AddIntConstant(m, "IPV6_RTHDR_TYPE_0", IPV6_RTHDR_TYPE_0); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5155 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5156 #ifdef IPV6_RECVPATHMTU |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5157 PyModule_AddIntConstant(m, "IPV6_RECVPATHMTU", IPV6_RECVPATHMTU); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5158 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5159 #ifdef IPV6_TCLASS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5160 PyModule_AddIntConstant(m, "IPV6_TCLASS", IPV6_TCLASS); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5161 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5162 #ifdef IPV6_USE_MIN_MTU |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5163 PyModule_AddIntConstant(m, "IPV6_USE_MIN_MTU", IPV6_USE_MIN_MTU); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5164 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5165 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5166 /* TCP options */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5167 #ifdef TCP_NODELAY |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5168 PyModule_AddIntConstant(m, "TCP_NODELAY", TCP_NODELAY); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5169 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5170 #ifdef TCP_MAXSEG |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5171 PyModule_AddIntConstant(m, "TCP_MAXSEG", TCP_MAXSEG); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5172 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5173 #ifdef TCP_CORK |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5174 PyModule_AddIntConstant(m, "TCP_CORK", TCP_CORK); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5175 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5176 #ifdef TCP_KEEPIDLE |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5177 PyModule_AddIntConstant(m, "TCP_KEEPIDLE", TCP_KEEPIDLE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5178 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5179 #ifdef TCP_KEEPINTVL |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5180 PyModule_AddIntConstant(m, "TCP_KEEPINTVL", TCP_KEEPINTVL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5181 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5182 #ifdef TCP_KEEPCNT |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5183 PyModule_AddIntConstant(m, "TCP_KEEPCNT", TCP_KEEPCNT); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5184 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5185 #ifdef TCP_SYNCNT |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5186 PyModule_AddIntConstant(m, "TCP_SYNCNT", TCP_SYNCNT); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5187 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5188 #ifdef TCP_LINGER2 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5189 PyModule_AddIntConstant(m, "TCP_LINGER2", TCP_LINGER2); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5190 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5191 #ifdef TCP_DEFER_ACCEPT |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5192 PyModule_AddIntConstant(m, "TCP_DEFER_ACCEPT", TCP_DEFER_ACCEPT); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5193 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5194 #ifdef TCP_WINDOW_CLAMP |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5195 PyModule_AddIntConstant(m, "TCP_WINDOW_CLAMP", TCP_WINDOW_CLAMP); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5196 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5197 #ifdef TCP_INFO |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5198 PyModule_AddIntConstant(m, "TCP_INFO", TCP_INFO); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5199 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5200 #ifdef TCP_QUICKACK |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5201 PyModule_AddIntConstant(m, "TCP_QUICKACK", TCP_QUICKACK); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5202 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5203 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5204 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5205 /* IPX options */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5206 #ifdef IPX_TYPE |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5207 PyModule_AddIntConstant(m, "IPX_TYPE", IPX_TYPE); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5208 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5209 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5210 /* get{addr,name}info parameters */ |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5211 #ifdef EAI_ADDRFAMILY |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5212 PyModule_AddIntConstant(m, "EAI_ADDRFAMILY", EAI_ADDRFAMILY); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5213 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5214 #ifdef EAI_AGAIN |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5215 PyModule_AddIntConstant(m, "EAI_AGAIN", EAI_AGAIN); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5216 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5217 #ifdef EAI_BADFLAGS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5218 PyModule_AddIntConstant(m, "EAI_BADFLAGS", EAI_BADFLAGS); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5219 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5220 #ifdef EAI_FAIL |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5221 PyModule_AddIntConstant(m, "EAI_FAIL", EAI_FAIL); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5222 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5223 #ifdef EAI_FAMILY |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5224 PyModule_AddIntConstant(m, "EAI_FAMILY", EAI_FAMILY); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5225 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5226 #ifdef EAI_MEMORY |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5227 PyModule_AddIntConstant(m, "EAI_MEMORY", EAI_MEMORY); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5228 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5229 #ifdef EAI_NODATA |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5230 PyModule_AddIntConstant(m, "EAI_NODATA", EAI_NODATA); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5231 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5232 #ifdef EAI_NONAME |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5233 PyModule_AddIntConstant(m, "EAI_NONAME", EAI_NONAME); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5234 #endif |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5235 #ifdef EAI_OVERFLOW |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5236 PyModule_AddIntConstant(m, "EAI_OVERFLOW", EAI_OVERFLOW); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5237 #endif |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5238 #ifdef EAI_SERVICE |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5239 PyModule_AddIntConstant(m, "EAI_SERVICE", EAI_SERVICE); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5240 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5241 #ifdef EAI_SOCKTYPE |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5242 PyModule_AddIntConstant(m, "EAI_SOCKTYPE", EAI_SOCKTYPE); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5243 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5244 #ifdef EAI_SYSTEM |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5245 PyModule_AddIntConstant(m, "EAI_SYSTEM", EAI_SYSTEM); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5246 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5247 #ifdef EAI_BADHINTS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5248 PyModule_AddIntConstant(m, "EAI_BADHINTS", EAI_BADHINTS); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5249 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5250 #ifdef EAI_PROTOCOL |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5251 PyModule_AddIntConstant(m, "EAI_PROTOCOL", EAI_PROTOCOL); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5252 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5253 #ifdef EAI_MAX |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5254 PyModule_AddIntConstant(m, "EAI_MAX", EAI_MAX); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5255 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5256 #ifdef AI_PASSIVE |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5257 PyModule_AddIntConstant(m, "AI_PASSIVE", AI_PASSIVE); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5258 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5259 #ifdef AI_CANONNAME |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5260 PyModule_AddIntConstant(m, "AI_CANONNAME", AI_CANONNAME); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5261 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5262 #ifdef AI_NUMERICHOST |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5263 PyModule_AddIntConstant(m, "AI_NUMERICHOST", AI_NUMERICHOST); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5264 #endif |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5265 #ifdef AI_NUMERICSERV |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5266 PyModule_AddIntConstant(m, "AI_NUMERICSERV", AI_NUMERICSERV); |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
5267 #endif |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5268 #ifdef AI_MASK |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5269 PyModule_AddIntConstant(m, "AI_MASK", AI_MASK); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5270 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5271 #ifdef AI_ALL |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5272 PyModule_AddIntConstant(m, "AI_ALL", AI_ALL); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5273 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5274 #ifdef AI_V4MAPPED_CFG |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5275 PyModule_AddIntConstant(m, "AI_V4MAPPED_CFG", AI_V4MAPPED_CFG); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5276 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5277 #ifdef AI_ADDRCONFIG |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5278 PyModule_AddIntConstant(m, "AI_ADDRCONFIG", AI_ADDRCONFIG); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5279 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5280 #ifdef AI_V4MAPPED |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5281 PyModule_AddIntConstant(m, "AI_V4MAPPED", AI_V4MAPPED); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5282 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5283 #ifdef AI_DEFAULT |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5284 PyModule_AddIntConstant(m, "AI_DEFAULT", AI_DEFAULT); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5285 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5286 #ifdef NI_MAXHOST |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5287 PyModule_AddIntConstant(m, "NI_MAXHOST", NI_MAXHOST); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5288 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5289 #ifdef NI_MAXSERV |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5290 PyModule_AddIntConstant(m, "NI_MAXSERV", NI_MAXSERV); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5291 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5292 #ifdef NI_NOFQDN |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5293 PyModule_AddIntConstant(m, "NI_NOFQDN", NI_NOFQDN); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5294 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5295 #ifdef NI_NUMERICHOST |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5296 PyModule_AddIntConstant(m, "NI_NUMERICHOST", NI_NUMERICHOST); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5297 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5298 #ifdef NI_NAMEREQD |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5299 PyModule_AddIntConstant(m, "NI_NAMEREQD", NI_NAMEREQD); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5300 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5301 #ifdef NI_NUMERICSERV |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5302 PyModule_AddIntConstant(m, "NI_NUMERICSERV", NI_NUMERICSERV); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5303 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5304 #ifdef NI_DGRAM |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5305 PyModule_AddIntConstant(m, "NI_DGRAM", NI_DGRAM); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5306 #endif |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5307 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5308 /* shutdown() parameters */ |
|
31027
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5309 #ifdef SHUT_RD |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5310 PyModule_AddIntConstant(m, "SHUT_RD", SHUT_RD); |
|
31027
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5311 #elif defined(SD_RECEIVE) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5312 PyModule_AddIntConstant(m, "SHUT_RD", SD_RECEIVE); |
|
31027
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5313 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5314 PyModule_AddIntConstant(m, "SHUT_RD", 0); |
|
31027
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5315 #endif |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5316 #ifdef SHUT_WR |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5317 PyModule_AddIntConstant(m, "SHUT_WR", SHUT_WR); |
|
31027
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5318 #elif defined(SD_SEND) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5319 PyModule_AddIntConstant(m, "SHUT_WR", SD_SEND); |
|
31027
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5320 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5321 PyModule_AddIntConstant(m, "SHUT_WR", 1); |
|
31027
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5322 #endif |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5323 #ifdef SHUT_RDWR |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5324 PyModule_AddIntConstant(m, "SHUT_RDWR", SHUT_RDWR); |
|
31027
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5325 #elif defined(SD_BOTH) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5326 PyModule_AddIntConstant(m, "SHUT_RDWR", SD_BOTH); |
|
31027
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5327 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5328 PyModule_AddIntConstant(m, "SHUT_RDWR", 2); |
|
31027
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5329 #endif |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5330 |
|
44474
bfed70277ab3
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
5331 #ifdef SIO_RCVALL |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5332 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5333 DWORD codes[] = {SIO_RCVALL, SIO_KEEPALIVE_VALS}; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5334 const char *names[] = {"SIO_RCVALL", "SIO_KEEPALIVE_VALS"}; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5335 int i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5336 for(i = 0; i<sizeof(codes)/sizeof(*codes); ++i) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5337 PyObject *tmp; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5338 tmp = PyLong_FromUnsignedLong(codes[i]); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5339 if (tmp == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5340 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5341 PyModule_AddObject(m, names[i], tmp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5342 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5343 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5344 PyModule_AddIntConstant(m, "RCVALL_OFF", RCVALL_OFF); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5345 PyModule_AddIntConstant(m, "RCVALL_ON", RCVALL_ON); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5346 PyModule_AddIntConstant(m, "RCVALL_SOCKETLEVELONLY", RCVALL_SOCKETLEVELONLY); |
|
46173
c4ed664a1da1
Repair compilation for Visual Studio 2005.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45854
diff
changeset
|
5347 #ifdef RCVALL_IPLEVEL |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5348 PyModule_AddIntConstant(m, "RCVALL_IPLEVEL", RCVALL_IPLEVEL); |
|
46173
c4ed664a1da1
Repair compilation for Visual Studio 2005.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45854
diff
changeset
|
5349 #endif |
|
c4ed664a1da1
Repair compilation for Visual Studio 2005.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45854
diff
changeset
|
5350 #ifdef RCVALL_MAX |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5351 PyModule_AddIntConstant(m, "RCVALL_MAX", RCVALL_MAX); |
|
46173
c4ed664a1da1
Repair compilation for Visual Studio 2005.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45854
diff
changeset
|
5352 #endif |
|
44474
bfed70277ab3
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
5353 #endif /* _MSTCPIP_ */ |
|
bfed70277ab3
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
5354 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5355 /* Initialize gethostbyname lock */ |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
5356 #if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5357 netdb_lock = PyThread_allocate_lock(); |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
5358 #endif |
| 294 | 5359 } |
|
18262
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
5360 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
5361 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
5362 #ifndef HAVE_INET_PTON |
|
43972
a8dd8874ff2d
Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
43876
diff
changeset
|
5363 #if !defined(NTDDI_VERSION) || (NTDDI_VERSION < NTDDI_LONGHORN) |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
5364 |
|
18262
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
5365 /* Simplistic emulation code for inet_pton that only works for IPv4 */ |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
5366 /* These are not exposed because they do not set errno properly */ |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
5367 |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
5368 int |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
5369 inet_pton(int af, const char *src, void *dst) |
|
18262
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
5370 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5371 if (af == AF_INET) { |
|
51538
edcf996f07e9
Issue #1008086: Fixes socket.inet_aton() to always return 4 bytes even
Gregory P. Smith <greg@mad-scientist.com>
parents:
51220
diff
changeset
|
5372 #if (SIZEOF_INT != 4) |
|
edcf996f07e9
Issue #1008086: Fixes socket.inet_aton() to always return 4 bytes even
Gregory P. Smith <greg@mad-scientist.com>
parents:
51220
diff
changeset
|
5373 #error "Not sure if in_addr_t exists and int is not 32-bits." |
|
edcf996f07e9
Issue #1008086: Fixes socket.inet_aton() to always return 4 bytes even
Gregory P. Smith <greg@mad-scientist.com>
parents:
51220
diff
changeset
|
5374 #endif |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5375 unsigned int packed_addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5376 packed_addr = inet_addr(src); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5377 if (packed_addr == INADDR_NONE) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5378 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5379 memcpy(dst, &packed_addr, 4); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5380 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5381 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5382 /* Should set errno to EAFNOSUPPORT */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5383 return -1; |
|
18262
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
5384 } |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
5385 |
|
18790
7cd22bf56d7b
Silence warnings in MSVC++: hide unused variables, add constness back to
Martin v. Löwis <martin@v.loewis.de>
parents:
18753
diff
changeset
|
5386 const char * |
|
7cd22bf56d7b
Silence warnings in MSVC++: hide unused variables, add constness back to
Martin v. Löwis <martin@v.loewis.de>
parents:
18753
diff
changeset
|
5387 inet_ntop(int af, const void *src, char *dst, socklen_t size) |
|
18262
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
5388 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5389 if (af == AF_INET) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5390 struct in_addr packed_addr; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5391 if (size < 16) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5392 /* Should set errno to ENOSPC. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5393 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5394 memcpy(&packed_addr, src, sizeof(packed_addr)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5395 return strncpy(dst, inet_ntoa(packed_addr), size); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5396 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5397 /* Should set errno to EAFNOSUPPORT */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61201
diff
changeset
|
5398 return NULL; |
|
18262
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
5399 } |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
5400 |
|
18262
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
5401 #endif |
|
43972
a8dd8874ff2d
Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
43876
diff
changeset
|
5402 #endif |
