def setup(self):
# overriding SocketServer.setup to correctly handle SSL.Connection objects
conn = self.connection = self.request
# TCP_QUICKACK is a better alternative to disabling Nagle's algorithm
# https://news.ycombinator.com/item?id=10607422
if getattr(socket, 'TCP_QUICKACK', None):
try:
conn.setsockopt(socket.IPPROTO_TCP, socket.TCP_QUICKACK, True)
except socket.error:
pass
try:
self.rfile = conn.makefile('rb', self.rbufsize)
self.wfile = conn.makefile('wb', self.wbufsize)
except (AttributeError, NotImplementedError):
if hasattr(conn, 'send') and hasattr(conn, 'recv'):
# it's an SSL.Connection
self.rfile = socket._fileobject(conn, "rb", self.rbufsize)
self.wfile = socket._fileobject(conn, "wb", self.wbufsize)
else:
# it's a SSLObject, or a martian
raise NotImplementedError(
'''eventlet.wsgi doesn't support sockets of type {0}'''.format(type(conn)))
评论列表
文章目录