Commit Graph

582 Commits

Author SHA1 Message Date
Victor Stinner 222dfc7d94 Issue #22117: Fix sock_call_ex() for non-blocking socket
Call internal_select() with a timeout of 0 second, not a timeout of -1 second
(blocking)!
2015-04-06 22:30:41 +02:00
Victor Stinner 8912d1418e Issue #23853: socket.socket.sendall() does no more reset the socket timeout
each time data is sent successfuly. The socket timeout is now the maximum total
duration to send all data.
2015-04-06 23:16:34 +02:00
Victor Stinner 9001d8089c Issue #23834: Fix initial value of the socket timeout
Use _PyTime_FromSeconds() to initialize the default socket timeout to -1
second, instead of -1 nanosecond which causes rounding issues in
internal_select().
2015-04-06 23:06:01 +02:00
Victor Stinner 10550cdb8a Issue #23834: Simplify timeout handling
* Use the new _PyTime_FromSeconds() function to set the timeout to -1 second
  for socket.settimeout(None). It avoids a special case in internal_select()
  because of a rounding issue: -1 nanosecond is rounded to 0 millisecond which
  means non-blocking, instead of blocking.
* Check if the interval the negative in sock_call_ex() instead of doing the
  check in internal_select(). sock_call_ex() remembers if the socket has a
  timeout or not, which avoids a race condition if the timeout is modified in a
  different thread.
2015-04-03 13:22:27 +02:00
Victor Stinner a135cb8143 Issue #23618: Ooops, remove abort() added for debug purpose 2015-04-02 15:17:12 +02:00
Victor Stinner 38aec7525e Issue #23618: Fix sock_connect_impl(), set the socket error code
sock_call_ex() gets the socket error code when the socket function fails.
sock_connect_impl() didn't set the error correctly.
2015-04-02 14:37:20 +02:00
Victor Stinner 81c41dbfcc Issue #23618: socket.socket.connect() now waits until the connection completes
instead of raising InterruptedError if the connection is interrupted by
signals, signal handlers don't raise an exception and the socket is blocking or
has a timeout.

socket.socket.connect() still raise InterruptedError for non-blocking sockets.
2015-04-02 11:50:57 +02:00
Victor Stinner 35bee932e4 Issue #23618: Don't declare recvmsg/sendmsg helper functions on Windows 2015-04-02 12:28:07 +02:00
Victor Stinner ff444e828e Issue #23834: Fix sock_call(), set deadline_initialized to recompute the timeout 2015-04-02 03:22:49 +02:00
Victor Stinner 02f32ab47e Issue #23834: Modify socket.sendall() to reuse sock_call() with
sock_send_impl()
2015-04-01 22:53:26 +02:00
Victor Stinner 31bf2d5073 Issue #23834: Add sock_call() helper function
The BEGIN_SELECT_LOOP and END_SELECT_LOOP macros of socketmodule.c don't handle
EINTR. Functions using these macros use an inner loop to handle EINTR, but they
don't recompute the timeout.

This changes replaces the two macros with a new sock_call() function which
takes a function as a parameter. sock_call() recomputes the timeout, handle
false positive and handle EINTR.
2015-04-01 21:57:09 +02:00
Benjamin Peterson 81541f4480 merge 3.4 2015-04-01 12:37:34 -04:00
Benjamin Peterson 4fd929b431 remove assignment in conditional 2015-04-01 11:16:40 -04:00
Victor Stinner a772662423 Issue #23618: Fix EINTR handling on Windows
Windows uses WSAEINTR error code, not EINTR, for socket functions.
2015-04-01 11:09:43 +02:00
Victor Stinner 70a46f635f Issue #23618: Enhance EINTR handling in socket.connect()
Call PyErr_CheckSignals() immediatly if connect() or select() fails with EINTR
in internal_connect().

Refactor also the code to limit indentaton and make it more readable.
2015-03-31 22:03:59 +02:00
Victor Stinner ee699e9d2b Issue #23618: Fix EINTR handling in socket.connect()
Call PyErr_CheckSignals() if connect(), select() or getsockopt() failed with
EINTR.
2015-03-31 21:28:42 +02:00
Victor Stinner c4e819a54f Issue #23618: Cleanup internal_connect() in socketmodule.c
On Windows, it looks like using the C type socklen_t for getsockopt() (instead
of int) is fine, it was already used in socket.getsockopt().
2015-03-31 21:23:10 +02:00
Victor Stinner b6c15bcad3 Issue #23618: Refactor internal_connect()
On Windows, internal_connect() now reuses internal_connect_select() and always
calls getsockopt().
2015-03-31 16:35:35 +02:00
Victor Stinner dd88d3db45 Issue #23618: Refactor internal_connect()
The function now returns the error code instead of using the global errno
(POSIX) or WSAGetLastError() (Windows).

