Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2639456rdg; Mon, 16 Oct 2023 10:07:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJv9GmCBpyz07JIlePYgqRFWime/13PSlIvIqd8dgRJe+oKRK8UuDjmsdcT4UhFCCvJVDB X-Received: by 2002:a17:902:e847:b0:1c2:193e:1126 with SMTP id t7-20020a170902e84700b001c2193e1126mr36176plg.28.1697476063660; Mon, 16 Oct 2023 10:07:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697476063; cv=none; d=google.com; s=arc-20160816; b=lhx2btodyi/TsOtdOj/IJzWoUM47sAc5H3Vg57xSOQh92DtpSOqoZrNADXepx3EaHa ZGFXn2GdGCaOjqqEUWeVrPdrygoOWsIujUrlfcr0MLKCPREP+gDLrqHTSY8+31WThsiT fSIXusLP5vdiVi2m0mkNT1bub8CPr3F30QPVx4SSZ3FgOfCOeXPsQQvcmuVe4m72/BNG K+kIWUwnIaHiZrNZq/ran/kIO2V+GUMSY4rA2AaTa79qFSQah6+JSGNhRQXrmHeWw0QO KmkUpqoogK6NqbxDwbIIXOWZuT8lhNrMJ1ZU1bRNBCjMkmj2Q7KGgco9bD5k/v+8ONbu IWng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=GMmQ1XM/tfeoRy7kS7mGhqo9rIvkstFPQCOPcoIFSyU=; fh=xJv+Klyytov3KGiQwAoOi4HC6j6hVaI+tOcmqPTIfBg=; b=POy8MU8kyRMvIp/QFRTXk8Rtx7Q3Jpcet7OnXJ4kZ6+lqiZgvUXNG5HAnPHHUKThke XfQGcfGRL8K8HgjOMhlbDhFgtgg1uKl8wyKzHP1PgLNJ+dM8nYYqcyr5LJjceIBT3O6z Z2KTQdku1Mxv16qaF16U1Yxt26iwufASgWi1So+hTMkM1tN2zGVQXhBY7BWr2ZSJ8Zl2 F+J4X4O9vVaPbQpN2J8p8rnzT2BppcBDp1c7C5l720tppqKJ007D5WOTOwUjb/6drPFo yBzRZFhjQsYl8yaQIpwitO7R9pbTy9TiPH7FGkBUAJvnLlUdzriqPiyOj9O+IjYMkc+v msQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jFppFaHX; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id d8-20020a170902654800b001c5e0672f53si10843861pln.466.2023.10.16.10.07.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 10:07:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jFppFaHX; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 6378680681C4; Mon, 16 Oct 2023 10:07:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234279AbjJPRHe (ORCPT + 99 others); Mon, 16 Oct 2023 13:07:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234098AbjJPRHY (ORCPT ); Mon, 16 Oct 2023 13:07:24 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5B151730 for ; Mon, 16 Oct 2023 10:05:47 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2c50fbc218bso33827781fa.3 for ; Mon, 16 Oct 2023 10:05:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697475946; x=1698080746; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=GMmQ1XM/tfeoRy7kS7mGhqo9rIvkstFPQCOPcoIFSyU=; b=jFppFaHX8gfUxZvEJvm0dbivbMpstab/ugQJckDYKtAS4IfjmNQ2IzxvETknRvufG2 7yFBGXauHemxW++DOajH67kieupDT63ZNE3I12RQ3tH4xg7eJXeOoHtFDYxjeyrQe7C4 bPpCeWpupI1AsUvKECiOX1WshnJoDvgGItKjPfZ1zRXfb0wlUeS4rEsGmg1SVaw2xvGl KX8mCNVdk89Uprr4Nms17I2OP/EwAIp9hFGRLaIIod1tBNOM3q/7QJEKS3nE+45Eewij V6vi1qPbxjOl2Ok1kvrNHHj7Bl4vJZ2UHGlbCq8RXrMBhN/BjAk5mRcziAsSqesfGiEp lVIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697475946; x=1698080746; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GMmQ1XM/tfeoRy7kS7mGhqo9rIvkstFPQCOPcoIFSyU=; b=MD+QruxtbuqU4tzg3LE0YnxmKustbTV0C+R6Jw8KwMh/pQtCRx3yXwBUx2M52w+nLO jp6Av+6vN0GQBhUmkeLv9oJes4JH1bCpuDE2QROkXefdYHvcP3F9VFqSNenJoyQoINuw Pslkk7qPU1IiR+PVKtMwz+6sF1/NOQ2nRaaZVZXiCpFuYvzoo9+5BQ3INUWWjUpPdAkA 8Z5n5vtjh9j8h8e4lK2cUYzHvrFP/axUaqMoHMFkQtN4rItWAg16V0sUVE5WlZzDMziW f6MUvHIrwH80Vpf2LD4KzGMYryqYa6Rgdw0+B2oKmxoMLE/S28JR3EZzs8DO1N3o8rWa pC7g== X-Gm-Message-State: AOJu0YzedV3zsTbX+0jipcV3MD7871Ptj94XoyvtkQScTfN6aPoIoz5Y 7jNLEIQv5A123P/xyk/G5joJL9KR/XM2DEecaQg= X-Received: by 2002:a05:651c:a11:b0:2c5:1037:b54d with SMTP id k17-20020a05651c0a1100b002c51037b54dmr8590133ljq.31.1697475945569; Mon, 16 Oct 2023 10:05:45 -0700 (PDT) MIME-Version: 1.0 References: <20231016154900.3094-1-iulia.tanasescu@nxp.com> <20231016154900.3094-3-iulia.tanasescu@nxp.com> In-Reply-To: <20231016154900.3094-3-iulia.tanasescu@nxp.com> From: Luiz Augusto von Dentz Date: Mon, 16 Oct 2023 10:04:59 -0700 Message-ID: Subject: Re: [PATCH BlueZ 2/4] shared/bass: Handle G_IO_HUP on io channels To: Iulia Tanasescu Cc: linux-bluetooth@vger.kernel.org, claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, silviu.barbulescu@nxp.com, vlad.pruteanu@nxp.com, andrei.istodorescu@nxp.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 16 Oct 2023 10:07:35 -0700 (PDT) Hi Iulia, On Mon, Oct 16, 2023 at 8:49=E2=80=AFAM Iulia Tanasescu wrote: > > This adds watches to handle closed sockets > > --- > src/shared/bass.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++ > src/shared/bass.h | 2 ++ > 2 files changed, 61 insertions(+) > > diff --git a/src/shared/bass.c b/src/shared/bass.c > index 0ee3187d1..78103d463 100644 > --- a/src/shared/bass.c > +++ b/src/shared/bass.c > @@ -655,6 +655,11 @@ static void connect_cb(GIOChannel *io, GError *gerr, > g_io_channel_unref(bcast_src->listen_io); > bcast_src->listen_io =3D NULL; > > + if (bcast_src->listen_io_id > 0) { > + g_source_remove(bcast_src->listen_io_id); > + bcast_src->listen_io_id =3D 0; > + } > + > /* Close pa sync io */ > if (bcast_src->pa_sync_io) { > g_io_channel_shutdown(bcast_src->pa_sync_io, > @@ -663,6 +668,11 @@ static void connect_cb(GIOChannel *io, GError *gerr, > bcast_src->pa_sync_io =3D NULL; > } > > + if (bcast_src->pa_sync_io_id > 0) { > + g_source_remove(bcast_src->pa_sync_io_id); > + bcast_src->pa_sync_io_id =3D 0; > + } > + > for (i =3D 0; i < bcast_src->num_subgroups; i++) > bcast_src->subgroup_data[i].bis_sync =3D > BT_BASS_BIG_SYNC_FAILED_BITMASK; > @@ -703,6 +713,18 @@ static bool bass_trigger_big_sync(struct bt_bcast_sr= c *bcast_src) > return false; > } > > +static gboolean pa_sync_io_disconnect_cb(GIOChannel *io, GIOCondition co= nd, > + gpointer data) > +{ > + struct bt_bcast_src *bcast_src =3D data; > + > + DBG(bcast_src->bass, "PA sync io has been disconnected"); > + > + bcast_src->pa_sync_io_id =3D 0; > + bcast_src->pa_sync_io =3D NULL; > + > + return FALSE; > +} > > static void confirm_cb(GIOChannel *io, gpointer user_data) > { > @@ -726,6 +748,15 @@ static void confirm_cb(GIOChannel *io, gpointer user= _data) > bcast_src->pa_sync_io =3D io; > g_io_channel_ref(bcast_src->pa_sync_io); > > + if (bcast_src->pa_sync_io_id > 0) { > + g_source_remove(bcast_src->pa_sync_io_id); > + bcast_src->pa_sync_io_id =3D 0; > + } > + > + bcast_src->pa_sync_io_id =3D g_io_add_watch(io, G_IO_ERR | G_IO_H= UP | > + G_IO_NVAL, (GIOFunc) pa_sync_io_disconnec= t_cb, > + bcast_src); > + > len =3D sizeof(qos); > memset(&qos, 0, len); > > @@ -844,6 +875,19 @@ static bool bass_validate_add_src_params(uint8_t *va= lue, size_t len) > return true; > } > > +static gboolean listen_io_disconnect_cb(GIOChannel *io, GIOCondition con= d, > + gpointer data) > +{ > + struct bt_bcast_src *bcast_src =3D data; > + > + DBG(bcast_src->bass, "Listen io has been disconnected"); > + > + bcast_src->listen_io_id =3D 0; > + bcast_src->listen_io =3D NULL; > + > + return FALSE; > +} > + > static void bass_handle_add_src_op(struct bt_bass *bass, > struct gatt_db_attribute *attrib, > uint8_t opcode, > @@ -1023,6 +1067,11 @@ static void bass_handle_add_src_op(struct bt_bass = *bass, > bcast_src->listen_io =3D io; > g_io_channel_ref(bcast_src->listen_io); > > + bcast_src->listen_io_id =3D g_io_add_watch(io, G_IO_ERR | > + G_IO_HUP | G_IO_NVAL, > + (GIOFunc)listen_io_disconnect_cb, > + bcast_src); IO handling shall probably be kept outside of shared so we could emulate it with use of socketpairs and unit test it, see how it was done for bap. > if (num_bis > 0 && !bcast_src->bises) > bcast_src->bises =3D queue_new(); > } else { > @@ -1318,11 +1367,21 @@ static void bass_bcast_src_free(void *data) > g_io_channel_unref(bcast_src->listen_io); > } > > + if (bcast_src->listen_io_id > 0) { > + g_source_remove(bcast_src->listen_io_id); > + bcast_src->listen_io_id =3D 0; > + } > + > if (bcast_src->pa_sync_io) { > g_io_channel_shutdown(bcast_src->pa_sync_io, TRUE, NULL); > g_io_channel_unref(bcast_src->pa_sync_io); > } > > + if (bcast_src->pa_sync_io_id > 0) { > + g_source_remove(bcast_src->pa_sync_io_id); > + bcast_src->pa_sync_io_id =3D 0; > + } > + > queue_destroy(bcast_src->bises, bass_bis_unref); > > free(bcast_src); > diff --git a/src/shared/bass.h b/src/shared/bass.h > index c4b5b76ba..bd3fe900b 100644 > --- a/src/shared/bass.h > +++ b/src/shared/bass.h > @@ -57,7 +57,9 @@ struct bt_bcast_src { > uint8_t num_subgroups; > struct bt_bass_subgroup_data *subgroup_data; > GIOChannel *listen_io; > + guint listen_io_id; > GIOChannel *pa_sync_io; > + guint pa_sync_io_id; > struct queue *bises; > }; > > -- > 2.39.2 > --=20 Luiz Augusto von Dentz