greenio: Pre-cache proxied GreenSocket methods; Fixes Bitbucket #136; Thanks to Derk Tegeler
https://bitbucket.org/which_linden/eventlet/issue/136
This commit is contained in:
@@ -143,15 +143,28 @@ class GreenSocket(object):
|
|||||||
# act non-blocking
|
# act non-blocking
|
||||||
self.act_non_blocking = False
|
self.act_non_blocking = False
|
||||||
|
|
||||||
|
# Copy some attributes from underlying real socket.
|
||||||
|
# This is the easiest way that i found to fix
|
||||||
|
# https://bitbucket.org/which_linden/eventlet/issue/136
|
||||||
|
# Only `getsockopt` is required to fix that issue, others
|
||||||
|
# are just premature optimization to save __getattr__ call.
|
||||||
|
self.bind = fd.bind
|
||||||
|
self.close = fd.close
|
||||||
|
self.fileno = fd.fileno
|
||||||
|
self.getsockname = fd.getsockname
|
||||||
|
self.getsockopt = fd.getsockopt
|
||||||
|
self.listen = fd.listen
|
||||||
|
self.setsockopt = fd.setsockopt
|
||||||
|
self.shutdown = fd.shutdown
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _sock(self):
|
def _sock(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
#forward unknown attibutes to fd
|
# Forward unknown attributes to fd, cache the value for future use.
|
||||||
# cache the value for future use.
|
|
||||||
# I do not see any simple attribute which could be changed
|
# I do not see any simple attribute which could be changed
|
||||||
# so caching everything in self is fine,
|
# so caching everything in self is fine.
|
||||||
# If we find such attributes - only attributes having __get__ might be cahed.
|
# If we find such attributes - only attributes having __get__ might be cached.
|
||||||
# For now - I do not want to complicate it.
|
# For now - I do not want to complicate it.
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
attr = getattr(self.fd, name)
|
attr = getattr(self.fd, name)
|
||||||
|
@@ -581,6 +581,12 @@ class TestGreenSocket(LimitedTestCase):
|
|||||||
flags = fcntl.fcntl(sock2.fd.fileno(), fcntl.F_GETFL)
|
flags = fcntl.fcntl(sock2.fd.fileno(), fcntl.F_GETFL)
|
||||||
assert flags & os.O_NONBLOCK == 0
|
assert flags & os.O_NONBLOCK == 0
|
||||||
|
|
||||||
|
def test_sockopt_interface(self):
|
||||||
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
assert sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR) == 0
|
||||||
|
assert sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) == '\000'
|
||||||
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
|
|
||||||
|
|
||||||
class TestGreenPipe(LimitedTestCase):
|
class TestGreenPipe(LimitedTestCase):
|
||||||
@skip_on_windows
|
@skip_on_windows
|
||||||
|
Reference in New Issue
Block a user