Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(27)

Delta Between Two Patch Sets: Modules/socketmodule.c

Issue 3871: cross and native build of python for mingw32 with distutils
Left Patch Set: Created 9 years, 6 months ago
Right Patch Set: Created 7 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « Modules/signalmodule.c ('k') | Modules/socketmodule.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 /* Socket module */ 1 /* Socket module */
2 2
3 /* 3 /*
4 4
5 This module provides an interface to Berkeley socket IPC. 5 This module provides an interface to Berkeley socket IPC.
6 6
7 Limitations: 7 Limitations:
8 8
9 - Only AF_INET, AF_INET6 and AF_UNIX address families are supported in a 9 - Only AF_INET, AF_INET6 and AF_UNIX address families are supported in a
10 portable manner, though AF_PACKET, AF_NETLINK and AF_TIPC are supported 10 portable manner, though AF_PACKET, AF_NETLINK and AF_TIPC are supported
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 #ifdef __APPLE__ 86 #ifdef __APPLE__
87 /* 87 /*
88 * inet_aton is not available on OSX 10.3, yet we want to use a binary 88 * inet_aton is not available on OSX 10.3, yet we want to use a binary
89 * that was build on 10.4 or later to work on that release, weak linking 89 * that was build on 10.4 or later to work on that release, weak linking
90 * comes to the rescue. 90 * comes to the rescue.
91 */ 91 */
92 # pragma weak inet_aton 92 # pragma weak inet_aton
93 #endif 93 #endif
94 94
95 #include "Python.h" 95 #include "Python.h"
96 #ifndef HAVE_GETPEERNAME
97 /* FIXME: see comments in configure.in. Also PC/pyconfig.h define it.
98 * Since only this module use getpeername why don't remove declaration
99 * from PC/pyconfig.h and define here if is defined MS_WIN32 ?
100 */
101 #ifdef __MINGW32__
102 # define HAVE_GETPEERNAME
103 #endif
104 #endif /* ndef HAVE_GETPEERNAME */
96 #include "structmember.h" 105 #include "structmember.h"
97 106
98 #undef MAX 107 #undef MAX
99 #define MAX(x, y) ((x) < (y) ? (y) : (x)) 108 #define MAX(x, y) ((x) < (y) ? (y) : (x))
100 109
101 /* Socket object documentation */ 110 /* Socket object documentation */
102 PyDoc_STRVAR(sock_doc, 111 PyDoc_STRVAR(sock_doc,
103 "socket([family[, type[, proto]]]) -> socket object\n\ 112 "socket([family[, type[, proto]]]) -> socket object\n\
104 \n\ 113 \n\
105 Open a socket of the given type. The family argument specifies the\n\ 114 Open a socket of the given type. The family argument specifies the\n\
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 /* include Python's addrinfo.h unless it causes trouble */ 326 /* include Python's addrinfo.h unless it causes trouble */
318 #if defined(__sgi) && _COMPILER_VERSION>700 && defined(_SS_ALIGNSIZE) 327 #if defined(__sgi) && _COMPILER_VERSION>700 && defined(_SS_ALIGNSIZE)
319 /* Do not include addinfo.h on some newer IRIX versions. 328 /* Do not include addinfo.h on some newer IRIX versions.
320 * _SS_ALIGNSIZE is defined in sys/socket.h by 6.5.21, 329 * _SS_ALIGNSIZE is defined in sys/socket.h by 6.5.21,
321 * for example, but not by 6.5.10. 330 * for example, but not by 6.5.10.
322 */ 331 */
323 #elif defined(_MSC_VER) && _MSC_VER>1201 332 #elif defined(_MSC_VER) && _MSC_VER>1201
324 /* Do not include addrinfo.h for MSVC7 or greater. 'addrinfo' and 333 /* Do not include addrinfo.h for MSVC7 or greater. 'addrinfo' and
325 * EAI_* constants are defined in (the already included) ws2tcpip.h. 334 * EAI_* constants are defined in (the already included) ws2tcpip.h.
326 */ 335 */
336 #elif defined(__MINGW32__)
337 /* FIXME: getaddrinfo(HAVE_GETADDRINFO) depend from WINVER
338 TODO: resolve later(see comments in pyport.h) */
339 #if 0
340 /* To use getaddrinfo/getnameinfo from runtime for version before 0x0501
341 we has to define those functions (see below).
342 In all cases mingw linker succeed to link binaries.
343 If you enable this code the load of module will fail on w2k
344 with message like this one:
345 "The specified procedure could not be found" */
346 # if (_WIN32_WINNT < 0x0501)
347 void WSAAPI freeaddrinfo (struct addrinfo*);
348 int WSAAPI getaddrinfo (const char*,const char*,const struct addrinfo*,
349 struct addrinfo**);
350 int WSAAPI getnameinfo(const struct sockaddr*,socklen_t,char*,DWORD,
351 char*,DWORD,int);
352 # endif
353 # define HAVE_GETADDRINFO
354 # define HAVE_GETNAMEINFO
355 #else
356 # if (_WIN32_WINNT < 0x0501)
357 /* Internal implemetation that has to work on w2k and latest. */
358 # define EAI_ADDRFAMILY
359 # include "addrinfo.h"
360 # else
361 # define HAVE_GETADDRINFO
362 # define HAVE_GETNAMEINFO
363 # endif
364 #endif
327 #else 365 #else
328 # include "addrinfo.h" 366 # include "addrinfo.h"
329 #endif 367 #endif
330 368
331 #ifndef HAVE_INET_PTON 369 #ifndef HAVE_INET_PTON
332 #if !defined(NTDDI_VERSION) || (NTDDI_VERSION < NTDDI_LONGHORN) 370 #if !defined(NTDDI_VERSION) || (NTDDI_VERSION < NTDDI_LONGHORN)
333 int inet_pton(int af, const char *src, void *dst); 371 int inet_pton(int af, const char *src, void *dst);
334 const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); 372 const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
335 #endif 373 #endif
336 #endif 374 #endif
(...skipping 17 matching lines...) Expand all
354 #ifdef HAVE_INET_ATON 392 #ifdef HAVE_INET_ATON
355 #define USE_INET_ATON_WEAKLINK 393 #define USE_INET_ATON_WEAKLINK
356 #endif 394 #endif
357 395
358 #endif 396 #endif
359 397
360 /* I know this is a bad practice, but it is the easiest... */ 398 /* I know this is a bad practice, but it is the easiest... */
361 #if !defined(HAVE_GETADDRINFO) 399 #if !defined(HAVE_GETADDRINFO)
362 /* avoid clashes with the C library definition of the symbol. */ 400 /* avoid clashes with the C library definition of the symbol. */
363 #define getaddrinfo fake_getaddrinfo 401 #define getaddrinfo fake_getaddrinfo
402 #ifdef __MINGW32__
403 #ifdef gai_strerror
404 /* NOTE: Mingw w32api always define gai_strerror to gai_strerror{A|W}
405 but getaddrinfo is defined if _WIN32_WINNT >= 0x0501.
406 MSDN say that gai_strerror() exist for w95 and later and
407 getaddrinfo()/getnameinfo() for wxp and later.
408 Since we use fake function to suppress warnign we has to undef. */
409 # undef gai_strerror
410 #endif
411 #endif /*def __MINGW32__*/
364 #define gai_strerror fake_gai_strerror 412 #define gai_strerror fake_gai_strerror
365 #define freeaddrinfo fake_freeaddrinfo 413 #define freeaddrinfo fake_freeaddrinfo
366 #include "getaddrinfo.c" 414 #include "getaddrinfo.c"
367 #endif 415 #endif
368 #if !defined(HAVE_GETNAMEINFO) 416 #if !defined(HAVE_GETNAMEINFO)
369 #define getnameinfo fake_getnameinfo 417 #define getnameinfo fake_getnameinfo
370 #include "getnameinfo.c" 418 #include "getnameinfo.c"
371 #endif 419 #endif
372 420
373 #ifdef MS_WINDOWS 421 #ifdef MS_WINDOWS
(...skipping 3349 matching lines...) Expand 10 before | Expand all | Expand 10 after
3723 Py_INCREF(Py_None); 3771 Py_INCREF(Py_None);
3724 return Py_None; 3772 return Py_None;
3725 } 3773 }
3726 3774
3727 PyDoc_STRVAR(shutdown_doc, 3775 PyDoc_STRVAR(shutdown_doc,
3728 "shutdown(flag)\n\ 3776 "shutdown(flag)\n\
3729 \n\ 3777 \n\
3730 Shut down the reading side of the socket (flag == SHUT_RD), the writing side\n\ 3778 Shut down the reading side of the socket (flag == SHUT_RD), the writing side\n\
3731 of the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR)."); 3779 of the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR).");
3732 3780
3781 #ifndef SIO_RCVALL
3782 #ifdef __MINGW32__
3783 /* MSDN: SIO_RCVALL defined on w2k and later */
3784 /* note "Separate SDKs" required for w2k */
3785 /* 0x98000001 = _WSAIOW(IOC_VENDOR,1) */
3786 # define SIO_RCVALL 0x98000001
3787 # define RCVALL_OFF 0
3788 # define RCVALL_ON 1
3789 /* NOTE: MSDN - this feature is not implemented */
3790 # define RCVALL_SOCKETLEVELONLY 2
3791
3792 /* 0x98000004 = _WSAIOW(IOC_VENDOR,4) */
3793 # define SIO_KEEPALIVE_VALS 0x98000004
3794 struct tcp_keepalive {
3795 u_long onoff;
3796 u_long keepalivetime;
3797 u_long keepaliveinterval;
3798 };
3799 #endif /* def __MINGW32__ */
3800 #endif /* ndef SIO_RCVALL */
3801
3733 #if defined(MS_WINDOWS) && defined(SIO_RCVALL) 3802 #if defined(MS_WINDOWS) && defined(SIO_RCVALL)
3803 /* If isn't defined test_socket.py fail with:
3804 AttributeError: type object '_socket.socket' has no attribute 'ioctl'
3805 */
3734 static PyObject* 3806 static PyObject*
3735 sock_ioctl(PySocketSockObject *s, PyObject *arg) 3807 sock_ioctl(PySocketSockObject *s, PyObject *arg)
3736 { 3808 {
3737 unsigned long cmd = SIO_RCVALL; 3809 unsigned long cmd = SIO_RCVALL;
3738 PyObject *argO; 3810 PyObject *argO;
3739 DWORD recv; 3811 DWORD recv;
3740 3812
3741 if (!PyArg_ParseTuple(arg, "kO:ioctl", &cmd, &argO)) 3813 if (!PyArg_ParseTuple(arg, "kO:ioctl", &cmd, &argO))
3742 return NULL; 3814 return NULL;
3743 3815
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
4061 }; 4133 };
4062 4134
4063 4135
4064 /* Python interface to gethostname(). */ 4136 /* Python interface to gethostname(). */
4065 4137
4066 /*ARGSUSED*/ 4138 /*ARGSUSED*/
4067 static PyObject * 4139 static PyObject *
4068 socket_gethostname(PyObject *self, PyObject *unused) 4140 socket_gethostname(PyObject *self, PyObject *unused)
4069 { 4141 {
4070 #ifdef MS_WINDOWS 4142 #ifdef MS_WINDOWS
4143 # undef USE_UNCODE_gethostname
4144 # if (_WIN32_WINNT >= 0x0500)
4145 # define USE_UNCODE_gethostname
4146 # endif
4147 #endif
4148 #ifdef USE_UNCODE_gethostname
4071 /* Don't use winsock's gethostname, as this returns the ANSI 4149 /* Don't use winsock's gethostname, as this returns the ANSI
4072 version of the hostname, whereas we need a Unicode string. 4150 version of the hostname, whereas we need a Unicode string.
4073 Otherwise, gethostname apparently also returns the DNS name. */ 4151 Otherwise, gethostname apparently also returns the DNS name. */
4074 wchar_t buf[MAX_COMPUTERNAME_LENGTH + 1]; 4152 wchar_t buf[MAX_COMPUTERNAME_LENGTH + 1];
4075 DWORD size = Py_ARRAY_LENGTH(buf); 4153 DWORD size = Py_ARRAY_LENGTH(buf);
4076 wchar_t *name; 4154 wchar_t *name;
4077 PyObject *result; 4155 PyObject *result;
4078 4156
4079 if (GetComputerNameExW(ComputerNamePhysicalDnsHostname, buf, &size)) 4157 if (GetComputerNameExW(ComputerNamePhysicalDnsHostname, buf, &size))
4080 return PyUnicode_FromWideChar(buf, size); 4158 return PyUnicode_FromWideChar(buf, size);
(...skipping 2643 matching lines...) Expand 10 before | Expand all | Expand 10 after
6724 return NULL; 6802 return NULL;
6725 memcpy(&packed_addr, src, sizeof(packed_addr)); 6803 memcpy(&packed_addr, src, sizeof(packed_addr));
6726 return strncpy(dst, inet_ntoa(packed_addr), size); 6804 return strncpy(dst, inet_ntoa(packed_addr), size);
6727 } 6805 }
6728 /* Should set errno to EAFNOSUPPORT */ 6806 /* Should set errno to EAFNOSUPPORT */
6729 return NULL; 6807 return NULL;
6730 } 6808 }
6731 6809
6732 #endif 6810 #endif
6733 #endif 6811 #endif
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+