Skip to content

Commit

Permalink
Merge branch 'master' into handle-stream-native-coro
Browse files Browse the repository at this point in the history
  • Loading branch information
bdarnell authored Dec 13, 2016
2 parents e09a6f8 + d258c17 commit f8282c3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions tornado/netutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
# thread now.
u'foo'.encode('idna')

# For undiagnosed reasons, 'latin1' codec may also need to be preloaded.
u'foo'.encode('latin1')

# These errnos indicate that a non-blocking operation must be retried
# at a later time. On most platforms they're the same value, but on
# some they differ.
Expand Down
4 changes: 2 additions & 2 deletions tornado/platform/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time

from tornado.platform import interface

from tornado.util import errno_from_exception

def try_close(f):
# Avoid issue #875 (race condition when using the file in another
Expand Down Expand Up @@ -61,7 +61,7 @@ def __init__(self):
break # success
except socket.error as detail:
if (not hasattr(errno, 'WSAEADDRINUSE') or
detail[0] != errno.WSAEADDRINUSE):
errno_from_exception(detail) != errno.WSAEADDRINUSE):
# "Address already in use" is the only error
# I've seen on two WinXP Pro SP2 boxes, under
# Pythons 2.3.5 and 2.4.1.
Expand Down
5 changes: 5 additions & 0 deletions tornado/tcpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def __init__(self, io_loop=None, ssl_options=None, max_buffer_size=None,
self._sockets = {} # fd -> socket object
self._pending_sockets = []
self._started = False
self._stopped = False
self.max_buffer_size = max_buffer_size
self.read_chunk_size = read_chunk_size

Expand Down Expand Up @@ -228,7 +229,11 @@ def stop(self):
Requests currently in progress may still continue after the
server is stopped.
"""
if self._stopped:
return
self._stopped = True
for fd, sock in self._sockets.items():
assert sock.fileno() == fd
self.io_loop.remove_handler(fd)
sock.close()

Expand Down
9 changes: 9 additions & 0 deletions tornado/test/tcpserver_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import absolute_import, division, print_function, with_statement

import socket

from tornado import gen
Expand Down Expand Up @@ -60,3 +61,11 @@ async def handle_stream(self, stream, address):
self.assertEqual(result, b'data')
server.stop()
client.close()

def test_stop_twice(self):
sock, port = bind_unused_port()
server = TCPServer()
server.add_socket(sock)
server.stop()
server.stop()

0 comments on commit f8282c3

Please sign in to comment.