Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753912Ab2BTQd1 (ORCPT ); Mon, 20 Feb 2012 11:33:27 -0500 Received: from bhuna.collabora.co.uk ([93.93.135.160]:43229 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753734Ab2BTQdX (ORCPT ); Mon, 20 Feb 2012 11:33:23 -0500 From: Javier Martinez Canillas To: "David S. Miller" Cc: Eric Dumazet , Lennart Poettering , Kay Sievers , Alban Crequy , Bart Cerneels , Rodrigo Moya , Sjoerd Simons , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/10] af_unix: implement poll(POLLOUT) for multicast sockets Date: Mon, 20 Feb 2012 17:33:46 +0100 Message-Id: <1329755629-10644-4-git-send-email-javier@collabora.co.uk> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1329755629-10644-1-git-send-email-javier@collabora.co.uk> References: <1329755629-10644-1-git-send-email-javier@collabora.co.uk> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2903 Lines: 93 From: Alban Crequy 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 | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 47 insertions(+), 0 deletions(-) diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index a6b489c..bd9dc58 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -2974,6 +2974,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; @@ -3011,6 +3016,48 @@ static unsigned int unix_dgram_poll(struct file *file, struct socket *sock, if (unix_recvq_full(other)) writable = 0; } + +#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. + */ + + /* Don't let the group die under us */ + unix_state_lock(other); + if (sock_flag(other, SOCK_DEAD) + || !unix_sk(other)->mcast_group) { + unix_state_unlock(other); + goto skip_multicast; + } + atomic_inc(&unix_sk(other)->mcast_group->refcnt); + unix_state_unlock(other); + + others = unix_find_multicast_recipients(sk, + unix_sk(other)->mcast_group, &err); + if (!others) + goto skip_multicast_peers; + 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_peers: + if (atomic_dec_and_test(&unix_sk(other)->mcast_group->refcnt)) + destroy_mcast_group(unix_sk(other)->mcast_group); + +skip_multicast: +#endif sock_put(other); } -- 1.7.7.6 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/