Mercurial > cpython-lru_cache-weakref
annotate Modules/socketmodule.c @ 7942:ee2aaa2f722a legacy-trunk
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 09 Apr 1998 20:56:35 +0000 |
| parents | 32f2eda2946c |
| children | 534602746079 |
| rev | line source |
|---|---|
| 294 | 1 /*********************************************************** |
|
2061
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
3 The Netherlands. |
| 294 | 4 |
| 5 All Rights Reserved | |
| 6 | |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
| 294 | 9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
| 294 | 11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
15 permission. |
| 294 | 16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4407
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
| 294 | 29 |
| 30 ******************************************************************/ | |
| 31 | |
| 32 /* Socket module */ | |
| 33 | |
| 34 /* | |
| 35 This module provides an interface to Berkeley socket IPC. | |
| 36 | |
| 37 Limitations: | |
| 38 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
39 - only AF_INET and AF_UNIX address families are supported |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
40 - no read/write operations (use send/recv or makefile instead) |
|
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
|
41 - additional restrictions apply on Windows |
| 294 | 42 |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
43 Module interface: |
| 294 | 44 |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
45 - socket.error: exception raised for socket specific errors |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
46 - 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
|
47 - 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
|
48 - 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
|
49 - socket.getprotobyname(protocolname) --> protocol number |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
50 - socket.getservbyname(servicename, protocolname) --> port number |
|
309
382323f92fce
Connection sockets now have the proper family/type/proto values.
Guido van Rossum <guido@python.org>
parents:
295
diff
changeset
|
51 - socket.socket(family, type [, proto]) --> new socket object |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
52 - 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
|
53 - 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
|
54 - 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
|
55 - socket.htonl(32 bit value) --> new int object |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
56 - socket.AF_INET, socket.SOCK_STREAM, etc.: constants from <socket.h> |
| 294 | 57 - an Internet socket address is a pair (hostname, port) |
| 58 where hostname can be anything recognized by gethostbyname() | |
| 59 (including the dd.dd.dd.dd notation) and port is in host byte order | |
| 60 - 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
|
61 - a UNIX domain socket address is a string specifying the pathname |
| 294 | 62 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
63 Socket methods: |
| 294 | 64 |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
65 - s.accept() --> new socket object, sockaddr |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
66 - s.bind(sockaddr) --> None |
|
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
67 - s.close() --> None |
|
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
68 - s.connect(sockaddr) --> None |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
69 - s.connect_ex(sockaddr) --> 0 or errno (handy for e.g. async connect) |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
70 - s.fileno() --> file descriptor |
|
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
|
71 - s.dup() --> same as socket.fromfd(os.dup(s.fileno(), ...) |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
72 - s.getpeername() --> sockaddr |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
73 - s.getsockname() --> sockaddr |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
74 - s.getsockopt(level, optname[, buflen]) --> int or string |
|
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
75 - s.listen(backlog) --> None |
|
2532
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
76 - s.makefile([mode[, bufsize]]) --> file object |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
77 - s.recv(buflen [,flags]) --> string |
|
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
78 - s.recvfrom(buflen [,flags]) --> string, sockaddr |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
79 - s.send(string [,flags]) --> nbytes |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
80 - s.sendto(string, [flags,] sockaddr) --> nbytes |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
81 - s.setblocking(0 | 1) --> None |
|
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
82 - s.setsockopt(level, optname, value) --> None |
|
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
83 - s.shutdown(how) --> None |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
84 - repr(s) --> "<socket object, fd=%d, family=%d, type=%d, protocol=%d>" |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
85 |
| 294 | 86 */ |
| 87 | |
| 1970 | 88 #include "Python.h" |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
89 #if defined(WITH_THREAD) && !defined(HAVE_GETHOSTBYNAME_R) && !defined(MS_WINDOWS) |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
90 #include "thread.h" |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
91 #endif |
| 294 | 92 |
| 4600 | 93 #ifdef HAVE_UNISTD_H |
| 94 #include <unistd.h> | |
| 95 #endif | |
| 96 | |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
97 #if !defined(MS_WINDOWS) && !defined(PYOS_OS2) |
|
4651
6effd10e7233
Added extern decl for gethostname() to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
98 extern int gethostname(); /* For Solaris, at least */ |
|
6effd10e7233
Added extern decl for gethostname() to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
99 #endif |
|
6effd10e7233
Added extern decl for gethostname() to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
100 |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
101 #if defined(PYCC_VACPP) |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
102 #include <types.h> |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
103 #include <io.h> |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
104 #include <sys/ioctl.h> |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
105 #include <utils.h> |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
106 #include <ctype.h> |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
107 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
108 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
109 #if defined(PYOS_OS2) |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
110 #define INCL_DOS |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
111 #define INCL_DOSERRORS |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
112 #define INCL_NOPMAPI |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
113 #include <os2.h> |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
114 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
115 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
116 #include <sys/types.h> |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
117 #include "mytime.h" |
|
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
|
118 |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
119 #include <signal.h> |
|
3738
ce74bba8a6a6
Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents:
3702
diff
changeset
|
120 #ifndef MS_WINDOWS |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
121 #include <netdb.h> |
| 294 | 122 #include <sys/socket.h> |
| 123 #include <netinet/in.h> | |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
124 #include <fcntl.h> |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
125 #else |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
126 #include <winsock.h> |
|
2736
37c48fde61b8
add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents:
2565
diff
changeset
|
127 #include <fcntl.h> |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
128 #endif |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
129 #ifdef HAVE_SYS_UN_H |
| 294 | 130 #include <sys/un.h> |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
131 #else |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
132 #undef AF_UNIX |
|
1271
2919b448e385
* Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
133 #endif |
|
2919b448e385
* Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
134 |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
135 #ifndef O_NDELAY |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
136 #define O_NDELAY O_NONBLOCK /* For QNX only? */ |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
137 #endif |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
138 |
|
3390
832f26d0e069
Include GUSI.h if using gusi-sockets
Jack Jansen <jack.jansen@cwi.nl>
parents:
3335
diff
changeset
|
139 #ifdef USE_GUSI |
|
832f26d0e069
Include GUSI.h if using gusi-sockets
Jack Jansen <jack.jansen@cwi.nl>
parents:
3335
diff
changeset
|
140 /* fdopen() isn't declared in stdio.h (sigh) */ |
|
832f26d0e069
Include GUSI.h if using gusi-sockets
Jack Jansen <jack.jansen@cwi.nl>
parents:
3335
diff
changeset
|
141 #include <GUSI.h> |
|
832f26d0e069
Include GUSI.h if using gusi-sockets
Jack Jansen <jack.jansen@cwi.nl>
parents:
3335
diff
changeset
|
142 #endif |
|
832f26d0e069
Include GUSI.h if using gusi-sockets
Jack Jansen <jack.jansen@cwi.nl>
parents:
3335
diff
changeset
|
143 |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
144 |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
145 /* Here we have some hacks to choose between K&R or ANSI style function |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
146 definitions. For NT to build this as an extension module (ie, DLL) |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
147 it must be compiled by the C++ compiler, as it takes the address of |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
148 a static data item exported from the main Python DLL. |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
149 */ |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
150 #ifdef MS_WINDOWS |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
151 /* seem to be a few differences in the API */ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
152 #define close 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
|
153 #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
|
154 #define FORCE_ANSI_FUNC_DEFS |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
155 #endif |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
156 |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
157 #if defined(PYOS_OS2) |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
158 #define close soclose |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
159 #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
|
160 #define FORCE_ANSI_FUNC_DEFS |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
161 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
162 |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
163 #ifdef FORCE_ANSI_FUNC_DEFS |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
164 #define BUILD_FUNC_DEF_1( fnname, arg1type, arg1name ) \ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
165 fnname( arg1type arg1name ) |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
166 |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
167 #define BUILD_FUNC_DEF_2( fnname, arg1type, arg1name, arg2type, arg2name ) \ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
168 fnname( arg1type arg1name, arg2type arg2name ) |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
169 |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
170 #define BUILD_FUNC_DEF_3( fnname, arg1type, arg1name, arg2type, arg2name , arg3type, arg3name ) \ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
171 fnname( arg1type arg1name, arg2type arg2name, arg3type arg3name ) |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
172 |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
173 #define BUILD_FUNC_DEF_4( fnname, arg1type, arg1name, arg2type, arg2name , arg3type, arg3name, arg4type, arg4name ) \ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
174 fnname( arg1type arg1name, arg2type arg2name, arg3type arg3name, arg4type arg4name ) |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
175 |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
176 #else /* !FORCE_ANSI_FN_DEFS */ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
177 #define BUILD_FUNC_DEF_1( fnname, arg1type, arg1name ) \ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
178 fnname( arg1name ) \ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
179 arg1type arg1name; |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
180 |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
181 #define BUILD_FUNC_DEF_2( fnname, arg1type, arg1name, arg2type, arg2name ) \ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
182 fnname( arg1name, arg2name ) \ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
183 arg1type arg1name; \ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
184 arg2type arg2name; |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
185 |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
186 #define BUILD_FUNC_DEF_3( fnname, arg1type, arg1name, arg2type, arg2name, arg3type, arg3name ) \ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
187 fnname( arg1name, arg2name, arg3name ) \ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
188 arg1type arg1name; \ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
189 arg2type arg2name; \ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
190 arg3type arg3name; |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
191 |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
192 #define BUILD_FUNC_DEF_4( fnname, arg1type, arg1name, arg2type, arg2name, arg3type, arg3name, arg4type, arg4name ) \ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
193 fnname( arg1name, arg2name, arg3name, arg4name ) \ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
194 arg1type arg1name; \ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
195 arg2type arg2name; \ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
196 arg3type arg3name; \ |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
197 arg4type arg4name; |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
198 |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
199 #endif /* !FORCE_ANSI_FN_DEFS */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
200 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
201 /* 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
|
202 by this module (but not argument type or memory errors, etc.). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
203 |
| 1970 | 204 static PyObject *PySocket_Error; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
205 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
206 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
207 /* 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
|
208 and return a NULL pointer from a function. */ |
| 294 | 209 |
| 1970 | 210 static PyObject * |
| 211 PySocket_Err() | |
| 294 | 212 { |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
213 #ifdef MS_WINDOWS |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
214 if (WSAGetLastError()) { |
| 1970 | 215 PyObject *v; |
| 216 v = Py_BuildValue("(is)", WSAGetLastError(), "winsock error"); | |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
217 if (v != NULL) { |
| 1970 | 218 PyErr_SetObject(PySocket_Error, v); |
| 219 Py_DECREF(v); | |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
220 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
221 return NULL; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
222 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
223 else |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
224 #endif |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
225 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
226 #if defined(PYOS_OS2) |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
227 if (sock_errno() != NO_ERROR) { |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
228 APIRET rc; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
229 ULONG msglen; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
230 char outbuf[100]; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
231 int myerrorcode = sock_errno(); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
232 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
233 /* Retrieve Socket-Related Error Message from MPTN.MSG File */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
234 rc = DosGetMessage(NULL, 0, outbuf, sizeof(outbuf), |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
235 myerrorcode - SOCBASEERR + 26, "mptn.msg", &msglen); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
236 if (rc == NO_ERROR) { |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
237 PyObject *v; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
238 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
239 outbuf[msglen] = '\0'; /* OS/2 Doesn't Guarantee a Terminator */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
240 if (strlen(outbuf) > 0) { /* If Non-Empty Msg, Trim CRLF */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
241 char *lastc = &outbuf[ strlen(outbuf)-1 ]; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
242 while (lastc > outbuf && isspace(*lastc)) |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
243 *lastc-- = '\0'; /* Trim Trailing Whitespace (CRLF) */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
244 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
245 v = Py_BuildValue("(is)", myerrorcode, outbuf); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
246 if (v != NULL) { |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
247 PyErr_SetObject(PySocket_Error, v); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
248 Py_DECREF(v); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
249 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
250 return NULL; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
251 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
252 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
253 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
254 |
| 1970 | 255 return PyErr_SetFromErrno(PySocket_Error); |
| 294 | 256 } |
| 257 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
258 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
259 /* The object holding a socket. It holds some extra information, |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
260 like the address family, which is used to decode socket address |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
261 arguments properly. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
262 |
| 294 | 263 typedef struct { |
| 1970 | 264 PyObject_HEAD |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
265 int sock_fd; /* Socket file descriptor */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
266 int sock_family; /* Address family, e.g., AF_INET */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
267 int sock_type; /* Socket type, e.g., SOCK_STREAM */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
268 int sock_proto; /* Protocol type, usually 0 */ |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
269 union sock_addr { |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
270 struct sockaddr_in in; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
271 #ifdef AF_UNIX |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
272 struct sockaddr_un un; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
273 #endif |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
274 } sock_addr; |
| 1970 | 275 } PySocketSockObject; |
| 294 | 276 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
277 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
278 /* A forward reference to the Socktype type object. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
279 The Socktype variable contains pointers to various functions, |
| 1970 | 280 some of which call newsockobject(), which uses Socktype, so |
|
374
70a18a6689d4
Make Socktype global so old and new compilers will like it.
Guido van Rossum <guido@python.org>
parents:
324
diff
changeset
|
281 there has to be a circular reference. */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
282 |
| 1970 | 283 staticforward PyTypeObject PySocketSock_Type; |
| 294 | 284 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
285 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
286 /* Create a new socket object. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
287 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
|
288 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
|
289 in NEWOBJ()). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
290 |
| 1970 | 291 static PySocketSockObject * |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
292 BUILD_FUNC_DEF_4(PySocketSock_New,int,fd, int,family, int,type, int,proto) |
| 294 | 293 { |
| 1970 | 294 PySocketSockObject *s; |
| 3594 | 295 PySocketSock_Type.ob_type = &PyType_Type; |
| 1970 | 296 s = PyObject_NEW(PySocketSockObject, &PySocketSock_Type); |
| 294 | 297 if (s != NULL) { |
| 298 s->sock_fd = fd; | |
| 299 s->sock_family = family; | |
| 300 s->sock_type = type; | |
| 301 s->sock_proto = proto; | |
| 302 } | |
| 303 return s; | |
| 304 } | |
| 305 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
306 |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
307 /* Lock to allow python interpreter to continue, but only allow one |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
308 thread to be in gethostbyname */ |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
309 #if defined(WITH_THREAD) && !defined(HAVE_GETHOSTBYNAME_R) && !defined(MS_WINDOWS) |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
310 type_lock gethostbyname_lock; |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
311 #endif |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
312 |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
313 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
314 /* 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
|
315 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
|
316 to do the work; the names "" and "<broadcast>" are special. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
317 Return the length (should always be 4 bytes), or negative if |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
318 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
|
319 |
| 294 | 320 static int |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
321 BUILD_FUNC_DEF_2(setipaddr, char*,name, struct sockaddr_in *,addr_ret) |
| 294 | 322 { |
| 323 struct hostent *hp; | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
324 int d1, d2, d3, d4; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
325 char ch; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
326 #ifdef HAVE_GETHOSTBYNAME_R |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
327 struct hostent hp_allocated; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
328 char buf[1001]; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
329 int buf_len = (sizeof buf) - 1; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
330 int errnop; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
331 #endif /* HAVE_GETHOSTBYNAME_R */ |
| 294 | 332 |
| 4600 | 333 memset((void *) addr_ret, '\0', sizeof(*addr_ret)); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
334 if (name[0] == '\0') { |
| 294 | 335 addr_ret->sin_addr.s_addr = INADDR_ANY; |
| 336 return 4; | |
| 337 } | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
338 if (name[0] == '<' && strcmp(name, "<broadcast>") == 0) { |
| 294 | 339 addr_ret->sin_addr.s_addr = INADDR_BROADCAST; |
| 340 return 4; | |
| 341 } | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
342 if (sscanf(name, "%d.%d.%d.%d%c", &d1, &d2, &d3, &d4, &ch) == 4 && |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
343 0 <= d1 && d1 <= 255 && 0 <= d2 && d2 <= 255 && |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
344 0 <= d3 && d3 <= 255 && 0 <= d4 && d4 <= 255) { |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
345 addr_ret->sin_addr.s_addr = htonl( |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
346 ((long) d1 << 24) | ((long) d2 << 16) | |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
347 ((long) d3 << 8) | ((long) d4 << 0)); |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
348 return 4; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
349 } |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
350 Py_BEGIN_ALLOW_THREADS |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
351 #ifdef HAVE_GETHOSTBYNAME_R |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
352 hp = gethostbyname_r(name, &hp_allocated, buf, buf_len, &errnop); |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
353 #else /* not HAVE_GETHOSTBYNAME_R */ |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
354 #if defined(WITH_THREAD) && !defined(MS_WINDOWS) |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
355 acquire_lock(gethostbyname_lock,1); |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
356 #endif |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
357 hp = gethostbyname(name); |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
358 #if defined(WITH_THREAD) && !defined(MS_WINDOWS) |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
359 release_lock(gethostbyname_lock); |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
360 #endif |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
361 #endif /* HAVE_GETHOSTBYNAME_R */ |
| 1970 | 362 Py_END_ALLOW_THREADS |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
363 |
| 294 | 364 if (hp == NULL) { |
|
2115
7ea369d05c2e
better test for existence of hstrerror()
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
365 #ifdef HAVE_HSTRERROR |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
366 /* Let's get real error message to return */ |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
367 extern int h_errno; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
368 PyErr_SetString(PySocket_Error, (char *)hstrerror(h_errno)); |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
369 #else |
| 1970 | 370 PyErr_SetString(PySocket_Error, "host not found"); |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
371 #endif |
| 294 | 372 return -1; |
| 373 } | |
| 374 memcpy((char *) &addr_ret->sin_addr, hp->h_addr, hp->h_length); | |
| 375 return hp->h_length; | |
| 376 } | |
| 377 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
378 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
379 /* 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
|
380 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
|
381 size numbers). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
382 |
| 1970 | 383 static PyObject * |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
384 BUILD_FUNC_DEF_1(makeipaddr, struct sockaddr_in *,addr) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
385 { |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
386 long x = ntohl(addr->sin_addr.s_addr); |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
387 char buf[100]; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
388 sprintf(buf, "%d.%d.%d.%d", |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
389 (int) (x>>24) & 0xff, (int) (x>>16) & 0xff, |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
390 (int) (x>> 8) & 0xff, (int) (x>> 0) & 0xff); |
| 1970 | 391 return PyString_FromString(buf); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
392 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
393 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
394 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
395 /* 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
|
396 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
|
397 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
|
398 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
|
399 |
| 294 | 400 /*ARGSUSED*/ |
| 1970 | 401 static PyObject * |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
402 BUILD_FUNC_DEF_2(makesockaddr,struct sockaddr *,addr, int,addrlen) |
| 294 | 403 { |
|
925
61143bf03b44
Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
404 if (addrlen == 0) { |
|
61143bf03b44
Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
405 /* No address -- may be recvfrom() from known socket */ |
| 1970 | 406 Py_INCREF(Py_None); |
| 407 return Py_None; | |
|
925
61143bf03b44
Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
408 } |
|
61143bf03b44
Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
409 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
410 switch (addr->sa_family) { |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
411 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
412 case AF_INET: |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
413 { |
| 294 | 414 struct sockaddr_in *a = (struct sockaddr_in *) addr; |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
415 PyObject *addrobj = makeipaddr(a); |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
416 PyObject *ret = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
417 if (addrobj) { |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
418 ret = Py_BuildValue("Oi", addrobj, ntohs(a->sin_port)); |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
419 Py_DECREF(addrobj); |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
420 } |
|
1207
b564bd4e57e1
* ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents:
1132
diff
changeset
|
421 return ret; |
| 294 | 422 } |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
423 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
424 #ifdef AF_UNIX |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
425 case AF_UNIX: |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
426 { |
| 294 | 427 struct sockaddr_un *a = (struct sockaddr_un *) addr; |
| 1970 | 428 return PyString_FromString(a->sun_path); |
| 294 | 429 } |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
430 #endif /* AF_UNIX */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
431 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
432 /* More cases here... */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
433 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
434 default: |
|
5436
cf818b70da3e
In makesockaddr(), if we don't know the address family, don't raise an
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
435 /* If we don't know the address family, don't raise an |
|
cf818b70da3e
In makesockaddr(), if we don't know the address family, don't raise an
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
436 exception -- return it as a tuple. */ |
|
cf818b70da3e
In makesockaddr(), if we don't know the address family, don't raise an
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
437 return Py_BuildValue("is#", |
|
cf818b70da3e
In makesockaddr(), if we don't know the address family, don't raise an
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
438 addr->sa_family, |
|
cf818b70da3e
In makesockaddr(), if we don't know the address family, don't raise an
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
439 addr->sa_data, |
|
cf818b70da3e
In makesockaddr(), if we don't know the address family, don't raise an
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
440 sizeof(addr->sa_data)); |
|
925
61143bf03b44
Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
441 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
442 } |
| 294 | 443 } |
| 444 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
445 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
446 /* 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
|
447 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
|
448 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
|
449 through len_ret. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
450 |
| 294 | 451 static int |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
452 BUILD_FUNC_DEF_4( |
| 1970 | 453 getsockaddrarg,PySocketSockObject *,s, PyObject *,args, struct sockaddr **,addr_ret, int *,len_ret) |
| 294 | 454 { |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
455 switch (s->sock_family) { |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
456 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
457 #ifdef AF_UNIX |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
458 case AF_UNIX: |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
459 { |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
460 struct sockaddr_un* addr; |
| 926 | 461 char *path; |
| 294 | 462 int len; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
463 addr = (struct sockaddr_un* )&(s->sock_addr).un; |
| 1970 | 464 if (!PyArg_Parse(args, "s#", &path, &len)) |
| 294 | 465 return 0; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
466 if (len > sizeof addr->sun_path) { |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
467 PyErr_SetString(PySocket_Error, |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
468 "AF_UNIX path too long"); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
469 return 0; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
470 } |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
471 addr->sun_family = AF_UNIX; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
472 memcpy(addr->sun_path, path, len); |
|
2736
37c48fde61b8
add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents:
2565
diff
changeset
|
473 addr->sun_path[len] = 0; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
474 *addr_ret = (struct sockaddr *) addr; |
|
3666
556ec82f4d93
Calculate length of AF_UNIX addr struct portably in getsockaddrarg().
Guido van Rossum <guido@python.org>
parents:
3665
diff
changeset
|
475 *len_ret = len + sizeof(*addr) - sizeof(addr->sun_path); |
| 294 | 476 return 1; |
| 477 } | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
478 #endif /* AF_UNIX */ |
| 294 | 479 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
480 case AF_INET: |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
481 { |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
482 struct sockaddr_in* addr; |
| 926 | 483 char *host; |
| 294 | 484 int port; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
485 addr=(struct sockaddr_in*)&(s->sock_addr).in; |
| 1970 | 486 if (!PyArg_Parse(args, "(si)", &host, &port)) |
| 294 | 487 return 0; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
488 if (setipaddr(host, addr) < 0) |
| 294 | 489 return 0; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
490 addr->sin_family = AF_INET; |
|
5287
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
4871
diff
changeset
|
491 addr->sin_port = htons((short)port); |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
492 *addr_ret = (struct sockaddr *) addr; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
493 *len_ret = sizeof *addr; |
| 294 | 494 return 1; |
| 495 } | |
| 496 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
497 /* More cases here... */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
498 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
499 default: |
| 1970 | 500 PyErr_SetString(PySocket_Error, "getsockaddrarg: bad family"); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
501 return 0; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
502 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
503 } |
| 294 | 504 } |
| 505 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
506 |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
507 /* Get the address length according to the socket object's address family. |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
508 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
|
509 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
|
510 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
511 static int |
| 1970 | 512 BUILD_FUNC_DEF_2(getsockaddrlen,PySocketSockObject *,s, int *,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
|
513 { |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
514 switch (s->sock_family) { |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
515 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
516 #ifdef AF_UNIX |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
517 case AF_UNIX: |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
518 { |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
519 *len_ret = sizeof (struct sockaddr_un); |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
520 return 1; |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
521 } |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
522 #endif /* AF_UNIX */ |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
523 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
524 case AF_INET: |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
525 { |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
526 *len_ret = sizeof (struct sockaddr_in); |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
527 return 1; |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
528 } |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
529 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
530 /* More cases here... */ |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
531 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
532 default: |
| 1970 | 533 PyErr_SetString(PySocket_Error, "getsockaddrarg: bad family"); |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
534 return 0; |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
535 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
536 } |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
537 } |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
538 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
539 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
540 /* s.accept() method */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
541 |
| 1970 | 542 static PyObject * |
| 543 BUILD_FUNC_DEF_2(PySocketSock_accept,PySocketSockObject *,s, PyObject *,args) | |
| 294 | 544 { |
| 545 char addrbuf[256]; | |
| 546 int addrlen, newfd; | |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
547 PyObject *sock = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
548 PyObject *addr = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
549 PyObject *res = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
550 |
| 1970 | 551 if (!PyArg_NoArgs(args)) |
| 294 | 552 return NULL; |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
553 if (!getsockaddrlen(s, &addrlen)) |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
554 return NULL; |
| 1970 | 555 Py_BEGIN_ALLOW_THREADS |
| 294 | 556 newfd = accept(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen); |
| 1970 | 557 Py_END_ALLOW_THREADS |
| 294 | 558 if (newfd < 0) |
| 1970 | 559 return PySocket_Err(); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
560 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
561 /* Create the new object with unspecified family, |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
562 to avoid calls to bind() etc. on it. */ |
| 1970 | 563 sock = (PyObject *) PySocketSock_New(newfd, |
|
1207
b564bd4e57e1
* ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents:
1132
diff
changeset
|
564 s->sock_family, |
|
b564bd4e57e1
* ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents:
1132
diff
changeset
|
565 s->sock_type, |
|
b564bd4e57e1
* ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents:
1132
diff
changeset
|
566 s->sock_proto); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
567 if (sock == NULL) { |
| 294 | 568 close(newfd); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
569 goto finally; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
570 } |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
571 if (!(addr = makesockaddr((struct sockaddr *) addrbuf, addrlen))) |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
572 goto finally; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
573 |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
574 if (!(res = Py_BuildValue("OO", sock, addr))) |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
575 goto finally; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
576 |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
577 finally: |
| 1970 | 578 Py_XDECREF(sock); |
| 579 Py_XDECREF(addr); | |
| 294 | 580 return res; |
| 581 } | |
| 582 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
583 |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
584 /* s.setblocking(1 | 0) method */ |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
585 |
| 1970 | 586 static PyObject * |
|
2736
37c48fde61b8
add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents:
2565
diff
changeset
|
587 BUILD_FUNC_DEF_2(PySocketSock_setblocking,PySocketSockObject*,s,PyObject*,args) |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
588 { |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
589 int block; |
|
5287
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
4871
diff
changeset
|
590 #ifndef MS_WINDOWS |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
591 int delay_flag; |
|
5287
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
4871
diff
changeset
|
592 #endif |
|
5534
84d3cca814fb
Remove the last three uses of PyArg_GetInt() from the source.
Guido van Rossum <guido@python.org>
parents:
5436
diff
changeset
|
593 if (!PyArg_Parse(args, "i", &block)) |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
594 return NULL; |
| 1970 | 595 Py_BEGIN_ALLOW_THREADS |
|
3738
ce74bba8a6a6
Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents:
3702
diff
changeset
|
596 #ifndef MS_WINDOWS |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
597 #ifdef PYOS_OS2 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
598 block = !block; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
599 ioctl(s->sock_fd, FIONBIO, (caddr_t)&block, sizeof(block)); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
600 #else /* !PYOS_OS2 */ |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
601 delay_flag = fcntl (s->sock_fd, F_GETFL, 0); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
602 if (block) |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
603 delay_flag &= (~O_NDELAY); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
604 else |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
605 delay_flag |= O_NDELAY; |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
606 fcntl (s->sock_fd, F_SETFL, delay_flag); |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
607 #endif /* !PYOS_OS2 */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
608 #else /* MS_WINDOWS */ |
|
2736
37c48fde61b8
add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents:
2565
diff
changeset
|
609 block = !block; |
|
37c48fde61b8
add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents:
2565
diff
changeset
|
610 ioctlsocket(s->sock_fd, FIONBIO, (u_long*)&block); |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
611 #endif /* MS_WINDOWS */ |
| 1970 | 612 Py_END_ALLOW_THREADS |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
613 |
| 1970 | 614 Py_INCREF(Py_None); |
| 615 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
|
616 } |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
617 |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
618 |
|
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
|
619 /* 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
|
620 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
|
621 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
|
622 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
|
623 |
| 1970 | 624 static PyObject * |
| 625 BUILD_FUNC_DEF_2(PySocketSock_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
|
626 { |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
627 int level; |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
628 int optname; |
|
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
|
629 int res; |
|
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
|
630 char *buf; |
|
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
|
631 int buflen; |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
632 int flag; |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
633 |
| 1970 | 634 if (PyArg_Parse(args, "(iii)", &level, &optname, &flag)) { |
|
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
|
635 buf = (char *) &flag; |
|
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
|
636 buflen = sizeof flag; |
|
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
|
637 } |
|
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
|
638 else { |
| 1970 | 639 PyErr_Clear(); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
640 if (!PyArg_Parse(args, "(iis#)", &level, &optname, |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
641 &buf, &buflen)) |
|
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
|
642 return NULL; |
|
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
|
643 } |
|
1413
c914b10bf2ed
* timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
644 res = setsockopt(s->sock_fd, level, optname, (ANY *)buf, buflen); |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
645 if (res < 0) |
| 1970 | 646 return PySocket_Err(); |
| 647 Py_INCREF(Py_None); | |
| 648 return Py_None; | |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
649 } |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
650 |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
651 |
|
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
|
652 /* 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
|
653 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
|
654 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
|
655 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
|
656 |
| 1970 | 657 static PyObject * |
| 658 BUILD_FUNC_DEF_2(PySocketSock_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
|
659 { |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
660 int level; |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
661 int optname; |
|
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
|
662 int res; |
| 1970 | 663 PyObject *buf; |
|
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
|
664 int buflen = 0; |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
665 |
|
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
|
666 if (!PyArg_ParseTuple(args, "ii|i", &level, &optname, &buflen)) |
|
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
|
667 return NULL; |
|
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
|
668 |
|
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
|
669 if (buflen == 0) { |
|
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
|
670 int flag = 0; |
|
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
|
671 int flagsize = sizeof flag; |
|
1413
c914b10bf2ed
* timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
672 res = getsockopt(s->sock_fd, level, optname, |
|
c914b10bf2ed
* timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
673 (ANY *)&flag, &flagsize); |
|
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
|
674 if (res < 0) |
| 1970 | 675 return PySocket_Err(); |
| 676 return PyInt_FromLong(flag); | |
|
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
|
677 } |
|
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
|
678 if (buflen <= 0 || buflen > 1024) { |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
679 PyErr_SetString(PySocket_Error, |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
680 "getsockopt buflen out of range"); |
|
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
|
681 return NULL; |
|
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
|
682 } |
| 1970 | 683 buf = PyString_FromStringAndSize((char *)NULL, buflen); |
|
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
|
684 if (buf == NULL) |
|
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
|
685 return NULL; |
|
1413
c914b10bf2ed
* timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
686 res = getsockopt(s->sock_fd, level, optname, |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2115
diff
changeset
|
687 (ANY *)PyString_AsString(buf), &buflen); |
|
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
|
688 if (res < 0) { |
| 1970 | 689 Py_DECREF(buf); |
| 690 return PySocket_Err(); | |
|
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
|
691 } |
| 1970 | 692 _PyString_Resize(&buf, buflen); |
|
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
|
693 return buf; |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
694 } |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
695 |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
696 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
697 /* s.bind(sockaddr) method */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
698 |
| 1970 | 699 static PyObject * |
| 700 BUILD_FUNC_DEF_2(PySocketSock_bind,PySocketSockObject *,s, PyObject *,args) | |
| 294 | 701 { |
| 702 struct sockaddr *addr; | |
| 703 int addrlen; | |
| 926 | 704 int res; |
| 294 | 705 if (!getsockaddrarg(s, args, &addr, &addrlen)) |
| 706 return NULL; | |
| 1970 | 707 Py_BEGIN_ALLOW_THREADS |
| 926 | 708 res = bind(s->sock_fd, addr, addrlen); |
| 1970 | 709 Py_END_ALLOW_THREADS |
| 926 | 710 if (res < 0) |
| 1970 | 711 return PySocket_Err(); |
| 712 Py_INCREF(Py_None); | |
| 713 return Py_None; | |
| 294 | 714 } |
| 715 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
716 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
717 /* s.close() method. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
718 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
|
719 will surely fail. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
720 |
| 1970 | 721 static PyObject * |
| 722 BUILD_FUNC_DEF_2(PySocketSock_close,PySocketSockObject *,s, PyObject *,args) | |
| 294 | 723 { |
| 1970 | 724 if (!PyArg_NoArgs(args)) |
| 294 | 725 return NULL; |
|
4407
7ddd8b3f6802
Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents:
3738
diff
changeset
|
726 if (s->sock_fd != -1) { |
|
7ddd8b3f6802
Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents:
3738
diff
changeset
|
727 Py_BEGIN_ALLOW_THREADS |
|
7ddd8b3f6802
Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents:
3738
diff
changeset
|
728 (void) close(s->sock_fd); |
|
7ddd8b3f6802
Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents:
3738
diff
changeset
|
729 Py_END_ALLOW_THREADS |
|
7ddd8b3f6802
Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents:
3738
diff
changeset
|
730 } |
| 294 | 731 s->sock_fd = -1; |
| 1970 | 732 Py_INCREF(Py_None); |
| 733 return Py_None; | |
| 294 | 734 } |
| 735 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
736 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
737 /* s.connect(sockaddr) method */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
738 |
| 1970 | 739 static PyObject * |
| 740 BUILD_FUNC_DEF_2(PySocketSock_connect,PySocketSockObject *,s, PyObject *,args) | |
| 294 | 741 { |
| 742 struct sockaddr *addr; | |
| 743 int addrlen; | |
| 926 | 744 int res; |
| 294 | 745 if (!getsockaddrarg(s, args, &addr, &addrlen)) |
| 746 return NULL; | |
| 1970 | 747 Py_BEGIN_ALLOW_THREADS |
| 926 | 748 res = connect(s->sock_fd, addr, addrlen); |
| 1970 | 749 Py_END_ALLOW_THREADS |
| 926 | 750 if (res < 0) |
| 1970 | 751 return PySocket_Err(); |
| 752 Py_INCREF(Py_None); | |
| 753 return Py_None; | |
| 294 | 754 } |
| 755 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
756 |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
757 /* s.connect_ex(sockaddr) method */ |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
758 |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
759 static PyObject * |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
760 BUILD_FUNC_DEF_2(PySocketSock_connect_ex,PySocketSockObject *,s, PyObject *,args) |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
761 { |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
762 struct sockaddr *addr; |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
763 int addrlen; |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
764 int res; |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
765 if (!getsockaddrarg(s, args, &addr, &addrlen)) |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
766 return NULL; |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
767 Py_BEGIN_ALLOW_THREADS |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
768 res = connect(s->sock_fd, addr, addrlen); |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
769 Py_END_ALLOW_THREADS |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
770 if (res != 0) |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
771 res = errno; |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
772 return PyInt_FromLong((long) res); |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
773 } |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
774 |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
775 |
|
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
|
776 /* 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
|
777 |
| 1970 | 778 static PyObject * |
| 779 BUILD_FUNC_DEF_2(PySocketSock_fileno,PySocketSockObject *,s, PyObject *,args) | |
|
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
|
780 { |
| 1970 | 781 if (!PyArg_NoArgs(args)) |
|
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
|
782 return NULL; |
| 1970 | 783 return PyInt_FromLong((long) s->sock_fd); |
|
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
|
784 } |
|
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
900
diff
changeset
|
785 |
|
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
900
diff
changeset
|
786 |
|
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
|
787 #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
|
788 /* 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
|
789 |
|
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
|
790 static PyObject * |
|
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
|
791 BUILD_FUNC_DEF_2(PySocketSock_dup,PySocketSockObject *,s, PyObject *,args) |
|
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
|
792 { |
|
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
|
793 int newfd; |
|
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
|
794 PyObject *sock; |
|
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
|
795 if (!PyArg_NoArgs(args)) |
|
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
|
796 return NULL; |
|
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
|
797 newfd = dup(s->sock_fd); |
|
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
|
798 if (newfd < 0) |
|
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
|
799 return PySocket_Err(); |
|
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
|
800 sock = (PyObject *) PySocketSock_New(newfd, |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
801 s->sock_family, |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
802 s->sock_type, |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
803 s->sock_proto); |
|
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
|
804 if (sock == NULL) |
|
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
|
805 close(newfd); |
|
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
|
806 return sock; |
|
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
|
807 } |
|
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
|
808 #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
|
809 |
|
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
|
810 |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
811 /* s.getsockname() method */ |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
812 |
| 1970 | 813 static PyObject * |
| 814 BUILD_FUNC_DEF_2(PySocketSock_getsockname,PySocketSockObject *,s, PyObject *,args) | |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
815 { |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
816 char addrbuf[256]; |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
817 int addrlen, res; |
| 1970 | 818 if (!PyArg_NoArgs(args)) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
819 return NULL; |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
820 if (!getsockaddrlen(s, &addrlen)) |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
821 return NULL; |
|
3335
9bd1e41d6b11
clear addr buffer before calling getsockname
Guido van Rossum <guido@python.org>
parents:
3091
diff
changeset
|
822 memset(addrbuf, 0, addrlen); |
| 1970 | 823 Py_BEGIN_ALLOW_THREADS |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
824 res = getsockname(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen); |
| 1970 | 825 Py_END_ALLOW_THREADS |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
826 if (res < 0) |
| 1970 | 827 return PySocket_Err(); |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
828 return makesockaddr((struct sockaddr *) addrbuf, addrlen); |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
829 } |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
830 |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
831 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
832 #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
|
833 /* s.getpeername() method */ |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
834 |
| 1970 | 835 static PyObject * |
| 836 BUILD_FUNC_DEF_2(PySocketSock_getpeername,PySocketSockObject *,s, PyObject *,args) | |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
837 { |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
838 char addrbuf[256]; |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
839 int addrlen, res; |
| 1970 | 840 if (!PyArg_NoArgs(args)) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
841 return NULL; |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
842 if (!getsockaddrlen(s, &addrlen)) |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
843 return NULL; |
| 1970 | 844 Py_BEGIN_ALLOW_THREADS |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
845 res = getpeername(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen); |
| 1970 | 846 Py_END_ALLOW_THREADS |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
847 if (res < 0) |
| 1970 | 848 return PySocket_Err(); |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
849 return makesockaddr((struct sockaddr *) addrbuf, addrlen); |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
850 } |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
851 #endif /* HAVE_GETPEERNAME */ |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
852 |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
853 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
854 /* s.listen(n) method */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
855 |
| 1970 | 856 static PyObject * |
| 857 BUILD_FUNC_DEF_2(PySocketSock_listen,PySocketSockObject *,s, PyObject *,args) | |
| 294 | 858 { |
| 859 int backlog; | |
| 926 | 860 int res; |
|
5534
84d3cca814fb
Remove the last three uses of PyArg_GetInt() from the source.
Guido van Rossum <guido@python.org>
parents:
5436
diff
changeset
|
861 if (!PyArg_Parse(args, "i", &backlog)) |
| 294 | 862 return NULL; |
| 1970 | 863 Py_BEGIN_ALLOW_THREADS |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
864 if (backlog < 1) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
865 backlog = 1; |
| 926 | 866 res = listen(s->sock_fd, backlog); |
| 1970 | 867 Py_END_ALLOW_THREADS |
| 926 | 868 if (res < 0) |
| 1970 | 869 return PySocket_Err(); |
| 870 Py_INCREF(Py_None); | |
| 871 return Py_None; | |
| 294 | 872 } |
| 873 | |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
874 #ifndef NO_DUP |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
875 /* s.makefile(mode) method. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
876 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
|
877 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
|
878 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
|
879 of each other.) |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
880 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
|
881 |
| 1970 | 882 static PyObject * |
| 883 BUILD_FUNC_DEF_2(PySocketSock_makefile,PySocketSockObject *,s, PyObject *,args) | |
| 294 | 884 { |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2115
diff
changeset
|
885 extern int fclose Py_PROTO((FILE *)); |
|
2532
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
886 char *mode = "r"; |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
887 int bufsize = -1; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
888 int fd; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
889 FILE *fp; |
|
2532
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
890 PyObject *f; |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
891 |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
892 if (!PyArg_ParseTuple(args, "|si", &mode, &bufsize)) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
893 return NULL; |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
894 #ifdef MS_WIN32 |
|
2736
37c48fde61b8
add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents:
2565
diff
changeset
|
895 if ( ((fd = _open_osfhandle( s->sock_fd, _O_BINARY )) < 0) || |
|
37c48fde61b8
add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents:
2565
diff
changeset
|
896 ((fd = dup(fd)) < 0) || ((fp = fdopen(fd, mode)) == NULL)) { |
|
37c48fde61b8
add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents:
2565
diff
changeset
|
897 #else |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
898 if ((fd = dup(s->sock_fd)) < 0 || |
|
2532
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
899 (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
|
900 #endif |
|
2532
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
901 if (fd >= 0) |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
902 close(fd); |
| 1970 | 903 return PySocket_Err(); |
|
2532
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
904 } |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
905 f = PyFile_FromFile(fp, "<socket>", mode, fclose); |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
906 if (f != NULL) |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
907 PyFile_SetBufSize(f, bufsize); |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
908 return f; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
909 } |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
910 #endif /* NO_DUP */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
911 |
|
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
|
912 /* 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
|
913 |
| 1970 | 914 static PyObject * |
| 915 BUILD_FUNC_DEF_2(PySocketSock_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
|
916 { |
|
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
|
917 int len, n, flags = 0; |
| 1970 | 918 PyObject *buf; |
|
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
|
919 if (!PyArg_ParseTuple(args, "i|i", &len, &flags)) |
|
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
|
920 return NULL; |
| 1970 | 921 buf = PyString_FromStringAndSize((char *) 0, len); |
| 294 | 922 if (buf == NULL) |
| 923 return NULL; | |
| 1970 | 924 Py_BEGIN_ALLOW_THREADS |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2115
diff
changeset
|
925 n = recv(s->sock_fd, PyString_AsString(buf), len, flags); |
| 1970 | 926 Py_END_ALLOW_THREADS |
| 3091 | 927 if (n < 0) { |
| 928 Py_DECREF(buf); | |
| 1970 | 929 return PySocket_Err(); |
| 3091 | 930 } |
|
3665
5188374377ae
Get rid of obsolete allowbroadcast().
Guido van Rossum <guido@python.org>
parents:
3594
diff
changeset
|
931 if (n != len && _PyString_Resize(&buf, n) < 0) |
| 294 | 932 return NULL; |
| 933 return buf; | |
| 934 } | |
| 935 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
936 |
|
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
|
937 /* s.recvfrom(nbytes [,flags]) method */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
938 |
| 1970 | 939 static PyObject * |
| 940 BUILD_FUNC_DEF_2(PySocketSock_recvfrom,PySocketSockObject *,s, PyObject *,args) | |
| 294 | 941 { |
| 942 char addrbuf[256]; | |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
943 PyObject *buf = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
944 PyObject *addr = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
945 PyObject *ret = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
946 |
|
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
|
947 int addrlen, len, n, flags = 0; |
|
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
|
948 if (!PyArg_ParseTuple(args, "i|i", &len, &flags)) |
|
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
|
949 return NULL; |
|
1295
4773d5c3b5a4
* socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
950 if (!getsockaddrlen(s, &addrlen)) |
|
4773d5c3b5a4
* socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
951 return NULL; |
| 1970 | 952 buf = PyString_FromStringAndSize((char *) 0, len); |
|
1295
4773d5c3b5a4
* socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
953 if (buf == NULL) |
|
4773d5c3b5a4
* socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
954 return NULL; |
| 1970 | 955 Py_BEGIN_ALLOW_THREADS |
| 956 n = recvfrom(s->sock_fd, PyString_AsString(buf), len, flags, | |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
957 #ifndef MS_WINDOWS |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
958 #if defined(PYOS_OS2) |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
959 (struct sockaddr *)addrbuf, &addrlen |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
960 #else |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
961 (ANY *)addrbuf, &addrlen |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
962 #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
|
963 #else |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
964 (struct sockaddr *)addrbuf, &addrlen |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
965 #endif |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
966 ); |
| 1970 | 967 Py_END_ALLOW_THREADS |
| 3091 | 968 if (n < 0) { |
| 969 Py_DECREF(buf); | |
| 1970 | 970 return PySocket_Err(); |
| 3091 | 971 } |
|
3665
5188374377ae
Get rid of obsolete allowbroadcast().
Guido van Rossum <guido@python.org>
parents:
3594
diff
changeset
|
972 if (n != len && _PyString_Resize(&buf, n) < 0) |
| 294 | 973 return NULL; |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
974 |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
975 if (!(addr = makesockaddr((struct sockaddr *)addrbuf, addrlen))) |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
976 goto finally; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
977 |
| 1970 | 978 ret = Py_BuildValue("OO", buf, addr); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
979 finally: |
| 1970 | 980 Py_XDECREF(addr); |
| 981 Py_XDECREF(buf); | |
|
1207
b564bd4e57e1
* ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents:
1132
diff
changeset
|
982 return ret; |
| 294 | 983 } |
| 984 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
985 |
|
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
|
986 /* 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
|
987 |
| 1970 | 988 static PyObject * |
| 989 BUILD_FUNC_DEF_2(PySocketSock_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
|
990 { |
| 926 | 991 char *buf; |
|
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
|
992 int len, n, flags = 0; |
|
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
|
993 if (!PyArg_ParseTuple(args, "s#|i", &buf, &len, &flags)) |
|
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
|
994 return NULL; |
| 1970 | 995 Py_BEGIN_ALLOW_THREADS |
| 926 | 996 n = send(s->sock_fd, buf, len, flags); |
| 1970 | 997 Py_END_ALLOW_THREADS |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
998 if (n < 0) |
| 1970 | 999 return PySocket_Err(); |
| 1000 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
|
1001 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1002 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1003 |
|
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
|
1004 /* 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
|
1005 |
| 1970 | 1006 static PyObject * |
| 1007 BUILD_FUNC_DEF_2(PySocketSock_sendto,PySocketSockObject *,s, PyObject *,args) | |
| 294 | 1008 { |
| 1970 | 1009 PyObject *addro; |
| 926 | 1010 char *buf; |
| 294 | 1011 struct sockaddr *addr; |
|
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
|
1012 int addrlen, len, n, flags; |
|
ac3c80abbf43
* classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
1013 flags = 0; |
| 1970 | 1014 if (!PyArg_Parse(args, "(s#O)", &buf, &len, &addro)) { |
| 1015 PyErr_Clear(); | |
| 1016 if (!PyArg_Parse(args, "(s#iO)", &buf, &len, &flags, &addro)) | |
|
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
|
1017 return NULL; |
| 294 | 1018 } |
|
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
|
1019 if (!getsockaddrarg(s, addro, &addr, &addrlen)) |
| 294 | 1020 return NULL; |
| 1970 | 1021 Py_BEGIN_ALLOW_THREADS |
|
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
|
1022 n = sendto(s->sock_fd, buf, len, flags, addr, addrlen); |
| 1970 | 1023 Py_END_ALLOW_THREADS |
| 294 | 1024 if (n < 0) |
| 1970 | 1025 return PySocket_Err(); |
| 1026 return PyInt_FromLong((long)n); | |
| 294 | 1027 } |
| 1028 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1029 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1030 /* s.shutdown(how) method */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1031 |
| 1970 | 1032 static PyObject * |
| 1033 BUILD_FUNC_DEF_2(PySocketSock_shutdown,PySocketSockObject *,s, PyObject *,args) | |
| 294 | 1034 { |
| 1035 int how; | |
| 926 | 1036 int res; |
|
5534
84d3cca814fb
Remove the last three uses of PyArg_GetInt() from the source.
Guido van Rossum <guido@python.org>
parents:
5436
diff
changeset
|
1037 if (!PyArg_Parse(args, "i", &how)) |
| 294 | 1038 return NULL; |
| 1970 | 1039 Py_BEGIN_ALLOW_THREADS |
| 926 | 1040 res = shutdown(s->sock_fd, how); |
| 1970 | 1041 Py_END_ALLOW_THREADS |
| 926 | 1042 if (res < 0) |
| 1970 | 1043 return PySocket_Err(); |
| 1044 Py_INCREF(Py_None); | |
| 1045 return Py_None; | |
| 294 | 1046 } |
| 1047 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1048 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1049 /* List of methods for socket objects */ |
| 294 | 1050 |
| 1970 | 1051 static PyMethodDef PySocketSock_methods[] = { |
| 1052 {"accept", (PyCFunction)PySocketSock_accept}, | |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1053 {"setblocking", (PyCFunction)PySocketSock_setblocking}, |
| 1970 | 1054 {"setsockopt", (PyCFunction)PySocketSock_setsockopt}, |
|
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
|
1055 {"getsockopt", (PyCFunction)PySocketSock_getsockopt, 1}, |
| 1970 | 1056 {"bind", (PyCFunction)PySocketSock_bind}, |
| 1057 {"close", (PyCFunction)PySocketSock_close}, | |
| 1058 {"connect", (PyCFunction)PySocketSock_connect}, | |
|
6618
04313d4f93ff
PySocketSock_methods: Added "connect_ex" so the method can actually be
Barry Warsaw <barry@python.org>
parents:
6604
diff
changeset
|
1059 {"connect_ex", (PyCFunction)PySocketSock_connect_ex}, |
| 1970 | 1060 {"fileno", (PyCFunction)PySocketSock_fileno}, |
|
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
|
1061 #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
|
1062 {"dup", (PyCFunction)PySocketSock_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
|
1063 #endif |
| 1970 | 1064 {"getsockname", (PyCFunction)PySocketSock_getsockname}, |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1065 #ifdef HAVE_GETPEERNAME |
| 1970 | 1066 {"getpeername", (PyCFunction)PySocketSock_getpeername}, |
|
1271
2919b448e385
* Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1067 #endif |
| 1970 | 1068 {"listen", (PyCFunction)PySocketSock_listen}, |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1069 #ifndef NO_DUP |
|
2532
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1070 {"makefile", (PyCFunction)PySocketSock_makefile, 1}, |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1071 #endif |
|
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
|
1072 {"recv", (PyCFunction)PySocketSock_recv, 1}, |
|
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
|
1073 {"recvfrom", (PyCFunction)PySocketSock_recvfrom, 1}, |
|
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
|
1074 {"send", (PyCFunction)PySocketSock_send, 1}, |
| 1970 | 1075 {"sendto", (PyCFunction)PySocketSock_sendto}, |
| 1076 {"shutdown", (PyCFunction)PySocketSock_shutdown}, | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1077 {NULL, NULL} /* sentinel */ |
| 294 | 1078 }; |
| 1079 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1080 |
| 1970 | 1081 /* 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
|
1082 First close the file description. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1083 |
| 294 | 1084 static void |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1085 BUILD_FUNC_DEF_1(PySocketSock_dealloc,PySocketSockObject *,s) |
| 294 | 1086 { |
| 1087 (void) close(s->sock_fd); | |
| 1970 | 1088 PyMem_DEL(s); |
| 294 | 1089 } |
| 1090 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1091 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1092 /* Return a socket object's named attribute. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1093 |
| 1970 | 1094 static PyObject * |
| 1095 BUILD_FUNC_DEF_2(PySocketSock_getattr,PySocketSockObject *,s, char *,name) | |
| 294 | 1096 { |
| 1970 | 1097 return Py_FindMethod(PySocketSock_methods, (PyObject *) s, name); |
| 294 | 1098 } |
| 1099 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1100 |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1101 static PyObject * |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1102 BUILD_FUNC_DEF_1(PySocketSock_repr,PySocketSockObject *,s) |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1103 { |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1104 char buf[512]; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1105 sprintf(buf, |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1106 "<socket object, fd=%d, family=%d, type=%d, protocol=%d>", |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1107 s->sock_fd, s->sock_family, s->sock_type, s->sock_proto); |
|
3421
90b54312661a
remove unused variables
Guido van Rossum <guido@python.org>
parents:
3390
diff
changeset
|
1108 return PyString_FromString(buf); |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1109 } |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1110 |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1111 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1112 /* 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
|
1113 |
| 1970 | 1114 static PyTypeObject PySocketSock_Type = { |
| 3594 | 1115 PyObject_HEAD_INIT(0) /* Must fill in type value later */ |
| 294 | 1116 0, |
| 1117 "socket", | |
| 1970 | 1118 sizeof(PySocketSockObject), |
| 294 | 1119 0, |
| 1970 | 1120 (destructor)PySocketSock_dealloc, /*tp_dealloc*/ |
| 294 | 1121 0, /*tp_print*/ |
| 1970 | 1122 (getattrfunc)PySocketSock_getattr, /*tp_getattr*/ |
| 294 | 1123 0, /*tp_setattr*/ |
| 1124 0, /*tp_compare*/ | |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1125 (reprfunc)PySocketSock_repr, /*tp_repr*/ |
| 294 | 1126 0, /*tp_as_number*/ |
| 1127 0, /*tp_as_sequence*/ | |
| 1128 0, /*tp_as_mapping*/ | |
| 1129 }; | |
| 1130 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1131 |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1132 /* Python interface to gethostname(). */ |
|
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1133 |
|
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1134 /*ARGSUSED*/ |
| 1970 | 1135 static PyObject * |
| 1136 BUILD_FUNC_DEF_2(PySocket_gethostname,PyObject *,self, PyObject *,args) | |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1137 { |
|
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1138 char buf[1024]; |
| 926 | 1139 int res; |
| 1970 | 1140 if (!PyArg_NoArgs(args)) |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1141 return NULL; |
| 1970 | 1142 Py_BEGIN_ALLOW_THREADS |
| 926 | 1143 res = gethostname(buf, (int) sizeof buf - 1); |
| 1970 | 1144 Py_END_ALLOW_THREADS |
| 926 | 1145 if (res < 0) |
| 1970 | 1146 return PySocket_Err(); |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1147 buf[sizeof buf - 1] = '\0'; |
| 1970 | 1148 return PyString_FromString(buf); |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1149 } |
| 926 | 1150 |
| 1151 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1152 /* Python interface to gethostbyname(name). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1153 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1154 /*ARGSUSED*/ |
| 1970 | 1155 static PyObject * |
| 1156 BUILD_FUNC_DEF_2(PySocket_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
|
1157 { |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1158 char *name; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1159 struct sockaddr_in addrbuf; |
| 1970 | 1160 if (!PyArg_Parse(args, "s", &name)) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1161 return NULL; |
| 926 | 1162 if (setipaddr(name, &addrbuf) < 0) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1163 return NULL; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1164 return makeipaddr(&addrbuf); |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1165 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1166 |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1167 /* Python interface to gethostbyaddr(IP). */ |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1168 |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1169 /*ARGSUSED*/ |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1170 static PyObject * |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1171 BUILD_FUNC_DEF_2(PySocket_gethostbyaddr,PyObject *,self, PyObject *, args) |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1172 { |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1173 struct sockaddr_in addr; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1174 char *ip_num; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1175 struct hostent *h; |
|
3421
90b54312661a
remove unused variables
Guido van Rossum <guido@python.org>
parents:
3390
diff
changeset
|
1176 char **pch; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1177 PyObject *rtn_tuple = (PyObject *)NULL; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1178 PyObject *name_list = (PyObject *)NULL; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1179 PyObject *addr_list = (PyObject *)NULL; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1180 PyObject *tmp; |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1181 #ifdef HAVE_GETHOSTBYNAME_R |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1182 struct hostent hp_allocated; |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1183 char buf[16384]; |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1184 int buf_len = (sizeof buf) - 1; |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1185 int errnop; |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1186 #endif /* HAVE_GETHOSTBYNAME_R */ |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1187 |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1188 if (!PyArg_Parse(args, "s", &ip_num)) |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1189 return NULL; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1190 if (setipaddr(ip_num, &addr) < 0) |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1191 return NULL; |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1192 Py_BEGIN_ALLOW_THREADS |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1193 #ifdef HAVE_GETHOSTBYNAME_R |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1194 h = gethostbyaddr_r((char *)&addr.sin_addr, |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1195 sizeof(addr.sin_addr), |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1196 AF_INET, |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1197 &hp_allocated, buf, buf_len, &errnop); |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1198 #else /* not HAVE_GETHOSTBYNAME_R */ |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1199 #if defined(WITH_THREAD) && !defined(MS_WINDOWS) |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1200 acquire_lock(gethostbyname_lock,1); |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1201 #endif |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1202 h = gethostbyaddr((char *)&addr.sin_addr, |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1203 sizeof(addr.sin_addr), |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1204 AF_INET); |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1205 #if defined(WITH_THREAD) && !defined(MS_WINDOWS) |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1206 release_lock(gethostbyname_lock); |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1207 #endif |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1208 #endif /* HAVE_GETHOSTBYNAME_R */ |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1209 Py_END_ALLOW_THREADS |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1210 if (h == NULL) { |
|
2115
7ea369d05c2e
better test for existence of hstrerror()
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
1211 #ifdef HAVE_HSTRERROR |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1212 /* Let's get real error message to return */ |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1213 extern int h_errno; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1214 PyErr_SetString(PySocket_Error, (char *)hstrerror(h_errno)); |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1215 #else |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1216 PyErr_SetString(PySocket_Error, "host not found"); |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1217 #endif |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1218 return NULL; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1219 } |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1220 if ((name_list = PyList_New(0)) == NULL) |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1221 goto err; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1222 if ((addr_list = PyList_New(0)) == NULL) |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1223 goto err; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1224 for (pch = h->h_aliases; *pch != NULL; pch++) { |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1225 int status; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1226 tmp = PyString_FromString(*pch); |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1227 if (tmp == NULL) |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1228 goto err; |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1229 status = PyList_Append(name_list, tmp); |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1230 Py_DECREF(tmp); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1231 if (status) |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1232 goto err; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1233 } |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1234 for (pch = h->h_addr_list; *pch != NULL; pch++) { |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1235 int status; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1236 memcpy((char *) &addr.sin_addr, *pch, h->h_length); |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1237 tmp = makeipaddr(&addr); |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1238 if (tmp == NULL) |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1239 goto err; |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1240 status = PyList_Append(addr_list, tmp); |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1241 Py_DECREF(tmp); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1242 if (status) |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1243 goto err; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1244 } |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1245 rtn_tuple = Py_BuildValue("sOO", h->h_name, name_list, addr_list); |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1246 err: |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1247 Py_XDECREF(name_list); |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1248 Py_XDECREF(addr_list); |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1249 return rtn_tuple; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1250 } |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1251 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1252 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1253 /* Python interface to getservbyname(name). |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1254 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
|
1255 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
|
1256 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1257 /*ARGSUSED*/ |
| 1970 | 1258 static PyObject * |
| 1259 BUILD_FUNC_DEF_2(PySocket_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
|
1260 { |
| 926 | 1261 char *name, *proto; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1262 struct servent *sp; |
| 1970 | 1263 if (!PyArg_Parse(args, "(ss)", &name, &proto)) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1264 return NULL; |
| 1970 | 1265 Py_BEGIN_ALLOW_THREADS |
| 926 | 1266 sp = getservbyname(name, proto); |
| 1970 | 1267 Py_END_ALLOW_THREADS |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1268 if (sp == NULL) { |
| 1970 | 1269 PyErr_SetString(PySocket_Error, "service/proto not found"); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1270 return NULL; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1271 } |
| 1970 | 1272 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
|
1273 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1274 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1275 |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1276 /* Python interface to getprotobyname(name). |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1277 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
|
1278 already known or not useful (like the list of aliases). */ |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1279 |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1280 /*ARGSUSED*/ |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1281 static PyObject * |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1282 BUILD_FUNC_DEF_2(PySocket_getprotobyname,PyObject *,self, PyObject *,args) |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1283 { |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1284 char *name; |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1285 struct protoent *sp; |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1286 if (!PyArg_Parse(args, "s", &name)) |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1287 return NULL; |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1288 Py_BEGIN_ALLOW_THREADS |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1289 sp = getprotobyname(name); |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1290 Py_END_ALLOW_THREADS |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1291 if (sp == NULL) { |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1292 PyErr_SetString(PySocket_Error, "protocol not found"); |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1293 return NULL; |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1294 } |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1295 return PyInt_FromLong((long) sp->p_proto); |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1296 } |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1297 |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1298 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1299 /* Python interface to socket(family, type, proto). |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1300 The third (protocol) argument is optional. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1301 Return a new socket object. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1302 |
| 294 | 1303 /*ARGSUSED*/ |
| 1970 | 1304 static PyObject * |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1305 BUILD_FUNC_DEF_2(PySocket_socket,PyObject *,self, PyObject *,args) |
| 294 | 1306 { |
| 1970 | 1307 PySocketSockObject *s; |
|
3738
ce74bba8a6a6
Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents:
3702
diff
changeset
|
1308 #ifdef MS_WINDOWS |
|
3672
cec27c93b5cb
more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents:
3666
diff
changeset
|
1309 SOCKET fd; |
|
cec27c93b5cb
more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents:
3666
diff
changeset
|
1310 #else |
|
cec27c93b5cb
more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents:
3666
diff
changeset
|
1311 int fd; |
|
cec27c93b5cb
more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents:
3666
diff
changeset
|
1312 #endif |
|
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
|
1313 int family, type, proto = 0; |
|
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
|
1314 if (!PyArg_ParseTuple(args, "ii|i", &family, &type, &proto)) |
|
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
|
1315 return NULL; |
| 1970 | 1316 Py_BEGIN_ALLOW_THREADS |
| 294 | 1317 fd = socket(family, type, proto); |
| 1970 | 1318 Py_END_ALLOW_THREADS |
|
3738
ce74bba8a6a6
Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents:
3702
diff
changeset
|
1319 #ifdef MS_WINDOWS |
|
3672
cec27c93b5cb
more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents:
3666
diff
changeset
|
1320 if (fd == INVALID_SOCKET) |
|
cec27c93b5cb
more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents:
3666
diff
changeset
|
1321 #else |
| 294 | 1322 if (fd < 0) |
|
3672
cec27c93b5cb
more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents:
3666
diff
changeset
|
1323 #endif |
| 1970 | 1324 return PySocket_Err(); |
| 1325 s = PySocketSock_New(fd, family, type, proto); | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1326 /* If the object can't be created, don't forget to close the |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1327 file descriptor again! */ |
| 294 | 1328 if (s == NULL) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1329 (void) close(fd); |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1330 /* From now on, ignore SIGPIPE and let the error checking |
|
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1331 do the work. */ |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1332 #ifdef SIGPIPE |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1333 (void) signal(SIGPIPE, SIG_IGN); |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1334 #endif |
| 1970 | 1335 return (PyObject *) s; |
| 294 | 1336 } |
| 1337 | |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1338 #ifndef NO_DUP |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
1339 /* 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
|
1340 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
|
1341 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
|
1342 |
|
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
1343 /*ARGSUSED*/ |
| 1970 | 1344 static PyObject * |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1345 BUILD_FUNC_DEF_2(PySocket_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
|
1346 { |
| 1970 | 1347 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
|
1348 int fd, family, type, proto = 0; |
|
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
|
1349 if (!PyArg_ParseTuple(args, "iii|i", &fd, &family, &type, &proto)) |
|
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
|
1350 return NULL; |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1099
diff
changeset
|
1351 /* Dup the fd so it and the socket can be closed independently */ |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1099
diff
changeset
|
1352 fd = dup(fd); |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1099
diff
changeset
|
1353 if (fd < 0) |
| 1970 | 1354 return PySocket_Err(); |
| 1355 s = PySocketSock_New(fd, family, type, proto); | |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
1356 /* From now on, ignore SIGPIPE and let the error checking |
|
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
1357 do the work. */ |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1358 #ifdef SIGPIPE |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
1359 (void) signal(SIGPIPE, SIG_IGN); |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1360 #endif |
| 1970 | 1361 return (PyObject *) s; |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
1362 } |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1363 #endif /* NO_DUP */ |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
1364 |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1365 static PyObject * |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1366 BUILD_FUNC_DEF_2(PySocket_ntohs, PyObject *, self, PyObject *, args) |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1367 { |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1368 int x1, x2; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1369 |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1370 if (!PyArg_Parse(args, "i", &x1)) { |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1371 return NULL; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1372 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1373 x2 = (int)ntohs((short)x1); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1374 return PyInt_FromLong(x2); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1375 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1376 |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1377 static PyObject * |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1378 BUILD_FUNC_DEF_2(PySocket_ntohl, PyObject *, self, PyObject *, args) |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1379 { |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1380 int x1, x2; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1381 |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1382 if (!PyArg_Parse(args, "i", &x1)) { |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1383 return NULL; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1384 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1385 x2 = ntohl(x1); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1386 return PyInt_FromLong(x2); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1387 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1388 |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1389 static PyObject * |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1390 BUILD_FUNC_DEF_2(PySocket_htons, PyObject *, self, PyObject *, args) |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1391 { |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1392 int x1, x2; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1393 |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1394 if (!PyArg_Parse(args, "i", &x1)) { |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1395 return NULL; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1396 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1397 x2 = (int)htons((short)x1); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1398 return PyInt_FromLong(x2); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1399 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1400 |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1401 static PyObject * |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1402 BUILD_FUNC_DEF_2(PySocket_htonl, PyObject *, self, PyObject *, args) |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1403 { |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1404 int x1, x2; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1405 |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1406 if (!PyArg_Parse(args, "i", &x1)) { |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1407 return NULL; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1408 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1409 x2 = htonl(x1); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1410 return PyInt_FromLong(x2); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1411 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1412 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1413 /* 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
|
1414 |
| 1970 | 1415 static PyMethodDef PySocket_methods[] = { |
| 1416 {"gethostbyname", PySocket_gethostbyname}, | |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1417 {"gethostbyaddr", PySocket_gethostbyaddr}, |
| 1970 | 1418 {"gethostname", PySocket_gethostname}, |
| 1419 {"getservbyname", PySocket_getservbyname}, | |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1420 {"getprotobyname", PySocket_getprotobyname}, |
|
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
|
1421 {"socket", PySocket_socket, 1}, |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1422 #ifndef NO_DUP |
|
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
|
1423 {"fromfd", PySocket_fromfd, 1}, |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1424 #endif |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1425 {"ntohs", PySocket_ntohs}, |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1426 {"ntohl", PySocket_ntohl}, |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1427 {"htons", PySocket_htons}, |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1428 {"htonl", PySocket_htonl}, |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1429 {NULL, NULL} /* Sentinel */ |
| 294 | 1430 }; |
| 1431 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1432 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1433 /* Convenience routine to export an integer value. |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1434 * |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
1435 * Errors are silently ignored, for better or for worse... |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1436 */ |
| 294 | 1437 static void |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1438 BUILD_FUNC_DEF_3(insint,PyObject *,d, char *,name, int,value) |
| 294 | 1439 { |
| 1970 | 1440 PyObject *v = PyInt_FromLong((long) value); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1441 if (!v || PyDict_SetItemString(d, name, v)) |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
1442 PyErr_Clear(); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1443 |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
1444 Py_XDECREF(v); |
| 294 | 1445 } |
| 1446 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1447 |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
1448 #ifdef 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
|
1449 |
|
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
|
1450 /* Additional initialization and cleanup for NT/Windows */ |
|
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
|
1451 |
|
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
|
1452 static void |
|
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
|
1453 NTcleanup() |
|
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
|
1454 { |
|
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
|
1455 WSACleanup(); |
|
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
|
1456 } |
|
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
|
1457 |
|
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
|
1458 static int |
|
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
|
1459 NTinit() |
|
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
|
1460 { |
|
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
|
1461 WSADATA WSAData; |
|
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
|
1462 int ret; |
|
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
|
1463 char buf[100]; |
|
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
|
1464 ret = WSAStartup(0x0101, &WSAData); |
|
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
|
1465 switch (ret) { |
|
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
|
1466 case 0: /* no error */ |
|
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
|
1467 atexit(NTcleanup); |
|
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
|
1468 return 1; |
|
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
|
1469 case WSASYSNOTREADY: |
|
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
|
1470 PyErr_SetString(PyExc_ImportError, |
|
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
|
1471 "WSAStartup failed: network not ready"); |
|
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
|
1472 break; |
|
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
|
1473 case WSAVERNOTSUPPORTED: |
|
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
|
1474 case WSAEINVAL: |
|
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
|
1475 PyErr_SetString(PyExc_ImportError, |
|
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
|
1476 "WSAStartup failed: requested version not supported"); |
|
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
|
1477 break; |
|
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
|
1478 default: |
|
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
|
1479 sprintf(buf, "WSAStartup failed: error code %d", ret); |
|
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
|
1480 PyErr_SetString(PyExc_ImportError, buf); |
|
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
|
1481 break; |
|
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
|
1482 } |
|
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
|
1483 return 0; |
|
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
|
1484 } |
|
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
|
1485 |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
1486 #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
|
1487 |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1488 #if defined(PYOS_OS2) |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1489 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1490 /* Additional initialization and cleanup for OS/2 */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1491 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1492 static void |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1493 OS2cleanup() |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1494 { |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1495 /* No cleanup is necessary for OS/2 Sockets */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1496 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1497 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1498 static int |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1499 OS2init() |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1500 { |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1501 char reason[64]; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1502 int rc = sock_init(); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1503 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1504 if (rc == 0) { |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
1505 atexit(OS2cleanup); |
|
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
1506 return 1; /* Indicate Success */ |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1507 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1508 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1509 sprintf(reason, "OS/2 TCP/IP Error# %d", sock_errno()); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1510 PyErr_SetString(PyExc_ImportError, reason); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1511 |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
1512 return 0; /* Indicate Failure */ |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1513 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1514 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1515 #endif /* PYOS_OS2 */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1516 |
|
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
|
1517 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1518 /* Initialize this module. |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1519 * This is called when the first 'import socket' is done, |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1520 * via a table in config.c, if config.c is compiled with USE_SOCKET |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1521 * defined. |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1522 * |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1523 * For MS_WINDOWS (which means any Windows variant), this module |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1524 * is actually called "_socket", and there's a wrapper "socket.py" |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1525 * which implements some missing functionality (such as makefile(), |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1526 * dup() and fromfd()). The import of "_socket" may fail with an |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1527 * ImportError exception if initialization of WINSOCK fails. When |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1528 * WINSOCK is initialized succesfully, a call to WSACleanup() is |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1529 * scheduled to be made at exit time. |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1530 * |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1531 * For OS/2, this module is also called "_socket" and uses a wrapper |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1532 * "socket.py" which implements that functionality that is missing |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1533 * when PC operating systems don't put socket descriptors in the |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1534 * operating system's filesystem layer. |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1535 */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1536 |
| 294 | 1537 void |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1538 #if defined(MS_WINDOWS) || defined(PYOS_OS2) |
|
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
|
1539 init_socket() |
|
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
|
1540 #else |
| 294 | 1541 initsocket() |
|
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
|
1542 #endif |
| 294 | 1543 { |
| 1970 | 1544 PyObject *m, *d; |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
1545 #ifdef 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
|
1546 if (!NTinit()) |
|
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
|
1547 return; |
|
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
|
1548 m = Py_InitModule("_socket", PySocket_methods); |
|
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
|
1549 #else |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
1550 #if defined(__TOS_OS2__) |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1551 if (!OS2init()) |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1552 return; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1553 m = Py_InitModule("_socket", PySocket_methods); |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
1554 #else |
| 1970 | 1555 m = Py_InitModule("socket", PySocket_methods); |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
1556 #endif |
|
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
|
1557 #endif |
| 1970 | 1558 d = PyModule_GetDict(m); |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
1559 PySocket_Error = PyErr_NewException("socket.error", NULL, NULL); |
|
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
1560 if (PySocket_Error == NULL) |
|
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
1561 return; |
|
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
1562 PyDict_SetItemString(d, "error", PySocket_Error); |
|
5572
b231855a9474
Add socket.socket_type, as discussed on c.l.p.
Guido van Rossum <guido@python.org>
parents:
5534
diff
changeset
|
1563 PySocketSock_Type.ob_type = &PyType_Type; |
|
b231855a9474
Add socket.socket_type, as discussed on c.l.p.
Guido van Rossum <guido@python.org>
parents:
5534
diff
changeset
|
1564 Py_INCREF(&PySocketSock_Type); |
|
5697
88b0b2a3aab5
socket_type -> SocketType
Guido van Rossum <guido@python.org>
parents:
5572
diff
changeset
|
1565 if (PyDict_SetItemString(d, "SocketType", |
|
5572
b231855a9474
Add socket.socket_type, as discussed on c.l.p.
Guido van Rossum <guido@python.org>
parents:
5534
diff
changeset
|
1566 (PyObject *)&PySocketSock_Type) != 0) |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
1567 return; |
| 294 | 1568 insint(d, "AF_INET", AF_INET); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1569 #ifdef AF_UNIX |
| 294 | 1570 insint(d, "AF_UNIX", AF_UNIX); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1571 #endif /* AF_UNIX */ |
| 294 | 1572 insint(d, "SOCK_STREAM", SOCK_STREAM); |
| 1573 insint(d, "SOCK_DGRAM", SOCK_DGRAM); | |
| 1574 insint(d, "SOCK_RAW", SOCK_RAW); | |
| 1575 insint(d, "SOCK_SEQPACKET", SOCK_SEQPACKET); | |
| 1576 insint(d, "SOCK_RDM", SOCK_RDM); | |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1577 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1578 #ifdef SO_DEBUG |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1579 insint(d, "SO_DEBUG", SO_DEBUG); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1580 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1581 #ifdef SO_ACCEPTCONN |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1582 insint(d, "SO_ACCEPTCONN", SO_ACCEPTCONN); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1583 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1584 #ifdef SO_REUSEADDR |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1585 insint(d, "SO_REUSEADDR", SO_REUSEADDR); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1586 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1587 #ifdef SO_KEEPALIVE |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1588 insint(d, "SO_KEEPALIVE", SO_KEEPALIVE); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1589 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1590 #ifdef SO_DONTROUTE |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1591 insint(d, "SO_DONTROUTE", SO_DONTROUTE); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1592 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1593 #ifdef SO_BROADCAST |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1594 insint(d, "SO_BROADCAST", SO_BROADCAST); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1595 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1596 #ifdef SO_USELOOPBACK |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1597 insint(d, "SO_USELOOPBACK", SO_USELOOPBACK); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1598 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1599 #ifdef SO_LINGER |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1600 insint(d, "SO_LINGER", SO_LINGER); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1601 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1602 #ifdef SO_OOBINLINE |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1603 insint(d, "SO_OOBINLINE", SO_OOBINLINE); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1604 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1605 #ifdef SO_REUSEPORT |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1606 insint(d, "SO_REUSEPORT", SO_REUSEPORT); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1607 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1608 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1609 #ifdef SO_SNDBUF |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1610 insint(d, "SO_SNDBUF", SO_SNDBUF); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1611 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1612 #ifdef SO_RCVBUF |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1613 insint(d, "SO_RCVBUF", SO_RCVBUF); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1614 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1615 #ifdef SO_SNDLOWAT |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1616 insint(d, "SO_SNDLOWAT", SO_SNDLOWAT); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1617 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1618 #ifdef SO_RCVLOWAT |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1619 insint(d, "SO_RCVLOWAT", SO_RCVLOWAT); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1620 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1621 #ifdef SO_SNDTIMEO |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1622 insint(d, "SO_SNDTIMEO", SO_SNDTIMEO); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1623 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1624 #ifdef SO_RCVTIMEO |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1625 insint(d, "SO_RCVTIMEO", SO_RCVTIMEO); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1626 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1627 #ifdef SO_ERROR |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1628 insint(d, "SO_ERROR", SO_ERROR); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1629 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1630 #ifdef SO_TYPE |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1631 insint(d, "SO_TYPE", SO_TYPE); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1632 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1633 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1634 /* Maximum number of connections for "listen" */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1635 #ifdef SOMAXCONN |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1636 insint(d, "SOMAXCONN", SOMAXCONN); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1637 #else |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1638 insint(d, "SOMAXCONN", 5); /* Common value */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1639 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1640 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1641 /* Flags for send, recv */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1642 #ifdef MSG_OOB |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1643 insint(d, "MSG_OOB", MSG_OOB); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1644 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1645 #ifdef MSG_PEEK |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1646 insint(d, "MSG_PEEK", MSG_PEEK); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1647 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1648 #ifdef MSG_DONTROUTE |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1649 insint(d, "MSG_DONTROUTE", MSG_DONTROUTE); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1650 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1651 #ifdef MSG_EOR |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1652 insint(d, "MSG_EOR", MSG_EOR); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1653 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1654 #ifdef MSG_TRUNC |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1655 insint(d, "MSG_TRUNC", MSG_TRUNC); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1656 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1657 #ifdef MSG_CTRUNC |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1658 insint(d, "MSG_CTRUNC", MSG_CTRUNC); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1659 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1660 #ifdef MSG_WAITALL |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1661 insint(d, "MSG_WAITALL", MSG_WAITALL); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1662 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1663 #ifdef MSG_BTAG |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1664 insint(d, "MSG_BTAG", MSG_BTAG); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1665 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1666 #ifdef MSG_ETAG |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1667 insint(d, "MSG_ETAG", MSG_ETAG); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1668 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1669 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1670 /* Protocol level and numbers, usable for [gs]etsockopt */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1671 #ifdef SOL_SOCKET |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1672 insint(d, "SOL_SOCKET", SOL_SOCKET); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1673 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1674 #ifdef IPPROTO_IP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1675 insint(d, "IPPROTO_IP", IPPROTO_IP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1676 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1677 #ifdef IPPROTO_ICMP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1678 insint(d, "IPPROTO_ICMP", IPPROTO_ICMP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1679 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1680 #ifdef IPPROTO_IGMP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1681 insint(d, "IPPROTO_IGMP", IPPROTO_IGMP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1682 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1683 #ifdef IPPROTO_GGP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1684 insint(d, "IPPROTO_GGP", IPPROTO_GGP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1685 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1686 #ifdef IPPROTO_TCP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1687 insint(d, "IPPROTO_TCP", IPPROTO_TCP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1688 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1689 #ifdef IPPROTO_EGP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1690 insint(d, "IPPROTO_EGP", IPPROTO_EGP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1691 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1692 #ifdef IPPROTO_PUP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1693 insint(d, "IPPROTO_PUP", IPPROTO_PUP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1694 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1695 #ifdef IPPROTO_UDP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1696 insint(d, "IPPROTO_UDP", IPPROTO_UDP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1697 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1698 #ifdef IPPROTO_IDP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1699 insint(d, "IPPROTO_IDP", IPPROTO_IDP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1700 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1701 #ifdef IPPROTO_HELLO |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1702 insint(d, "IPPROTO_HELLO", IPPROTO_HELLO); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1703 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1704 #ifdef IPPROTO_ND |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1705 insint(d, "IPPROTO_ND", IPPROTO_ND); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1706 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1707 #ifdef IPPROTO_TP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1708 insint(d, "IPPROTO_TP", IPPROTO_TP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1709 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1710 #ifdef IPPROTO_XTP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1711 insint(d, "IPPROTO_XTP", IPPROTO_XTP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1712 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1713 #ifdef IPPROTO_EON |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1714 insint(d, "IPPROTO_EON", IPPROTO_EON); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1715 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1716 #ifdef IPPROTO_BIP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1717 insint(d, "IPPROTO_BIP", IPPROTO_BIP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1718 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1719 /**/ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1720 #ifdef IPPROTO_RAW |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1721 insint(d, "IPPROTO_RAW", IPPROTO_RAW); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1722 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1723 #ifdef IPPROTO_MAX |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1724 insint(d, "IPPROTO_MAX", IPPROTO_MAX); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1725 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1726 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1727 /* Some port configuration */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1728 #ifdef IPPORT_RESERVED |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1729 insint(d, "IPPORT_RESERVED", IPPORT_RESERVED); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1730 #else |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1731 insint(d, "IPPORT_RESERVED", 1024); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1732 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1733 #ifdef IPPORT_USERRESERVED |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1734 insint(d, "IPPORT_USERRESERVED", IPPORT_USERRESERVED); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1735 #else |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1736 insint(d, "IPPORT_USERRESERVED", 5000); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1737 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1738 |
| 2369 | 1739 /* Some reserved IP v.4 addresses */ |
| 1740 #ifdef INADDR_ANY | |
| 1741 insint(d, "INADDR_ANY", INADDR_ANY); | |
| 1742 #else | |
| 1743 insint(d, "INADDR_ANY", 0x00000000); | |
| 1744 #endif | |
| 1745 #ifdef INADDR_BROADCAST | |
| 1746 insint(d, "INADDR_BROADCAST", INADDR_BROADCAST); | |
| 1747 #else | |
| 1748 insint(d, "INADDR_BROADCAST", 0xffffffff); | |
| 1749 #endif | |
| 1750 #ifdef INADDR_LOOPBACK | |
| 1751 insint(d, "INADDR_LOOPBACK", INADDR_LOOPBACK); | |
| 1752 #else | |
| 1753 insint(d, "INADDR_LOOPBACK", 0x7F000001); | |
| 1754 #endif | |
| 1755 #ifdef INADDR_UNSPEC_GROUP | |
| 1756 insint(d, "INADDR_UNSPEC_GROUP", INADDR_UNSPEC_GROUP); | |
| 1757 #else | |
| 1758 insint(d, "INADDR_UNSPEC_GROUP", 0xe0000000); | |
| 1759 #endif | |
| 1760 #ifdef INADDR_ALLHOSTS_GROUP | |
| 1761 insint(d, "INADDR_ALLHOSTS_GROUP", INADDR_ALLHOSTS_GROUP); | |
| 1762 #else | |
| 1763 insint(d, "INADDR_ALLHOSTS_GROUP", 0xe0000001); | |
| 1764 #endif | |
| 1765 #ifdef INADDR_MAX_LOCAL_GROUP | |
| 1766 insint(d, "INADDR_MAX_LOCAL_GROUP", INADDR_MAX_LOCAL_GROUP); | |
| 1767 #else | |
| 1768 insint(d, "INADDR_MAX_LOCAL_GROUP", 0xe00000ff); | |
| 1769 #endif | |
| 1770 #ifdef INADDR_NONE | |
| 1771 insint(d, "INADDR_NONE", INADDR_NONE); | |
| 1772 #else | |
| 1773 insint(d, "INADDR_NONE", 0xffffffff); | |
| 1774 #endif | |
| 1775 | |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1776 /* IP [gs]etsockopt options */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1777 #ifdef IP_OPTIONS |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1778 insint(d, "IP_OPTIONS", IP_OPTIONS); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1779 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1780 #ifdef IP_HDRINCL |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1781 insint(d, "IP_HDRINCL", IP_HDRINCL); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1782 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1783 #ifdef IP_TOS |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1784 insint(d, "IP_TOS", IP_TOS); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1785 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1786 #ifdef IP_TTL |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1787 insint(d, "IP_TTL", IP_TTL); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1788 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1789 #ifdef IP_RECVOPTS |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1790 insint(d, "IP_RECVOPTS", IP_RECVOPTS); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1791 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1792 #ifdef IP_RECVRETOPTS |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1793 insint(d, "IP_RECVRETOPTS", IP_RECVRETOPTS); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1794 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1795 #ifdef IP_RECVDSTADDR |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1796 insint(d, "IP_RECVDSTADDR", IP_RECVDSTADDR); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1797 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1798 #ifdef IP_RETOPTS |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1799 insint(d, "IP_RETOPTS", IP_RETOPTS); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1800 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1801 #ifdef IP_MULTICAST_IF |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1802 insint(d, "IP_MULTICAST_IF", IP_MULTICAST_IF); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1803 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1804 #ifdef IP_MULTICAST_TTL |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1805 insint(d, "IP_MULTICAST_TTL", IP_MULTICAST_TTL); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1806 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1807 #ifdef IP_MULTICAST_LOOP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1808 insint(d, "IP_MULTICAST_LOOP", IP_MULTICAST_LOOP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1809 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1810 #ifdef IP_ADD_MEMBERSHIP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1811 insint(d, "IP_ADD_MEMBERSHIP", IP_ADD_MEMBERSHIP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1812 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1813 #ifdef IP_DROP_MEMBERSHIP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1814 insint(d, "IP_DROP_MEMBERSHIP", IP_DROP_MEMBERSHIP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
1815 #endif |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1816 |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1817 /* Initialize gethostbyname lock */ |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1818 #if defined(WITH_THREAD) && !defined(HAVE_GETHOSTBYNAME_R) && !defined(MS_WINDOWS) |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1819 gethostbyname_lock = allocate_lock(); |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1820 #endif |
| 294 | 1821 } |
