Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
5eca7f3f
Commit
5eca7f3f
authored
Sep 01, 2019
by
Serhiy Storchaka
Committed by
GitHub
Sep 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-15999: Always pass bool instead of int to socket.setblocking(). (GH-15621)
parent
eb897461
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
18 additions
and
18 deletions
+18
-18
Doc/howto/sockets.rst
Doc/howto/sockets.rst
+1
-1
Lib/asyncore.py
Lib/asyncore.py
+2
-2
Lib/test/test_asyncio/functional.py
Lib/test/test_asyncio/functional.py
+1
-1
Lib/test/test_socket.py
Lib/test/test_socket.py
+5
-5
Lib/test/test_ssl.py
Lib/test/test_ssl.py
+2
-2
Lib/test/test_timeout.py
Lib/test/test_timeout.py
+6
-6
Modules/socketmodule.c
Modules/socketmodule.c
+1
-1
No files found.
Doc/howto/sockets.rst
View file @
5eca7f3f
...
...
@@ -317,7 +317,7 @@ know about the mechanics of using sockets. You'll still use the same calls, in
much the same ways. It's just that, if you do it right, your app will be almost
inside-out.
In Python, you use ``socket.setblocking(
0
)`` to make it non-blocking. In C, it's
In Python, you use ``socket.setblocking(
False
)`` to make it non-blocking. In C, it's
more complex, (for one thing, you'll need to choose between the BSD flavor
``O_NONBLOCK`` and the almost indistinguishable Posix flavor ``O_NDELAY``, which
is completely different from ``TCP_NODELAY``), but it's the exact same idea. You
...
...
Lib/asyncore.py
View file @
5eca7f3f
...
...
@@ -228,7 +228,7 @@ class dispatcher:
if
sock
:
# Set to nonblocking just to make sure for cases where we
# get a socket from a blocking source.
sock
.
setblocking
(
0
)
sock
.
setblocking
(
False
)
self
.
set_socket
(
sock
,
map
)
self
.
connected
=
True
# The constructor no longer requires that the socket
...
...
@@ -280,7 +280,7 @@ class dispatcher:
def
create_socket
(
self
,
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_STREAM
):
self
.
family_and_type
=
family
,
type
sock
=
socket
.
socket
(
family
,
type
)
sock
.
setblocking
(
0
)
sock
.
setblocking
(
False
)
self
.
set_socket
(
sock
)
def
set_socket
(
self
,
sock
,
map
=
None
):
...
...
Lib/test/test_asyncio/functional.py
View file @
5eca7f3f
...
...
@@ -225,7 +225,7 @@ class TestThreadedServer(SocketThread):
def
run
(
self
):
try
:
with
self
.
_sock
:
self
.
_sock
.
setblocking
(
0
)
self
.
_sock
.
setblocking
(
False
)
self
.
_run
()
finally
:
self
.
_s1
.
close
()
...
...
Lib/test/test_socket.py
View file @
5eca7f3f
...
...
@@ -4597,7 +4597,7 @@ class NonBlockingTCPTests(ThreadedTCPSocketTest):
def
testAccept
(
self
):
# Testing non-blocking accept
self
.
serv
.
setblocking
(
0
)
self
.
serv
.
setblocking
(
False
)
# connect() didn't start: non-blocking accept() fails
start_time
=
time
.
monotonic
()
...
...
@@ -4628,7 +4628,7 @@ class NonBlockingTCPTests(ThreadedTCPSocketTest):
# Testing non-blocking recv
conn
,
addr
=
self
.
serv
.
accept
()
self
.
addCleanup
(
conn
.
close
)
conn
.
setblocking
(
0
)
conn
.
setblocking
(
False
)
# the server didn't send data yet: non-blocking recv() fails
with
self
.
assertRaises
(
BlockingIOError
):
...
...
@@ -5698,15 +5698,15 @@ class NonblockConstantTest(unittest.TestCase):
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
|
socket
.
SOCK_NONBLOCK
)
as
s
:
self
.
checkNonblock
(
s
)
s
.
setblocking
(
1
)
s
.
setblocking
(
True
)
self
.
checkNonblock
(
s
,
nonblock
=
False
)
s
.
setblocking
(
0
)
s
.
setblocking
(
False
)
self
.
checkNonblock
(
s
)
s
.
settimeout
(
None
)
self
.
checkNonblock
(
s
,
nonblock
=
False
)
s
.
settimeout
(
2.0
)
self
.
checkNonblock
(
s
,
timeout
=
2.0
)
s
.
setblocking
(
1
)
s
.
setblocking
(
True
)
self
.
checkNonblock
(
s
,
nonblock
=
False
)
# defaulttimeout
t
=
socket
.
getdefaulttimeout
()
...
...
Lib/test/test_ssl.py
View file @
5eca7f3f
...
...
@@ -2209,7 +2209,7 @@ class ThreadedEchoServer(threading.Thread):
self
.
running
=
False
self
.
sock
=
connsock
self
.
addr
=
addr
self
.
sock
.
setblocking
(
1
)
self
.
sock
.
setblocking
(
True
)
self
.
sslconn
=
None
threading
.
Thread
.
__init__
(
self
)
self
.
daemon
=
True
...
...
@@ -3255,7 +3255,7 @@ class ThreadedTests(unittest.TestCase):
wrapped
=
False
with
server
:
s
=
socket
.
socket
()
s
.
setblocking
(
1
)
s
.
setblocking
(
True
)
s
.
connect
((
HOST
,
server
.
port
))
if
support
.
verbose
:
sys
.
stdout
.
write
(
"
\
n
"
)
...
...
Lib/test/test_timeout.py
View file @
5eca7f3f
...
...
@@ -79,24 +79,24 @@ class CreationTestCase(unittest.TestCase):
def
testTimeoutThenBlocking
(
self
):
# Test settimeout() followed by setblocking()
self
.
sock
.
settimeout
(
10
)
self
.
sock
.
setblocking
(
1
)
self
.
sock
.
setblocking
(
True
)
self
.
assertEqual
(
self
.
sock
.
gettimeout
(),
None
)
self
.
sock
.
setblocking
(
0
)
self
.
sock
.
setblocking
(
False
)
self
.
assertEqual
(
self
.
sock
.
gettimeout
(),
0.0
)
self
.
sock
.
settimeout
(
10
)
self
.
sock
.
setblocking
(
0
)
self
.
sock
.
setblocking
(
False
)
self
.
assertEqual
(
self
.
sock
.
gettimeout
(),
0.0
)
self
.
sock
.
setblocking
(
1
)
self
.
sock
.
setblocking
(
True
)
self
.
assertEqual
(
self
.
sock
.
gettimeout
(),
None
)
def
testBlockingThenTimeout
(
self
):
# Test setblocking() followed by settimeout()
self
.
sock
.
setblocking
(
0
)
self
.
sock
.
setblocking
(
False
)
self
.
sock
.
settimeout
(
1
)
self
.
assertEqual
(
self
.
sock
.
gettimeout
(),
1
)
self
.
sock
.
setblocking
(
1
)
self
.
sock
.
setblocking
(
True
)
self
.
sock
.
settimeout
(
1
)
self
.
assertEqual
(
self
.
sock
.
gettimeout
(),
1
)
...
...
Modules/socketmodule.c
View file @
5eca7f3f
...
...
@@ -146,7 +146,7 @@ recvfrom_into(buffer[, nbytes, [, flags])\n\
sendall(data[, flags]) -- send all data
\n
\
send(data[, flags]) -- send data, may not send all of it
\n
\
sendto(data[, flags], addr) -- send data to a given address
\n
\
setblocking(
0 | 1
) -- set or clear the blocking I/O flag
\n
\
setblocking(
bool
) -- set or clear the blocking I/O flag
\n
\
getblocking() -- return True if socket is blocking, False if non-blocking
\n
\
setsockopt(level, optname, value[, optlen]) -- set socket options
\n
\
settimeout(None | float) -- set or clear the timeout
\n
\
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment