From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 56E658DB3 for ; Wed, 9 Sep 2015 07:31:25 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP; 08 Sep 2015 22:31:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,494,1437462000"; d="scan'208";a="641221937" Received: from yliu-dev.sh.intel.com ([10.239.66.60]) by orsmga003.jf.intel.com with ESMTP; 08 Sep 2015 22:31:24 -0700 From: Yuanhan Liu To: dev@dpdk.org Date: Wed, 9 Sep 2015 13:34:35 +0800 Message-Id: <1441776876-14595-3-git-send-email-yuanhan.liu@linux.intel.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1441776876-14595-1-git-send-email-yuanhan.liu@linux.intel.com> References: <1441776876-14595-1-git-send-email-yuanhan.liu@linux.intel.com> Subject: [dpdk-dev] [PATCH 3/4] vhost: get rid of duplicate code X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Sep 2015 05:31:25 -0000 Signed-off-by: Yuanhan Liu Acked-by: Changchun Ouyang Acked-by: Huawei Xie --- lib/librte_vhost/vhost_user/vhost-net-user.c | 36 ++++++++-------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c index f406a94..d1f8877 100644 --- a/lib/librte_vhost/vhost_user/vhost-net-user.c +++ b/lib/librte_vhost/vhost_user/vhost-net-user.c @@ -329,32 +329,16 @@ vserver_message_handler(int connfd, void *dat, int *remove) ctx.fh = cfd_ctx->fh; ret = read_vhost_message(connfd, &msg); - if (ret < 0) { - RTE_LOG(ERR, VHOST_CONFIG, - "vhost read message failed\n"); - - close(connfd); - *remove = 1; - free(cfd_ctx); - user_destroy_device(ctx); - ops->destroy_device(ctx); - - return; - } else if (ret == 0) { - RTE_LOG(INFO, VHOST_CONFIG, - "vhost peer closed\n"); - - close(connfd); - *remove = 1; - free(cfd_ctx); - user_destroy_device(ctx); - ops->destroy_device(ctx); - - return; - } - if (msg.request > VHOST_USER_MAX) { - RTE_LOG(ERR, VHOST_CONFIG, - "vhost read incorrect message\n"); + if (ret <= 0 || msg.request > VHOST_USER_MAX) { + if (ret < 0) + RTE_LOG(ERR, VHOST_CONFIG, + "vhost read message failed\n"); + else if (ret == 0) + RTE_LOG(INFO, VHOST_CONFIG, + "vhost peer closed\n"); + else + RTE_LOG(ERR, VHOST_CONFIG, + "vhost read incorrect message\n"); close(connfd); *remove = 1; -- 1.9.0