Moved SSL imports out of util, removed SSL-specific exceptions from the various socket_ functions.
This commit is contained in:
@@ -109,10 +109,6 @@ def socket_send(descriptor, data, flags=0):
|
|||||||
if e[0] == errno.EWOULDBLOCK or e[0] == errno.ENOTCONN:
|
if e[0] == errno.EWOULDBLOCK or e[0] == errno.ENOTCONN:
|
||||||
return 0
|
return 0
|
||||||
raise
|
raise
|
||||||
except util.SSL.WantWriteError:
|
|
||||||
return 0
|
|
||||||
except util.SSL.WantReadError:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
# winsock sometimes throws ENOTCONN
|
# winsock sometimes throws ENOTCONN
|
||||||
SOCKET_CLOSED = (errno.ECONNRESET, errno.ENOTCONN, errno.ESHUTDOWN)
|
SOCKET_CLOSED = (errno.ECONNRESET, errno.ENOTCONN, errno.ESHUTDOWN)
|
||||||
@@ -125,14 +121,6 @@ def socket_recv(descriptor, buflen, flags=0):
|
|||||||
if e[0] in SOCKET_CLOSED:
|
if e[0] in SOCKET_CLOSED:
|
||||||
return ''
|
return ''
|
||||||
raise
|
raise
|
||||||
except util.SSL.WantReadError:
|
|
||||||
return None
|
|
||||||
except util.SSL.ZeroReturnError:
|
|
||||||
return ''
|
|
||||||
except util.SSL.SysCallError, e:
|
|
||||||
if e[0] == -1 or e[0] > 0:
|
|
||||||
return ''
|
|
||||||
raise
|
|
||||||
|
|
||||||
|
|
||||||
def file_recv(fd, buflen, flags=0):
|
def file_recv(fd, buflen, flags=0):
|
||||||
@@ -521,6 +509,22 @@ class GreenPipe(GreenFile):
|
|||||||
self.fd.fd.flush()
|
self.fd.fd.flush()
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
from OpenSSL import SSL
|
||||||
|
except ImportError:
|
||||||
|
class SSL(object):
|
||||||
|
class WantWriteError(object):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class WantReadError(object):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class ZeroReturnError(object):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class SysCallError(object):
|
||||||
|
pass
|
||||||
|
|
||||||
class GreenSSL(GreenSocket):
|
class GreenSSL(GreenSocket):
|
||||||
""" Nonblocking wrapper for SSL.Connection objects.
|
""" Nonblocking wrapper for SSL.Connection objects.
|
||||||
|
|
||||||
@@ -530,7 +534,7 @@ class GreenSSL(GreenSocket):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, fd):
|
def __init__(self, fd):
|
||||||
super(GreenSSL, self).__init__(fd)
|
super(GreenSSL, self).__init__(fd)
|
||||||
assert(isinstance(fd, (util.SSL.ConnectionType)),
|
assert(isinstance(fd, (SSL.ConnectionType)),
|
||||||
"GreenSSL can only be constructed with an "\
|
"GreenSSL can only be constructed with an "\
|
||||||
"OpenSSL Connection object")
|
"OpenSSL Connection object")
|
||||||
self.sock = self
|
self.sock = self
|
||||||
@@ -551,12 +555,12 @@ class GreenSSL(GreenSocket):
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
return self.fd.do_handshake()
|
return self.fd.do_handshake()
|
||||||
except util.SSL.WantReadError:
|
except SSL.WantReadError:
|
||||||
trampoline(self.fd.fileno(),
|
trampoline(self.fd.fileno(),
|
||||||
read=True,
|
read=True,
|
||||||
timeout=self.timeout,
|
timeout=self.timeout,
|
||||||
timeout_exc=socket.timeout)
|
timeout_exc=socket.timeout)
|
||||||
except util.SSL.WantWriteError:
|
except SSL.WantWriteError:
|
||||||
trampoline(self.fd.fileno(),
|
trampoline(self.fd.fileno(),
|
||||||
write=True,
|
write=True,
|
||||||
timeout=self.timeout,
|
timeout=self.timeout,
|
||||||
@@ -600,18 +604,20 @@ class GreenSSL(GreenSocket):
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
return self.fd.read(size)
|
return self.fd.read(size)
|
||||||
except util.SSL.WantReadError:
|
except SSL.WantReadError:
|
||||||
trampoline(self.fd.fileno(),
|
trampoline(self.fd.fileno(),
|
||||||
read=True,
|
read=True,
|
||||||
timeout=self.timeout,
|
timeout=self.timeout,
|
||||||
timeout_exc=socket.timeout)
|
timeout_exc=socket.timeout)
|
||||||
except util.SSL.WantWriteError:
|
except SSL.WantWriteError:
|
||||||
trampoline(self.fd.fileno(),
|
trampoline(self.fd.fileno(),
|
||||||
write=True,
|
write=True,
|
||||||
timeout=self.timeout,
|
timeout=self.timeout,
|
||||||
timeout_exc=socket.timeout)
|
timeout_exc=socket.timeout)
|
||||||
except util.SSL.SysCallError, e:
|
except SSL.ZeroReturnError:
|
||||||
if e[0] == -1:
|
return ''
|
||||||
|
except SSL.SysCallError, e:
|
||||||
|
if e[0] == -1 or e[0] > 0:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
recv = read
|
recv = read
|
||||||
@@ -630,12 +636,12 @@ class GreenSSL(GreenSocket):
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
return self.fd.write(data)
|
return self.fd.write(data)
|
||||||
except util.SSL.WantReadError:
|
except SSL.WantReadError:
|
||||||
trampoline(self.fd.fileno(),
|
trampoline(self.fd.fileno(),
|
||||||
read=True,
|
read=True,
|
||||||
timeout=self.timeout,
|
timeout=self.timeout,
|
||||||
timeout_exc=socket.timeout)
|
timeout_exc=socket.timeout)
|
||||||
except util.SSL.WantWriteError:
|
except SSL.WantWriteError:
|
||||||
trampoline(self.fd.fileno(),
|
trampoline(self.fd.fileno(),
|
||||||
write=True,
|
write=True,
|
||||||
timeout=self.timeout,
|
timeout=self.timeout,
|
||||||
@@ -667,12 +673,12 @@ class GreenSSL(GreenSocket):
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
return self.fd.shutdown()
|
return self.fd.shutdown()
|
||||||
except util.SSL.WantReadError:
|
except SSL.WantReadError:
|
||||||
trampoline(self.fd.fileno(),
|
trampoline(self.fd.fileno(),
|
||||||
read=True,
|
read=True,
|
||||||
timeout=self.timeout,
|
timeout=self.timeout,
|
||||||
timeout_exc=socket.timeout)
|
timeout_exc=socket.timeout)
|
||||||
except util.SSL.WantWriteError:
|
except SSL.WantWriteError:
|
||||||
trampoline(self.fd.fileno(),
|
trampoline(self.fd.fileno(),
|
||||||
write=True,
|
write=True,
|
||||||
timeout=self.timeout,
|
timeout=self.timeout,
|
||||||
|
|||||||
@@ -25,23 +25,6 @@ import select
|
|||||||
import socket
|
import socket
|
||||||
import errno
|
import errno
|
||||||
|
|
||||||
try:
|
|
||||||
from OpenSSL import SSL
|
|
||||||
except ImportError:
|
|
||||||
class SSL(object):
|
|
||||||
class WantWriteError(object):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class WantReadError(object):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class ZeroReturnError(object):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class SysCallError(object):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def g_log(*args):
|
def g_log(*args):
|
||||||
import sys
|
import sys
|
||||||
from eventlet.support import greenlets as greenlet
|
from eventlet.support import greenlets as greenlet
|
||||||
|
|||||||
Reference in New Issue
Block a user