From patchwork Sun Dec 4 10:28:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guoshuai Li X-Patchwork-Id: 702410 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 3tWkm54F97z9tB1 for ; Sun, 4 Dec 2016 21:34:45 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 32154514; Sun, 4 Dec 2016 10:34:41 +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 1C2A14A5 for ; Sun, 4 Dec 2016 10:34:38 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp2203-239.mail.aliyun.com (smtp2203-239.mail.aliyun.com [121.197.203.239]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id C28CA124 for ; Sun, 4 Dec 2016 10:34:36 +0000 (UTC) X-Alimail-AntiSpam: AC=CONTINUE; BC=0.2702877|-1; FP=0|0|0|0|0|-1|-1|-1; HT=e02c03306; MF=ligs@dtdream.com; NM=1; PH=DS; RN=2; RT=2; SR=0; TI=SMTPD_---.7Fsvw6E_1480847302; Received: from localhost.localdomain(mailfrom:ligs@dtdream.com ip:111.198.29.132) by smtp.aliyun-inc.com(10.147.42.197); Sun, 04 Dec 2016 18:28:23 +0800 From: Guoshuai Li To: ovs-dev@openvswitch.org Date: Sun, 4 Dec 2016 18:28:17 +0800 Message-Id: <20161204102817.18056-1-ligs@dtdream.com> X-Mailer: git-send-email 2.10.1.windows.1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=ham 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] 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..68dffbc 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 as e: + return (0, "") def send(self, buf): try: