From: Ben Pfaff Date: Thu, 22 Nov 2012 06:09:55 +0000 (-0800) Subject: python/ovs/stream: Fix Stream.connect() retval for incomplete connection. X-Git-Tag: v1.9.0~54 X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fovs.git;a=commitdiff_plain;h=892a2b9db8d58a67f713ff6a2a76ac29eb697a9e python/ovs/stream: Fix Stream.connect() retval for incomplete connection. If the loop condition in Stream.connect() was false, which is especially likely for TCP connections, then Stream.connect() would return None, which violates its documented behavior. This commit fixes the problem. Reported-by: Isaku Yamahata Tested-by: Isaku Yamahata Signed-off-by: Ben Pfaff --- diff --git a/python/ovs/stream.py b/python/ovs/stream.py index dad68483e..c6d57daea 100644 --- a/python/ovs/stream.py +++ b/python/ovs/stream.py @@ -162,15 +162,17 @@ class Stream(object): is complete, returns 0 if the connection was successful or a positive errno value if it failed. If the connection is still in progress, returns errno.EAGAIN.""" - last_state = -1 # Always differs from initial self.state - while self.state != last_state: - last_state = self.state - if self.state == Stream.__S_CONNECTING: - self.__scs_connecting() - elif self.state == Stream.__S_CONNECTED: - return 0 - elif self.state == Stream.__S_DISCONNECTED: - return self.error + + if self.state == Stream.__S_CONNECTING: + self.__scs_connecting() + + if self.state == Stream.__S_CONNECTING: + return errno.EAGAIN + elif self.state == Stream.__S_CONNECTED: + return 0 + else: + assert self.state == Stream.__S_DISCONNECTED + return self.error def recv(self, n): """Tries to receive up to 'n' bytes from this stream. Returns a