summaryrefslogtreecommitdiffstats
path: root/Modules/socketmodule.c
Commit message (Collapse)AuthorAgeFilesLines
* PySocketSock_connect_ex(): On Windows, return the correct Windows exitTim Peters2001-10-301-1/+6
| | | | | code. The patch is from Jeremy, and allows test_asynchat to run again. Bugfix candidate.
* Oops. In the tp_name field, the name should be "_socket.socket", notGuido van Rossum2001-10-281-2/+2
| | | | | | "socket.socket" -- on Windows, "socket.socket" is the wrapper class. Also added the module name to the SSL type (which is not a new-style class -- I don't want to mess with it yet).
* Made SocketType and socket the same thing: a subclassable type whoseGuido van Rossum2001-10-271-119/+167
| | | | | | | | | | | | | | | | | | | | | constructor acts just like socket() before. All three arguments have a sensible default now; socket() is equivalent to socket(AF_INET, SOCK_STREAM). One minor issue: the socket() function and the SocketType had different doc strings; socket.__doc__ gave the signature, SocketType.__doc__ gave the methods. I've merged these for now, but maybe the list of methods is no longer necessary since it can easily be recovered through socket.__dict__.keys(). The problem with keeping it is that the total doc string is a bit long (34 lines -- it scrolls of a standard tty screen). Another general issue with the socket module is that it's a big mess. There's pages and pages of random platform #ifdefs, and the naming conventions are totally wrong: it uses Py prefixes and CapWords for static functions. That's a cleanup for another day... (Also I think the big starting comment that summarizes the API can go -- it's a repeat of the docstring.)
* Add sendall() method, which loops until all data is written or anGuido van Rossum2001-10-261-2/+44
| | | | | | | error occurs, and doesn't return a count. (This is my second patch from SF patch #474307, with small change to the docstring for send().) 2.1.2 "bugfix" candidate.
* After discussion with itojun, it was clarified that Tru64 is in error,Martin v. Löwis2001-10-251-1/+3
| | | | and that the work-around should be restricted to that system.
* SF patch #474590 -- RISC OS supportGuido van Rossum2001-10-241-15/+10
|
* Fix typo. Thanks to Jack Jansen for spotting it.Martin v. Löwis2001-10-241-1/+1
|
* Include netdb.h to detect getaddrinfo. Work around problem with getaddrinfoMartin v. Löwis2001-10-241-0/+6
| | | | not properly processing numeric IPv4 addresses. Fixes V5.1 part of #472675.
* (Hopefully) fix SF bug #472675: CVS socketmodule now doesn't compileGuido van Rossum2001-10-191-1/+1
| | | | | This appears to be a case of a missing \n\ in a multiline string literal.
* Expose three OpenSSL API calls for dealing with the PRNG.Jeremy Hylton2001-10-181-0/+67
| | | | | | | | | | | | | | | | | Quoth the OpenSSL RAND_add man page: OpenSSL makes sure that the PRNG state is unique for each thread. On systems that provide /dev/urandom, the randomness device is used to seed the PRNG transparently. However, on all other systems, the application is responsible for seeding the PRNG by calling RAND_add(), RAND_egd(3) or RAND_load_file(3). I decided to expose RAND_add() because it's general and RAND_egd() because it's a useful special case. RAND_load_file() didn't seem to offer much over RAND_add(), so I skipped it. Also supplied RAND_status() which returns true if the PRNG is seeded and false if not.
* Fix a bunch of warnings reported by Skip.Guido van Rossum2001-10-151-8/+8
| | | | | | | To whoever who changed a bunch of (PyCFunction) casts to (PyNoArgsFunction) in PyMethodDef initializers: don't do that. The cast is to shut the compiler up. The compiler wants the function pointer initializer to be a PyCFunction.
* Test for __sun instead of __sun__, since SUNWspro only defines the latter;Martin v. Löwis2001-10-131-1/+1
| | | | gcc defines both.
* PySocket_getaddrinfo(): fix two refcount bugs, both having to do withGuido van Rossum2001-10-121-3/+6
| | | | | | | | | | | a misunderstanding of the refcont behavior of the 'O' format code in PyArg_ParseTuple() and Py_BuildValue(), respectively. - pobj is only a borrowed reference, so should *not* be DECREF'ed at the end. This was the cause of SF bug #470635. - The Py_BuildValue() call would leak the object produced by makesockaddr(). (I found this by eyeballing the code.)
* Use PySocket_Err() instead of PyErr_SetFromErrno().Jeremy Hylton2001-10-111-3/+2
| | | | The former does the right thing on Windows, the latter does not.
* Commit parts of SF patch #462759Jeremy Hylton2001-10-111-68/+68
| | | | | | | | | | | | | | | Use #define X509_NAME_MAXLEN for server/issuer length on an SSL object. Update doc strings for socket.ssl() and ssl methods read() and write(). PySSL_SSLwrite(): Check return value and raise exception on error. Use int for len instead of size_t. (All the function the size_t obj was passed to our from expected an int!) PySSL_SSLread(): Check return value of PyArg_ParseTuple()! More robust checks of return values from SSL_read().
* Convert socket methods to use METH_O and METH_NOARGS where possible.Jeremy Hylton2001-10-111-50/+39
|
* Add a bunch of SSL error constantsJeremy Hylton2001-10-111-0/+12
|
* Lots of code reorganization with a few small API changes.Jeremy Hylton2001-10-101-45/+113
| | | | | | | | | | | | | | | | | | | | | | Change all the local names that start with SSL to start with PySSL. The OpenSSL library defines lots of calls that start with "SSL_". The calls for Python's SSL objects also started with "SSL_". This choice made it really confusing to figure out which calls were to the library and which calls were local to the file. Add PySSL_SetError() that sets an exception based on the information from SSL_get_error(). This function will eventually replace all the calls that set it with an error message that is based on the name of the call that failed rather than the reason it failed. (Example: If SSL_connect() failed it used to report "SSL_connect error" now it will offer a specific message about why SSL_connect failed.) XXX It might be helpful to augment the error message generated below with the name of the SSL function that generated the error. I expect it's obvious most of the time. Remove several unnecessary INCREFs in the module's constructor call. PyDict_SetItem() and friends do the INCREF for you.
* Do simple error checking before doing any SSL calls.Jeremy Hylton2001-10-101-5/+5
|
* USe PyObject_SetString() instead of PyObject_SetObject() in newSSLObject().Jeremy Hylton2001-10-101-14/+9
|
* In newSSLObject(), initialize the various members of an SSLObject to NULL.Jeremy Hylton2001-10-101-2/+8
| | | | | | | In SSL_dealloc(), free/dealloc them only if they're non-NULL. Fixes some obvious core dumps, but not sure yet if there are more semantics to the SSL calls that would affect the dealloc.
* A bit of reformatting to match the standard styleJeremy Hylton2001-10-101-7/+7
|
* Fix two memory leaks in socket.ssl().Jeremy Hylton2001-10-101-39/+29
| | | | | | | | | | | | | | | | | | | | | | | | XXX [1] These changes aren't tested very thoroughly, because regrtest doesn't do any SSL tests. I've done some trivial tests on my own, but don't really know how to use the key and cert files. In one case, an SSL-level error causes Python to dump core. I'll get the fixed in the next round of changes. XXX [2] The checkin removes the x_attr member of the SSLObject struct. I'm not sure if this is kosher for backwards compatibility at the binary level. Perhaps its safer to keep the member but keep it assigned to NULL. And the leaks? newSSLObject() called PyDict_New(), stored the result in x_attr without checking it, and later stored NULL in x_attr without doing anything to the dict. So the dict always leaks. There is no further reference to x_attr, so I just removed it completely. The error cases in newSSLObject() passed the return value of PyString_FromString() directly to PyErr_SetObject(). PyErr_SetObject() expects a borrowed reference, so the string leaked.
* SF bug [#456252] Python should never stomp on [u]intptr_t.Tim Peters2001-08-291-1/+1
| | | | | | | | | | | pyport.h: typedef a new Py_intptr_t type. DELICATE ASSUMPTION: That HAVE_UINTPTR_T implies intptr_t is available as well as uintptr_t. If that turns out not to be true, things must get uglier (C99 wants both, so I think it's an assumption we're *likely* to get away with). thread_nt.h, PyThread_start_new_thread: MS _beginthread is documented as returning unsigned long; no idea why uintptr_t was being used. Others: Always use Py_[u]intptr_t, never [u]intptr_t directly.
* SSL_dealloc(): Apply the change suggested in SF bug #425370 whichBarry Warsaw2001-08-201-1/+1
| | | | | changes the order of the free calls to be the reverse of the alloc calls. Closes that bug.
* It will always be a string, because it is created just before this call.Jeremy Hylton2001-08-201-1/+1
|
* Fix portability problems with glibc 2.0, as reported in #449157.Martin v. Löwis2001-08-151-0/+4
|
* Bump size of sprintf buffer. Suggested by Alex Coventry.Martin v. Löwis2001-08-121-1/+1
|
* Autotest for netpacket/packet.h, as it is not available on all Linux versions.Martin v. Löwis2001-08-101-6/+6
| | | | Depend AF_PACKET on HAVE_NETPACKET_PACKET_H. Fixes #449157
* Add more constants. Contributed by itojun.Martin v. Löwis2001-08-041-1/+73
|
* Auto-detect hstrerror. Raise socket.herror in PyH_Error. Register the threeMartin v. Löwis2001-08-041-2/+4
| | | | exception classes in the module dictionary.
* Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.Martin v. Löwis2001-08-031-6/+16
| | | | Since getnameinfo is not implemented, remove __APPLE__ check here.
* Enable PyOS_snprintf() et al. during alpha phase of 2.2.0 andMarc-André Lemburg2001-07-311-10/+2
| | | | add another use case to the socketmodule.
* Temporarily work around bug #445928: Force usage of getaddrinfo emulationMartin v. Löwis2001-07-301-2/+6
| | | | code on Darwin, since the C library version of that seems to be broken.
* Use HAVE_SNPRINTF, not HAVE_SPRINTF, for checking the availability ofThomas Wouters2001-07-241-1/+1
| | | | snprintf.
* Autocheck for snprintf, and use sprintf if it is not available.Martin v. Löwis2001-07-241-3/+8
| | | | | Remove declaration of h_errno, since it is supposedly declared in netdb.h. Changes proposed by itojun.
* Before declaring h_errno, do not check for Win32 only. Instead, do checkMartin v. Löwis2001-07-231-1/+1
| | | | whether h_errno is a macro.
* Instead of accessing ss_family, cast sockaddr_storage to sockaddr and access ↵Martin v. Löwis2001-07-231-1/+5
| | | | sa_family.
* Patch #401196: IPv6 extensions to the socket module.Martin v. Löwis2001-07-211-103/+546
| | | | | | | | New functions getnameinfo, getaddrinfo. New exceptions socket.gaierror, socket.herror. Various new constants, in particular AF_INET6 and error codes and parameters for getaddrinfo. AF_INET6 support in setipaddr, makesockaddr, getsockaddr, getsockaddrlen, gethost_common, PySocket_gethostbyaddr.
* Silence warnings in MSVC++: hide unused variables, add constness back toMartin v. Löwis2001-07-211-5/+5
| | | | inet_pton/ntop, convert htons argument to u_short.
* Clean up some warnings from the SGI compiler.Fred Drake2001-07-191-3/+3
| | | | This is part of SF patch #434992.
* Port getaddrinfo to MSVC++.Martin v. Löwis2001-07-191-12/+0
|
* Remove const-ness in inet_pton declaration.Martin v. Löwis2001-06-251-1/+1
|
* Fix typos in inet_pton/inet_ntop.Martin v. Löwis2001-06-241-2/+3
|
* Provide a definition for offsetof.Martin v. Löwis2001-06-241-0/+8
|
* Emulate inet_{pton,ntop} on systems that don't provide it.Martin v. Löwis2001-06-241-0/+41
|
* Pure brute-force hackery to allow Python to build on Windows again,Tim Peters2001-06-241-0/+12
| | | | | because I need to make progress and don't have time now to think about whatever it is the new code is trying to accomplish.
* Patch #401196: Configuration machinery for IPv6.Martin v. Löwis2001-06-231-0/+10
| | | | | Contributed by Jun-ichiro "itojun" Hagino. get{addr,name}info emulation code taken from WIDE.
* Fix a minor style consistency issue.Fred Drake2001-05-111-3/+3
| | | | | | When getting a string buffer for a string we just created, use PyString_AS_STRING() instead of PyString_AsString() to avoid the call overhead and extra type check.
* Three uses of makesockaddr() used sockaddr buffers that had not be cleared;Fred Drake2001-05-091-1/+4
| | | | | | | | | | | | | this could cause invalid paths to be returned for AF_UNIX sockets on some platforms (including FreeBSD 4.2-RELEASE), appearantly because there is no assurance that the address will be nul-terminated when filled in by the kernel. PySocketSock_recvfrom(): Use PyString_AS_STRING() to get the data pointer of a string we create ourselves; there is no need for the extra type check from PyString_AsString(). This closes SF bug #416573.