internal_connect() now returns errno if getsockopt() fails.
2015-03-31 16:08:22 +02:00
Victor Stinner 1bb0aef4d1 Issue #22117: Fix integer overflow check in socket_parse_timeout() on Windows 2015-03-31 16:31:19 +02:00
Victor Stinner dd83bd2f9c Issue #23618: Fix internal_connect_select() 2015-03-31 14:24:47 +02:00
Victor Stinner 416f2e66ca Issue #23618: internal_connect_select() now waits also for error events 2015-03-31 13:56:29 +02:00
Victor Stinner e6951c6c8a Issue #23618: Refactor internal_select() to prepare socket.connect() for EINTR 2015-03-31 13:50:44 +02:00
Victor Stinner 391fa713f7 Issue #23618: Refactor the _socket module
* Inline internal_select() function
* Rename internal_select_ex() internal_select()
2015-03-31 13:15:31 +02:00
Victor Stinner 869e1778c0 Issue #22117: Replace usage of _PyTime_ROUND_UP with _PyTime_ROUND_CEILING
All these functions only accept positive timeouts, so this change has no effect
in practice.
2015-03-30 03:49:14 +02:00
Victor Stinner ea9c0dd2c2 Issue #22117: Fix usage of _PyTime_AsTimeval()
Add _PyTime_AsTimeval_noraise() function. Call it when it's not possible (or
not useful) to raise a Python exception on overflow.
2015-03-30 02:51:13 +02:00
Victor Stinner 71694d5c8c Issue #22117: The socket module uses _PyTime_t timestamp for timeouts 2015-03-28 01:18:54 +01:00
Victor Stinner b7df3144ef Issue #23618, #22117: refactor socketmodule.c
Move Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS inside internal_select_ex() to
prepare a switch to the _PyTime_t type and retry syscall on EINTR.
2015-03-27 22:59:32 +01:00
Victor Stinner f50e187724 Fix compiler warnings: comparison between signed and unsigned numbers 2015-03-20 11:32:24 +01:00
Serhiy Storchaka 8490f5acfe Issue #23001: Few functions in modules mmap, ossaudiodev, socket, ssl, and
codecs, that accepted only read-only bytes-like object now accept writable
bytes-like object too.
2015-03-20 09:00:36 +02:00
Victor Stinner 9a8089b32a Issue #23646: Enhance precision of time.sleep() and socket timeout when
interrupted by a signal

Add a new _PyTime_AddDouble() function and remove _PyTime_ADD_SECONDS() macro.
The _PyTime_ADD_SECONDS only supported an integer number of seconds, the
_PyTime_AddDouble() has subsecond resolution.
2015-03-20 01:42:20 +01:00
Serhiy Storchaka caa01f861c Fixed GCC version testing. 2015-03-05 23:42:24 +02:00
Victor Stinner a4c727131e Fix "GCC diagnostic" in socketmodule.c
Fix regression of changeset 7c6e3358221a on GCC < 4.4. The _socket module
cannot be compiled on "x86 FreeBSD 7.2 3.x" buildbot anymore.
2015-03-05 14:04:03 +01:00
Serhiy Storchaka b48af340b9 Silenced minor GCC warnings. 2015-02-26 15:27:57 +02:00
Serhiy Storchaka 4d0d982985 Issue #23446: Use PyMem_New instead of PyMem_Malloc to avoid possible integer
overflows.  Added few missed PyErr_NoMemory().
2015-02-16 13:33:32 +02:00
Serhiy Storchaka 1a1ff29659 Issue #23446: Use PyMem_New instead of PyMem_Malloc to avoid possible integer
overflows.  Added few missed PyErr_NoMemory().
2015-02-16 13:28:22 +02:00
Charles-François Natali 6e6c59b508 Issue #23285: PEP 475 -- Retry system calls failing with EINTR. 2015-02-07 13:27:50 +00:00
Serhiy Storchaka b757c83ec6 Issue #22581: Use more "bytes-like object" throughout the docs and comments. 2014-12-05 22:25:22 +02:00
Steve Dower 65e4cb10d9 Issue #22919: Windows build updated to support VC 14.0 (Visual Studio 2015), which will be used for the official 3.5 release. 2014-11-22 12:54:57 -08:00
Serhiy Storchaka 92bf919ed0 Issue #22581: Use more "bytes-like object" throughout the docs and comments. 2014-12-05 22:26:10 +02:00
Charles-François Natali ea07eb9469 Issue #22378: socket module: add SO_MARK. 2014-09-18 23:18:46 +01:00
Serhiy Storchaka d8a1447c99 Issue #22215: Now ValueError is raised instead of TypeError when str or bytes
argument contains not permitted null character or byte.
2014-09-06 20:07:17 +03:00
Victor Stinner ae58649721 Issue #22043: time.monotonic() is now always available
threading.Lock.acquire(), threading.RLock.acquire() and socket operations now
use a monotonic clock, instead of the system clock, when a timeout is used.
2014-09-02 23:18:25 +02:00
Victor Stinner 1a62a680d6 Issue #22218: Fix "comparison between signed and unsigned integers" warnings in
socketmodule.c.
2014-08-17 19:33:28 +02:00
Martin v. Löwis 17fd1e1013 Issue #22127: fix typo. 2014-08-05 16:13:50 +02:00
Martin v. Löwis eb1c28a849 Issue #22127: Bypass IDNA for pure-ASCII host names (in particular for numeric IPs). 2014-08-05 16:10:38 +02:00
Victor Stinner 011428e168 (Merge 3.4) Fix repr(_socket.socket) on Windows 64-bit: don't fail with
OverflowError on closed socket. repr(socket.socket) already works fine.
2014-07-26 14:37:57 +02:00
Victor Stinner e254e53c83 Fix repr(_socket.socket) on Windows 64-bit: don't fail with OverflowError
on closed socket. repr(socket.socket) already works fine.
2014-07-26 14:36:55 +02:00
Victor Stinner b6dab6bce8 Issue #22042: Avoid dangerous C cast in socket.setblocking()
Avoid cast from (int*) to (u_long*), even if sizeof(int) == sizeof(u_long).
2014-07-23 22:56:55 +02:00
Berker Peksag d9375f121e Fix typo in socket.getaddrinfo() docstring.
Reported by Krishna Kumar Thakur on docs@.
2014-06-30 11:30:00 +03:00