Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3339402iog; Mon, 20 Jun 2022 17:43:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tdS9F9ICa7JVJjpUq65ITeJAxEij3lDcPUNbNeT+iSXCteOtqoeeFv00EY6RB7nY7/N1KZ X-Received: by 2002:a17:90b:4382:b0:1ea:f4b6:1e29 with SMTP id in2-20020a17090b438200b001eaf4b61e29mr27521563pjb.159.1655772232702; Mon, 20 Jun 2022 17:43:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655772232; cv=none; d=google.com; s=arc-20160816; b=dCoIBSz2QFgzh41c0LGZb9bK64J2stjlRV19u9wZWoQcq+13+1lTcTw6L6ABFx9rXl PLLv7JCImwqbjuXhWVCKCF4CaKKw2HvJQzUJV2MJTcgmVdHOHb20fTwEqQrXshlt5mIZ bKnZu8BMVcukBRDkulF2Aquz0cHkcDi0D6u7feVdBRQ0wlyBmA/27+LNC5jcn/iJszuH UJy2KpKhZ9noLlJSYD9oCI+2d2/gy4UqBoF1p9sBlkfEvVWCzf+jxx2L2fX6S1oQcO+t fxdbvghC6j8YrPYr2QtE2nAQpEchtgOvn5sG/aMMe1rdwQZpVdQkxs8di4o8Bp1YN/7a 3wwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:message-id:subject:reply-to:from:to:dkim-signature:date; bh=KP4otxWVhQW8iB5l/zwSnHapuVrUU7ofdACUxCcrn7I=; b=YbyOpG2sSo6PInKn+YLG0G/4WrBlx8SlmAYhuPR0bLxrt/UdqKrp1Cd18xC6ExYCv4 jV3sXND0HJXd9VZJCIS1AfbXvszcWNx1YdSNq9EOaqn5Q+rbqu9Mkc9COO0BMqVm3xbc Czkp41ajef/dgvAZ/qk+jbqxlegETqaU5hkrb7LtYpYJ12HiAtLhl9RKYChXwhW0npWU 6TbO/tTGFWAy55cchbmT/lFGSIKUeZXVkhMz7FYwLpweRhd49M8z4BfuI2YJxSqe2BuG Z5hPNqWJhufB7KIgX6G0uB0rvMSXXRfDTbIKYvq6EiZhpER3hiXc3301t3dJDYUt4JmI kIqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b="x9H2OR/u"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i1-20020a170902c94100b0016762ae2914si2949304pla.191.2022.06.20.17.43.39; Mon, 20 Jun 2022 17:43:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b="x9H2OR/u"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240120AbiFUA3j (ORCPT + 99 others); Mon, 20 Jun 2022 20:29:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233015AbiFUA3h (ORCPT ); Mon, 20 Jun 2022 20:29:37 -0400 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 760DB20F78 for ; Mon, 20 Jun 2022 17:29:34 -0700 (PDT) Date: Tue, 21 Jun 2022 00:29:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1655771372; x=1656030572; bh=KP4otxWVhQW8iB5l/zwSnHapuVrUU7ofdACUxCcrn7I=; h=Date:To:From:Reply-To:Subject:Message-ID:Feedback-ID:From:To:Cc: Date:Subject:Reply-To:Feedback-ID:Message-ID; b=x9H2OR/u31qzawfH5gCI6p2JsQ5s8Ltq5J4GMPD9TdoneToj23qm2CVezFCCwpbSU 3CAN8kyEyqY+2YjW7rGHQ8DEbrvFlJoRoJRZAS+5jKvWN4ElBdaIomTOHbER3yZne5 hMGZQg5F9owZmJDWxMURv2HVeupWvZssRu6t9vYQjUkLyijFWdfOn53JV2z3dHXnt+ XqDVKl/hLLrbsvDYdJXWyKoDeq51l9ZahnrVX7Jh3+fvZ+qpdFWqTRuppelU6fG414 A+iB+MrJc45RFv5O363WQMmhOjhy0Id3D63N1uwFHgd6dT59FPtenD5czTLBiOG7pc LdaVf9zqONpoA== To: linux-kernel From: "Ryan P. Nicholl" Reply-To: "Ryan P. Nicholl" Subject: Networking Question Message-ID: <6_nVwntZEyEq2Gn0PYDz5w_yuD20E9Je_Bk2rJHsOersGq3v2x3_6hXnyjNm-X83-OTl1KKo4eLoHzyBVM_nzCcDrpPtz4dz3_71A3QezfI=@protonmail.com> Feedback-ID: 15386781:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I've been unable to find any Linux API for asynchronously waiting for the T= CP send buffer to drain. The problem I have, in a nutshell, is noted in this part of the documentati= on: If fildes refers to a socket, close() shall cause the socket to be destroyed. If the socket is in connection-mode, and the SO_LINGER option is set for the socket with non-zero linger time, and the socket has untransmitted data, then close() shall block for up to the current linger interval until all data is transmitted. Ok, so not good for asynchronous programming, so I could disable the SO_LIN= GER option, but that leaves me with another problem, namely that I *want* t= he socket to linger. The behavior I want is something like, calling "close", getting EAGAIN inst= ead of triggering TCP RST, and something like EPOLLWRITEFLUSHED to wait for= the TCP send buffer to be drained. I know neither of these are possible. Right now the only solution I can think of is to enable SO_LINGER and spawn= a thread to run close in, but this might spawn a lot of threads, and doesn= 't support cancellation well. Alternatively, I could call getsockopt with TCP_INFO in a loop, but this tr= iggers a lot of wake-ups and might result in sockets hanging around a lot l= onger than they need to. I want to allow linger indefinitely on close until some event happens like = running out of ram or other resources, basically to intelligently do someth= ing like: "OK, we're running low on RAM/resources, time to send RST and dro= p the send buffer for the 5k worst behaving connections". So unfortunately = even with the timeout provided by SO_LINGER, even assuming close would some= how complete in the background, this could be an issue. Is there any way to do this properly on Linux? If not, any possibility that= something like adding EPOLLWRITEFLUSHED would be a welcome addition? Please CC me on responses. -- Ryan P. Nicholl