Commit Graph

246 Commits

Author SHA1 Message Date
Neal Norwitz 39d22e5693 Use O_NONBLOCK rather than O_NDELAY, so we get POSIX non-blocking I/O.
On HPUX, Solaris, Tru64 (Dec UNIX), and IRIX (I think),
O_NONBLOCK is the POSIX version of non-blocking I/O
which is what we want.

On Linux and FreeBSD (at least), O_NONBLOCK and O_NDELAY are the same.
So this change should have no negative effect on those platforms.

Tested on Linux, Solaris, HPUX.

Thanks to Anders Qvist for diagnosing this problem.
2002-11-02 19:55:21 +00:00
Martin v. Löwis 8eb92a014b Patch #608999: Fix portability problems with MIPSPro 7.x 2002-09-19 08:03:21 +00:00
Guido van Rossum 83a072d953 Update the module doc comment. 2002-09-03 19:10:18 +00:00
Neal Norwitz 90128ba22c SF bug #592645 fix memory leak in socket.getaddrinfo 2002-08-09 03:37:42 +00:00
Guido van Rossum 12e3c710db The other half of the patches added to SF patch 555085 by A I
MacIntyre.  At least on OS/2, a subsequent connect() on a nonblocking
socket returns errno==EISCONN to indicate success.  This seems
harmless on Unix.
2002-08-08 20:39:30 +00:00
Guido van Rossum 22a97159cd Clean up some docstrings. Some docstrings didn't show their return
value; others were inconsistent in what to name the argument or return
value; a few module-global functions had "socket." in front of their
name, against convention.
2002-08-08 20:37:08 +00:00
Tim Peters 5814187f5b internal_connect(): Windows. When sock_timeout > 0 and connect() yields
WSAEWOULDBLOCK, the second connect() attempt appears to yield WSAEISCONN
on Win98 but WSAEINVAL on Win2K.  So accept either as meaning "yawn,
fine".  This allows test_socket to succeed on my Win2K box (which it
already did on my Win98SE box).
2002-08-06 22:25:02 +00:00
Mark Hammond fe51c6d66e Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
for Py_Main().

Thanks to Kalle Svensson and Skip Montanaro for the patches.
2002-08-02 02:27:13 +00:00
Martin v. Löwis ddc6f4748e Pass length of result structure into setipaddr. Fixes bug #565747.
Committed to 2.2 branch.
2002-07-28 16:10:31 +00:00
Jeremy Hylton 825e47b655 Put checks for error returns in the right place. 2002-07-25 16:37:51 +00:00
Jeremy Hylton c075e197d6 Extended socket.htonl and ntohl to accept longs.
Fixes SF bug #568322.

The code should raise an OverflowError if the long is > 32 bits, even
on platforms where sizeof(long) > 4.
2002-07-25 16:01:12 +00:00
Mark Hammond 62b1ab1b31 Replace DL_IMPORT with PyMODINIT_FUNC and remove "/export:init..." link
command line for Windows builds.  This should allow MSVC to import and
build the Python MSVC6 project files without error.
2002-07-23 06:31:15 +00:00
Guido van Rossum ad65490628 Bail out early from internal_select() when socket file descriptor
closed.  Prevents core dump.
2002-07-19 12:44:59 +00:00
Tim Peters a12b4cfaa5 A Python float is a C double; redeclare defaulttimeout as such; stops
compiler wngs on Windows.
2002-07-18 22:38:44 +00:00
Guido van Rossum 1693ba8bf8 Silence warning about getdefaulttimeout in PyMethodDef. 2002-07-18 21:11:26 +00:00
Guido van Rossum 9d0c8cee66 Add default timeout functionality. This adds setdefaulttimeout() and
getdefaulttimeout() functions to the socket and _socket modules, and
appropriate tests.
2002-07-18 17:08:35 +00:00
Jeremy Hylton 938ace69a0 staticforward bites the dust.
The staticforward define was needed to support certain broken C
compilers (notably SCO ODT 3.0, perhaps early AIX as well) botched the
static keyword when it was used with a forward declaration of a static
initialized structure.  Standard C allows the forward declaration with
static, and we've decided to stop catering to broken C compilers.  (In
fact, we expect that the compilers are all fixed eight years later.)

I'm leaving staticforward and statichere defined in object.h as
static.  This is only for backwards compatibility with C extensions
that might still use it.

