From patchwork Sun Dec 4 12:02:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guoshuai Li X-Patchwork-Id: 702424 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tWmkK46KJz9tB1 for ; Sun, 4 Dec 2016 23:03:20 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id D208E5AA; Sun, 4 Dec 2016 12:03:16 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 86606516 for ; Sun, 4 Dec 2016 12:03:15 +0000 (UTC) X-Greylist: delayed 01:33:53 by SQLgrey-1.7.6 Received: from smtp2203-239.mail.aliyun.com (unknown [121.197.203.239]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id 71361FB for ; Sun, 4 Dec 2016 12:03:14 +0000 (UTC) X-Alimail-AntiSpam: AC=CONTINUE; BC=0.2841815|-1; FP=8409872713683315963|1|1|1|0|-1|-1|-1; HT=e02c03305; MF=ligs@dtdream.com; NM=1; PH=DS; RN=2; RT=2; SR=0; TI=SMTPD_---.7Fu.bS2_1480852956; Received: from localhost.localdomain(mailfrom:ligs@dtdream.com ip:111.198.29.132) by smtp.aliyun-inc.com(10.147.40.7); Sun, 04 Dec 2016 20:02:37 +0800 From: Guoshuai Li To: ovs-dev@openvswitch.org Date: Sun, 4 Dec 2016 20:02:29 +0800 Message-Id: <20161204120229.2860-1-ligs@dtdream.com> X-Mailer: git-send-email 2.10.1.windows.1 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RDNS_NONE, UNPARSEABLE_RELAY autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Guoshuai Li Subject: [ovs-dev] [PATCH V2] python: Fix The SSL connection is not reconnected when the OVSDB Server is restarted X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org When the SSL connection is disconnected by the peer the client's do_handshake() function throws the exception OpenSSL.SSL.SysCallError we need to catch the exception and return the exception errno so that the SSL connection can be reconnected. And the recv() function throws the exception OpenSSL.SSL.ZeroReturnError This exception refers to TCP connection normal closed, return (0, "") --- python/ovs/stream.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/ovs/stream.py b/python/ovs/stream.py index b43e105..abb1b8e 100644 --- a/python/ovs/stream.py +++ b/python/ovs/stream.py @@ -451,6 +451,8 @@ class SSLStream(Stream): self.socket.do_handshake() except SSL.WantReadError: return errno.EAGAIN + except SSL.SysCallError as e: + return ovs.socket_util.get_exception_errno(e) return 0 @@ -459,6 +461,8 @@ class SSLStream(Stream): return super(SSLStream, self).recv(n) except SSL.WantReadError: return (errno.EAGAIN, "") + except SSL.ZeroReturnError: + return (0, "") def send(self, buf): try: