From patchwork Fri Jan 21 14:39:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Crequy X-Patchwork-Id: 79846 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 315E9B7105 for ; Sat, 22 Jan 2011 01:44:39 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753742Ab1AUOnO (ORCPT ); Fri, 21 Jan 2011 09:43:14 -0500 Received: from bhuna.collabora.co.uk ([93.93.128.226]:57142 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753554Ab1AUOnN (ORCPT ); Fri, 21 Jan 2011 09:43:13 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: alban) with ESMTPSA id F289BC0822D From: Alban Crequy To: "David S. Miller" , Eric Dumazet , Lennart Poettering , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Alban Crequy , Ian Molton Cc: Alban Crequy Subject: [PATCH 7/8] af_unix: implement poll(POLLOUT) for multicast sockets Date: Fri, 21 Jan 2011 14:39:47 +0000 Message-Id: <1295620788-6002-7-git-send-email-alban.crequy@collabora.co.uk> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <20110121143751.57b1453d@chocolatine.cbg.collabora.co.uk> References: <20110121143751.57b1453d@chocolatine.cbg.collabora.co.uk> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When a socket subscribed to a multicast group has its incoming queue full, it can either block the emission to the multicast group or let the messages be dropped. The latter is useful to monitor all messages without slowing down the traffic. It is specified with the flag UNIX_MREQ_DROP_WHEN_FULL when the multicast group is joined. poll(POLLOUT) is implemented by checking all receiving queues of subscribed sockets. If only one of them has its receiving queue full and does not have UNIX_MREQ_DROP_WHEN_FULL, the multicast socket is not writeable. Signed-off-by: Alban Crequy Reviewed-by: Ian Molton --- net/unix/af_unix.c | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-) diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 4147d64..138d9a2 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -2940,6 +2940,11 @@ static unsigned int unix_dgram_poll(struct file *file, struct socket *sock, { struct sock *sk = sock->sk, *other; unsigned int mask, writable; +#ifdef CONFIG_UNIX_MULTICAST + struct sock_set *others; + int err = 0; + int i; +#endif sock_poll_wait(file, sk_sleep(sk), wait); mask = 0; @@ -2980,6 +2985,34 @@ static unsigned int unix_dgram_poll(struct file *file, struct socket *sock, sock_put(other); } +#ifdef CONFIG_UNIX_MULTICAST + /* + * On multicast sockets, we need to check if the receiving queue is + * full on all peers who don't have UNIX_MREQ_DROP_WHEN_FULL. + */ + if (!other || !unix_sk(other)->mcast_group) + goto skip_multicast; + others = unix_find_multicast_recipients(sk, + unix_sk(other)->mcast_group, &err); + if (!others) + goto skip_multicast; + for (i = others->offset ; i < others->cnt ; i++) { + if (others->items[i].flags & UNIX_MREQ_DROP_WHEN_FULL) + continue; + if (unix_peer(others->items[i].s) != sk) { + sock_poll_wait(file, + &unix_sk(others->items[i].s)->peer_wait, wait); + if (unix_recvq_full(others->items[i].s)) { + writable = 0; + break; + } + } + } + up_sock_set(others); + +skip_multicast: +#endif + if (writable) mask |= POLLOUT | POLLWRNORM | POLLWRBAND; else