From patchwork Wed Oct 8 22:19:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hefty, Sean" X-Patchwork-Id: 5055801 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9BAC5C11AC for ; Wed, 8 Oct 2014 22:20:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D91BB2012F for ; Wed, 8 Oct 2014 22:20:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BD62120123 for ; Wed, 8 Oct 2014 22:20:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933767AbaJHWU0 (ORCPT ); Wed, 8 Oct 2014 18:20:26 -0400 Received: from mga02.intel.com ([134.134.136.20]:54937 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932253AbaJHWU0 (ORCPT ); Wed, 8 Oct 2014 18:20:26 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 08 Oct 2014 15:19:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,681,1406617200"; d="scan'208";a="585655722" Received: from cst-linux.jf.intel.com ([10.23.221.72]) by orsmga001.jf.intel.com with ESMTP; 08 Oct 2014 15:19:48 -0700 From: sean.hefty@intel.com To: linux-rdma@vger.kernel.org, srkodali@linux.vnet.ibm.com Cc: Sean Hefty Subject: [PATCH] rsocket: Return ECONNRESET when socket in recv is disconnected Date: Wed, 8 Oct 2014 15:19:33 -0700 Message-Id: <1412806773-23776-1-git-send-email-sean.hefty@intel.com> X-Mailer: git-send-email 1.7.3 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sean Hefty The following behavior difference was reported between rsockets and sockets: when remote end is suddenly closed, recv() waiting on it receives tcp/ip => ECONNRESET error rsockets => 0 value Update rrecv() to return ECONNRESET if no data is available and the connection is no longer readable. Problem reported by: srkodali@linux.vnet.ibm.com Signed-off-by: Sean Hefty --- src/rsocket.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/rsocket.c b/src/rsocket.c index 074fb18..7c7af52 100644 --- a/src/rsocket.c +++ b/src/rsocket.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2013 Intel Corporation. All rights reserved. + * Copyright (c) 2008-2014 Intel Corporation. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU @@ -2394,7 +2394,7 @@ ssize_t rrecv(int socket, void *buf, size_t len, int flags) struct rsocket *rs; size_t left = len; uint32_t end_size, rsize; - int ret; + int ret = 0; rs = idm_at(&idm, socket); if (rs->type == SOCK_DGRAM) { @@ -2419,9 +2419,11 @@ ssize_t rrecv(int socket, void *buf, size_t len, int flags) rs_conn_have_rdata); if (ret) break; + + if (!(rs->state & rs_readable)) + ret = ERR(ECONNRESET); } - ret = 0; if (flags & MSG_PEEK) { left = len - rs_peek(rs, buf, left); break; @@ -2456,7 +2458,7 @@ ssize_t rrecv(int socket, void *buf, size_t len, int flags) } while (left && (flags & MSG_WAITALL) && (rs->state & rs_readable)); fastlock_release(&rs->rlock); - return ret ? ret : len - left; + return (ret && left == len) ? ret : len - left; } ssize_t rrecvfrom(int socket, void *buf, size_t len, int flags,