From patchwork Wed Jun 4 15:20:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Goode X-Patchwork-Id: 4295021 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2F97E9F1D6 for ; Wed, 4 Jun 2014 15:21:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3B961201DE for ; Wed, 4 Jun 2014 15:21:30 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id B98BA200F3 for ; Wed, 4 Jun 2014 15:21:28 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id E1D52265112; Wed, 4 Jun 2014 17:21:26 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id A4B0F265086; Wed, 4 Jun 2014 17:21:15 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 209B6265090; Wed, 4 Jun 2014 17:21:15 +0200 (CEST) Received: from mail-yh0-f43.google.com (mail-yh0-f43.google.com [209.85.213.43]) by alsa0.perex.cz (Postfix) with ESMTP id B349B265071 for ; Wed, 4 Jun 2014 17:21:06 +0200 (CEST) Received: by mail-yh0-f43.google.com with SMTP id v1so6528344yhn.30 for ; Wed, 04 Jun 2014 08:21:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=Dnf3xlmYHjswPNJnyHy0FQp7n8MkSpK/qQm2bL2G0x4=; b=Wcarc66U1SLoOuujpF+7wW8ZmJz0D8f0AxgkmVo0j2ii4JDyk+9EgqXZrcMlfK/Hm/ XWsaMf6FgyeDKxnSFgBTK/IbYYwFYmJka2btG69zqE6oPUe2T9v+haBoFdFaKIwzvU8Z KACK73XFuIiouQ7w4VDZnzIH9/9nw2Ip7XYhUpwLbRiniQIanD0ghznKyvSnf15t7T50 XOLsGQJELFGfRf8ByTculsntjvVJMlK4xVphpMeMm+d1SumkZnuo4daQrdyO/G7+2YEG 2QmvBkJq3EUCWrLjl+wxGO5NXRSaqwFQC9xZgQ4jdiJM5uoU4pQmLxhM5b9NUxjqUcVX 3ioA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Dnf3xlmYHjswPNJnyHy0FQp7n8MkSpK/qQm2bL2G0x4=; b=Sqswt4cYOx4O4z+o2rBm1vUMYBUFHDZbgt/z1SUEg8qjNrEMvJ3unSwCORAZoSJsfx AXTThmAaRhMZMhLLJ5nN1zwfGxIkp4+pHcEqb9CFShFwkNa6pfKvFDZMvK3SYGDWSe+F 9ei6DQ3yxCKQHkWwwJlSN2anSZhCpZZMMe7fZdqikiczVnubNX4wwFrU2o9RwNzN4HYQ wDAxGOWgQM9/mUXdKL76iOHxO0iPL1A/xYg2mOGRBRohnq9KfX1tEi6eOg0fSEVPpYSy WZEtZ6hMEI2UeYmGi2aHKUj6HxEfERr4OVvrMbCCEBMNGrDRiGr8hFh2A+5EuOdxZ/FD u1Bw== X-Gm-Message-State: ALoCoQnEl8is9N6/v4zjKdCYof8jLMRkYsMK0ASPpbLooo2QRm/0ELLGyX6w5T+Mjhe2tPsnw8/Y X-Received: by 10.236.31.39 with SMTP id l27mr74111007yha.7.1401895265319; Wed, 04 Jun 2014 08:21:05 -0700 (PDT) Received: from wpg-ubiq154.hot.corp.google.com (wpg-ubiq154.hot.corp.google.com [172.24.166.195]) by mx.google.com with ESMTPSA id x12sm388033yhe.53.2014.06.04.08.21.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Jun 2014 08:21:04 -0700 (PDT) From: Adam Goode To: patch@alsa-project.org Date: Wed, 4 Jun 2014 11:20:55 -0400 Message-Id: <1401895255-25348-1-git-send-email-agoode@google.com> X-Mailer: git-send-email 2.0.0.526.g5318336 Cc: Adam Goode , alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH v2 1/1] ALSA: seq: Continue broadcasting events to ports if one of them fails X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Sometimes PORT_EXIT messages are lost when a process is exiting. This happens if you subscribe to the announce port with client A, then subscribe to the announce port with client B, then kill client A. Client B will not see the PORT_EXIT message because client A's port is closing and is earlier in the announce port subscription list. The for each loop will try to send the announcement to client A and fail, then will stop trying to broadcast to other ports. Killing B works fine since the announcement will already have gone to A. The CLIENT_EXIT message does not get lost. How to reproduce problem: *** termA $ aseqdump -p 0:1 0:1 Port subscribed 0:1 -> 128:0 *** termB $ aseqdump -p 0:1 *** termA 0:1 Client start client 129 0:1 Port start 129:0 0:1 Port subscribed 0:1 -> 129:0 *** termB 0:1 Port subscribed 0:1 -> 129:0 *** termA ^C *** termB 0:1 Client exit client 128 <--- expected Port exit as well (before client exit) Signed-off-by: Adam Goode diff --git a/sound/core/seq/seq_clientmgr.c b/sound/core/seq/seq_clientmgr.c index 9ca5e64..225c7315 100644 --- a/sound/core/seq/seq_clientmgr.c +++ b/sound/core/seq/seq_clientmgr.c @@ -660,7 +660,7 @@ static int deliver_to_subscribers(struct snd_seq_client *client, int atomic, int hop) { struct snd_seq_subscribers *subs; - int err = 0, num_ev = 0; + int err, result = 0, num_ev = 0; struct snd_seq_event event_saved; struct snd_seq_client_port *src_port; struct snd_seq_port_subs_info *grp; @@ -685,8 +685,12 @@ static int deliver_to_subscribers(struct snd_seq_client *client, subs->info.flags & SNDRV_SEQ_PORT_SUBS_TIME_REAL); err = snd_seq_deliver_single_event(client, event, 0, atomic, hop); - if (err < 0) - break; + if (err < 0) { + /* save first error that occurs and continue */ + if (!result) + result = err; + continue; + } num_ev++; /* restore original event record */ *event = event_saved; @@ -697,7 +701,7 @@ static int deliver_to_subscribers(struct snd_seq_client *client, up_read(&grp->list_mutex); *event = event_saved; /* restore */ snd_seq_port_unlock(src_port); - return (err < 0) ? err : num_ev; + return (result < 0) ? result : num_ev; } @@ -709,7 +713,7 @@ static int port_broadcast_event(struct snd_seq_client *client, struct snd_seq_event *event, int atomic, int hop) { - int num_ev = 0, err = 0; + int num_ev = 0, err, result = 0; struct snd_seq_client *dest_client; struct snd_seq_client_port *port; @@ -724,14 +728,18 @@ static int port_broadcast_event(struct snd_seq_client *client, err = snd_seq_deliver_single_event(NULL, event, SNDRV_SEQ_FILTER_BROADCAST, atomic, hop); - if (err < 0) - break; + if (err < 0) { + /* save first error that occurs and continue */ + if (!result) + result = err; + continue; + } num_ev++; } read_unlock(&dest_client->ports_lock); snd_seq_client_unlock(dest_client); event->dest.port = SNDRV_SEQ_ADDRESS_BROADCAST; /* restore */ - return (err < 0) ? err : num_ev; + return (result < 0) ? result : num_ev; } /* @@ -741,7 +749,7 @@ static int port_broadcast_event(struct snd_seq_client *client, static int broadcast_event(struct snd_seq_client *client, struct snd_seq_event *event, int atomic, int hop) { - int err = 0, num_ev = 0; + int err, result = 0, num_ev = 0; int dest; struct snd_seq_addr addr; @@ -760,12 +768,16 @@ static int broadcast_event(struct snd_seq_client *client, err = snd_seq_deliver_single_event(NULL, event, SNDRV_SEQ_FILTER_BROADCAST, atomic, hop); - if (err < 0) - break; + if (err < 0) { + /* save first error that occurs and continue */ + if (!result) + result = err; + continue; + } num_ev += err; } event->dest = addr; /* restore */ - return (err < 0) ? err : num_ev; + return (result < 0) ? result : num_ev; }