XXX I haven't updated the documentation.
2002-07-17 16:30:39 +00:00
Jack Jansen 84262fb1f3 Mac OS X Jaguar (developer preview) seems to have a working getaddrinfo(). 2002-07-02 14:40:42 +00:00
Martin v. Löwis 14f8b4cfcb Patch #568124: Add doc string macros. 2002-06-13 20:33:02 +00:00
Guido van Rossum 7b8bac106a Fix non-blocking connect() for Windows. Refactored the code
that retries the connect() call in timeout mode so it can be shared
between connect() and connect_ex(), and needs only a single #ifdef.

The test for this was doing funky stuff I don't approve of,
so I removed it in favor of a simpler test.  This allowed me
to implement a simpler, "purer" form of the timeout retry code.
Hopefully that's enough (if you want to be fancy, use non-blocking
mode and decode the errors yourself, like before).
2002-06-13 16:07:04 +00:00
Guido van Rossum 11ba094957 Major overhaul of timeout sockets:
- setblocking(0) and settimeout(0) are now equivalent, and ditto for
  setblocking(1) and settimeout(None).

- Don't raise an exception from internal_select(); let the final call
  report the error (this means you will get an EAGAIN error instead of
  an ETIMEDOUT error -- I don't care).

- Move the select to inside the Py_{BEGIN,END}_ALLOW_THREADS brackets,
  so other theads can run (this was a bug in the original code).

- Redid the retry logic in connect() and connect_ex() to avoid masking
  errors.  This probably doesn't work for Windows yet; I'll fix that
  next.  It may also fail on other platforms, depending on what
  retrying a connect does; I need help with this.

- Get rid of the retry logic in accept().  I don't think it was needed
  at all.  But I may be wrong.
2002-06-13 15:07:44 +00:00
Andrew MacIntyre 7aec4a2e2c work around name clash with OS/2 TCPIP routine sock_init() 2002-06-13 11:53:52 +00:00
Guido van Rossum 1790e65d43 Move the conex_finally label up, so that the errno value is always
returned.
2002-06-07 19:55:29 +00:00
Guido van Rossum e8008f0013 I decided to change the interaction between setblocking() and
settimeout().   Already, settimeout() canceled non-blocking mode; now,
setblocking() also cancels the timeout.  This is easier to document.

(XXX should settimeout(0) be an alias for setblocking(0)?  They seem
to have roughly the same effect.  Also, I'm not sure that the code in
connect() and accept() is correct in all cases.  We'll sort this out
soon enough.)
2002-06-07 03:36:20 +00:00
Guido van Rossum c4fcfa3457 Major cleanup. Renamed static methods to avoid Py prefix. Other misc
cleanup as well, e.g. renamed NTinit to os_init.
2002-06-07 03:19:37 +00:00
Guido van Rossum 3eede5ad81 Whitespace normalization, folding long lines, uniform comment
delimiters.  Also repaired some docstrings and comments.
2002-06-07 02:08:35 +00:00
Guido van Rossum b9e916a0b5 Correct several blunders in the timeout code, mostly my own fault (for
not testing it -- apparently test_timeout.py doesn't test anything
useful):

In internal_select():

- The tv_usec part of the timeout for select() was calculated wrong.

- The first argument to select() was one too low.

- The sense of the direction argument to internal_select() was
  inverted.

In PySocketSock_settimeout():

- The calls to internal_setblocking() were swapped.

Also, repaired some comments and fixed the test for the return value
of internal_select() in sendall -- this was in the original patch.
2002-06-07 01:42:47 +00:00
Guido van Rossum 67f7a38849 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
I've made considerable changes to Michael's code, specifically to use
the select() system call directly and to store the timeout as a C
double instead of a Python object; internally, -1.0 (or anything
negative) represents the None from the API.

I'm not 100% sure that all corner cases are covered correctly, so
please keep an eye on this.  Next I'm going to try it Windows before
Tim complains.

No way is this a bugfix candidate. :-)
2002-06-06 21:08:16 +00:00
Guido van Rossum c9a55776c8 The insint() function is not used. Nuke it. 2002-06-06 20:41:10 +00:00
Guido van Rossum e1c478ff8a The tp_new implementation should initialize the errorhandler field,
otherwise this code could segfault:

  from socket import socket
  s = socket.__new__(socket)
  s.recv(100)
2002-06-06 20:08:25 +00:00
Tim Peters 5de9842b34 Repair widespread misuse of _PyString_Resize. Since it's clear people
don't understand how this function works, also beefed up the docs.  The
most common usage error is of this form (often spread out across gotos):

	if (_PyString_Resize(&s, n) < 0) {
		Py_DECREF(s);
		s = NULL;
		goto outtahere;
	}

