[ovs-dev] [PATCH] python/ovs/stream: TypeError: bad operand type for unary -: 'NoneType'
Isaku Yamahata
yamahata at valinux.co.jp
Thu Nov 22 02:57:35 UTC 2012
> I think there's a simpler way to handle this. Here is my version. Will
> you review it? Thanks.
Looks good and I tested it.
Tested-by: Isaku Yamahata <yamahata at valinux.co.jp>
thanks,
>
> --8<--------------------------cut here-------------------------->8--
>
> From: Ben Pfaff <blp at nicira.com>
> Date: Wed, 21 Nov 2012 09:00:39 -0800
> Subject: [PATCH] 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 <yamahata at valinux.co.jp>
> Signed-off-by: Ben Pfaff <blp at nicira.com>
> ---
> python/ovs/stream.py | 20 +++++++++++---------
> 1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/python/ovs/stream.py b/python/ovs/stream.py
> index c4d243d..cbe7f42 100644
> --- a/python/ovs/stream.py
> +++ b/python/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
> --
> 1.7.10.4
>
--
yamahata
More information about the dev
mailing list