Skip to content

Commit

Permalink
python/ovs/stream: Fix Stream.connect() retval for incomplete connect…
Browse files Browse the repository at this point in the history
…ion.

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 <[email protected]>
Tested-by: Isaku Yamahata <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
blp committed Nov 22, 2012
1 parent 4fe3445 commit dcb66da
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions python/ovs/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,17 @@ def connect(self):
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
Expand Down

0 comments on commit dcb66da

Please sign in to comment.