From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 33D0760300 for ; Tue, 1 Feb 2022 14:17:36 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1C0622BE for ; Tue, 1 Feb 2022 14:17:06 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 58A032B3 for ; Tue, 1 Feb 2022 14:17:05 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 27A7B42487 for ; Tue, 1 Feb 2022 14:17:05 +0100 (CET) Date: Tue, 1 Feb 2022 14:17:04 +0100 From: Wolfgang Bumiller To: Thomas Lamprecht Cc: Dominik Csapak , Proxmox Backup Server development discussion Message-ID: <20220201131704.df62rongokade73v@olga.proxmox.com> References: <20220117104825.2409598-1-d.csapak@proxmox.com> <20220117104825.2409598-4-d.csapak@proxmox.com> <10964093-6e3e-363c-e2d0-f30b25c20ac2@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-SPAM-LEVEL: Spam detection results: 0 AWL 0.401 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: Re: [pbs-devel] [PATCH proxmox v4 3/4] proxmox-async: add connect_to_udp helper X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2022 13:17:36 -0000 On Tue, Feb 01, 2022 at 01:39:00PM +0100, Thomas Lamprecht wrote: > On 01.02.22 13:13, Dominik Csapak wrote: > > On 2/1/22 13:02, Thomas Lamprecht wrote: > >>> +    addr: A, > >>> +) -> io::Result { > >>> +    let socket = match tokio::net::lookup_host(&addr).await?.next() {> +        Some(SocketAddr::V4(_)) => UdpSocket::bind("0.0.0.0:0").await?, > >>> +        Some(SocketAddr::V6(_)) => UdpSocket::bind("[::]:0").await?, > >>> +        None => proxmox_sys::io_bail!("could not resolve address family {}", addr), > >> > >> would it have some merit to use {:?} to loose the Display trait bound? > >> Probably not to relevant though. > >> > > > > then we'd need the Debug trait though, so no real gain? > > > > hmm, thought that was implied, meh.. Normally one would want to pass it via the error > (type) upwards and let the caller handle it, but those error types can be stupid too... Just don't include it in the error and drop the additional trait requirement as this is supposed to provide what should be a standard function which wouldn't do that either. It should look & feel more like `std::net::TcpSocket::connect` / `tokio::net::TcpSocket::connect` already do. Also, please actually really loop over the addresses instead of just using the first one. Note that in `std` the error for not finding any address is currently[1]: Error::new(ErrorKind::InvalidInput, &"could not resolve to any addresses") and while I have a strong aversion against abusing system error types for something that doesn't actually come from a syscall (EINVAL in this case), in thise case we can even do the same since this should be part of std anyway... [1] https://github.com/rust-lang/rust/blob/74fbbefea8d13683cca5eee62e4740706cb3144a/library/std/src/net/mod.rs#L77