The error is that if _PyString_Resize runs out of memory, it automatically
decrefs the input string object s (which also deallocates it, since its
refcount must be 1 upon entry), and sets s to NULL.  So if the "if"
branch ever triggers, it's an error to call Py_DECREF(s):  s is already
NULL!  A correct way to write the above is the simpler (and intended)

	if (_PyString_Resize(&s, n) < 0)
		goto outtahere;

Bugfix candidate.
2002-04-27 18:44:32 +00:00
Neil Schemenauer aa769ae468 PyObject_Del can now be used as a function designator. 2002-04-12 02:44:10 +00:00
Jack Jansen 8ab04b4d65 Got rid of ifdefs for long-obsolete GUSI versions. 2002-04-11 20:46:23 +00:00
Fred Drake 4baedc1d9b Use the PyModule_Add*() APIs instead of manipulating the module dict
directly.
2002-04-01 14:53:37 +00:00
Neal Norwitz 7e78acbb1b Remove last occurrance of PyArg_GetInt. It is deprecated, 2002-03-25 22:23:53 +00:00
Jack Jansen 6d8898b5eb Due to interaction between the MSL C library and the GUSI I/O library I can get reads from sockets to work consistently either for unbuffered binary files or for buffered binary files, but not for both:-(
The workaround is to force socket.makefile() to disable buffering for binary files.

Fixes bug 534625. 2.2.1 candidate.
2002-03-25 15:32:01 +00:00
Andrew MacIntyre ba43e8700b OS/2 EMX port changes (Modules part of patch #450267):
Modules/
    socketmodule.c

EMX handles sockets like Posix, rather than use native APIs
2002-03-03 03:03:52 +00:00
Martin v. Löwis 272cb40e31 Patch #520062: Support IPv6 with VC.NET. 2002-03-01 08:31:07 +00:00
Tim Peters 643a7fc62f Moved the declaration of PySocketSock_Type from socketmodule.h to
socketmodule.c.  No code outside of the .c file references it, so it
doesn't belong the .h file (at least not yet ...), and declaring it
an imported symbol in the .h file can't be made to work on Windows (it's
a cross-DLL symbol then) without substantial code rewriting.  Also
repaired the comment that goes along with the decl, to stop referring
to names and functions that haven't existed for 7 years <wink>.

socketmodule.c compiles cleanly on Windows again.  The test_socket dies
at once, though (later).
2002-02-17 04:13:21 +00:00
Martin v. Löwis e6cc5b68bf Remove extraneous variable 'total', as reported by James Rucker. 2002-02-16 23:13:54 +00:00
Marc-André Lemburg 976ade691c Also fix the comment. 2002-02-16 18:47:07 +00:00
Marc-André Lemburg bb8b78b77a Fix the name of the header file. 2002-02-16 18:44:52 +00:00
Marc-André Lemburg a5d2b4cb18 Break SSL support out of _socket module and place it into a new
helper module _ssl.

The support for the RAND_* APIs in _ssl is now only enabled
for OpenSSL 0.9.5 and up since they were added in that
release.

Note that socketmodule.* should really be renamed to _socket.* --
unfortunately, this seems to lose the CVS history of the file.

Please review and test... I was only able to test the header file
chaos in socketmodule.c/h on Linux. The test run through fine
and compiles don't give errors or warnings.

WARNING: This patch does *not* include changes to the various
non-Unix build process files.
2002-02-16 18:23:30 +00:00
Martin v. Löwis 43b936d08c Patch #477750: Use METH_ constants in Modules. 2002-01-17 23:15:58 +00:00
Martin v. Löwis cdc4451222 Include <unistd.h> in Python.h. Fixes #500924. 2002-01-12 11:05:12 +00:00
Martin v. Löwis 3cde2cb78a Add TCP socket options from glibc 2.2.4. Fixes #495680.
2.2.1 bugfix candidate.
2001-12-22 15:05:32 +00:00
Martin v. Löwis 44ddbde3ab Remove INET6 define. Use ENABLE_IPV6 instead. 2001-12-02 10:15:37 +00:00
Tim Peters 75cdad5584 More sprintf -> PyOS_snprintf. 2001-11-28 22:07:30 +00:00
Tim Peters 885d457709 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Also changed <>-style #includes to ""-style in some places where the
former didn't make sense.
2001-11-28 20:27:42 +00:00
Andrew M. Kuchling 3072ecdcd2 Fix docstring typo 2001-11-28 04:28:31 +00:00