diff options
author | Isaku Yamahata <yamahata@valinux.co.jp> | 2012-11-30 11:44:53 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2012-11-30 14:51:10 +0900 |
commit | 1150dc49c40815b651a8a0db47f10f57bf89618b (patch) | |
tree | 671010d3dcba247d4607c8ade794cc47117f2df7 | |
parent | dae4bc4dc3293c7969f0a9e1084371a39dcb23da (diff) |
python/ovs/stream: Fix Stream.connect() retval for incomplete connection.
This code is a backport from the upstream OVS (commit dcb66da):
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 <yamahata@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/contrib/ovs/stream.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/ryu/contrib/ovs/stream.py b/ryu/contrib/ovs/stream.py index c4d243d0..c640ebf5 100644 --- a/ryu/contrib/ovs/stream.py +++ b/ryu/contrib/ovs/stream.py @@ -161,15 +161,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 |