From nobody Mon Aug 4 19:46:49 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4bwnBK4YTyz63RGB; Mon, 04 Aug 2025 19:46:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bwnBK2rZVz4Kdv; Mon, 04 Aug 2025 19:46:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754336809; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LoDxI60OM6GJ+c+MXr5HyY8d5CzoWKmFOwXluDCGCV4=; b=IXXnMFEBdmPN4+lX2Q8fSqABZ9A14lev7MGTG2C7HskhMgKXyYJyzoXzsNkZfct6Xvvvdj XrWkXi77p6R5VlcuaJVsQMYuwARLgxt67L2btlWM/j90ayu/zfwnpEhabfaqfBiu022xAu +WVtSf/cUjPf/S778JZb4IPJUCJp6X6B+MirSyi7dvdFAsnSRIyF5kPWOtbJDWB0glSqC8 mkZIAzZC/jCH2rMiTcgWTaNPeFl12xpCBbTBqhy523CI7jcPYuMl8cCNDDsDeHJieexQx4 h6gy8fdm8zfHz3W3OByxHdeNk/pGR/OG86QSQQ0+As81xpdejH7ibNYRqO0vHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754336809; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LoDxI60OM6GJ+c+MXr5HyY8d5CzoWKmFOwXluDCGCV4=; b=DkXJ99c7EgnJRXT6h8Xnk1tPwiR6p+UpD4Nh33tELwasfMJ6/r5XlsNctLfJsKc6+XaHKS l6GeXYPIGXreokkhNdg0sdm0cw/WGBon+94fTIE9w0OznKltoqLDLSHXcZdQf/SwDmA94w B6yIcXIioJsGRCSLz+XiDh+uZFTHPnIkPlpBDfxb833zdOX5iv9xTDI6EFjdfuvU+jWjK7 53+Hp81Z4Oi6WSyjUT7ovu027WbWhBqO7sK1c2piVMU5RIbWzjpRd9msoAo0V0XTGTQbl1 i7bnB2IjL3wwJrUMueXPdpjkfmRUrn1o8uSWmoGFAV2CSXACzGHJXT+KOI07bg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1754336809; a=rsa-sha256; cv=none; b=e13YBeSWcUMexz2kA8CPVOjtp9+ryHc6ugbACf6VBl7HVmONQEPskF/Q4lZmDXb8OquFE3 yAnBWi8UXIo3ch6hvdD0zzYVGgeLjNgCYSAVXcS0/gvVfEv0MM8UXH4Vj/HonT5TqvwTsq RF34FQyyzZ+VM9W6YgLAVLcB6CmTY3VnbcnDXuMHM8DdFSPiiIfv9IjKOKOKM5/zyKnzel 4LKi3dFxAGpDTu+Ip8hkyQLunYMUXgioyr+137MiZFEPwvA84BcsW4ZmVea0XjAlfx0kaL 2Ow0KxQXU4YbbAuPQqyAh+AU1Ev9l7fvcC6khyPVzk9Sz8SxCqBQGpFksQ27aQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4bwnBK2JbPz13BB; Mon, 04 Aug 2025 19:46:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 574Jkn6O099099; Mon, 4 Aug 2025 19:46:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 574JknC4099096; Mon, 4 Aug 2025 19:46:49 GMT (envelope-from git) Date: Mon, 4 Aug 2025 19:46:49 GMT Message-Id: <202508041946.574JknC4099096@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 22ce7be762ea - main - libutil++: Add freebsd::addrinfo_up wrapper class for std::unique_ptr<> List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 22ce7be762ea7b03a2c40ad52932023c69e1400f Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=22ce7be762ea7b03a2c40ad52932023c69e1400f commit 22ce7be762ea7b03a2c40ad52932023c69e1400f Author: John Baldwin AuthorDate: 2025-08-04 19:38:07 +0000 Commit: John Baldwin CommitDate: 2025-08-04 19:38:07 +0000 libutil++: Add freebsd::addrinfo_up wrapper class for std::unique_ptr<> This class uses a custom deleter that calls freeaddrinfo(). Sponsored by: Chelsio Communications Pull Request: https://github.com/freebsd/freebsd-src/pull/1794 --- lib/libutil++/Makefile | 1 + lib/libutil++/freebsd::addrinfo_up.3 | 45 ++++++++++++++++++++++++++++++++++++ lib/libutil++/libutil++.hh | 16 +++++++++++++ 3 files changed, 62 insertions(+) diff --git a/lib/libutil++/Makefile b/lib/libutil++/Makefile index ec83a9ad35f9..d53629b2e4e0 100644 --- a/lib/libutil++/Makefile +++ b/lib/libutil++/Makefile @@ -5,6 +5,7 @@ SHLIB_MAJOR= 1 SRCS= stringf.cc MAN+= freebsd::FILE_up.3 \ + freebsd::addrinfo_up.3 \ freebsd::malloc_up.3 \ freebsd::stringf.3 diff --git a/lib/libutil++/freebsd::addrinfo_up.3 b/lib/libutil++/freebsd::addrinfo_up.3 new file mode 100644 index 000000000000..4845a76bfb61 --- /dev/null +++ b/lib/libutil++/freebsd::addrinfo_up.3 @@ -0,0 +1,45 @@ +.\" +.\" SPDX-License-Identifier: BSD-2-Clause +.\" +.\" Copyright (c) 2025 Chelsio Communications, Inc. +.\" Written by: John Baldwin +.\" +.Dd July 31, 2025 +.Dt FREEBSD::ADDRINFO_UP 3 +.Os +.Sh NAME +.Nm freebsd::addrinfo_up +.Nd std::unique_ptr specialization for lists of socket addresses +.Sh LIBRARY +.Lb libutil++ +.Sh SYNOPSIS +.In libutil++.hh +.Ft using addrinfo_up = std::unique_ptr; +.Sh DESCRIPTION +This class is a specialization of +.Vt std::unique_ptr +for socket addresses returned by +.Xr getaddrinfo 3 . +When a list of socket addresses managed by an instance of this class is +disposed, +.Xr freeaddrinfo 3 +is invoked to dispose of the list. +.Sh EXAMPLES +.Bd -literal -offset indent +freebsd::addrinfo_up +resolve_address(const char *address, const char *port) +{ + struct addrinfo hints, *ai; + int error; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + error = getaddrinfo(address, port, &hints, &ai); + if (error != 0) + return {}; + return freebsd::addrinfo_up(ai); +} +.Ed +.Sh SEE ALSO +.Xr getaddrinfo 3 diff --git a/lib/libutil++/libutil++.hh b/lib/libutil++/libutil++.hh index 93cc2d9e6650..e9269b482a5c 100644 --- a/lib/libutil++/libutil++.hh +++ b/lib/libutil++/libutil++.hh @@ -8,6 +8,8 @@ #ifndef __LIBUTILPP_HH__ #define __LIBUTILPP_HH__ +#include + #include #include #include @@ -27,6 +29,20 @@ namespace freebsd { using FILE_up = std::unique_ptr; + /* + * addrinfo_up is a std::unique_ptr<> which uses + * freeaddrinfo() to destroy the wrapped pointer. It is + * intended to wrap arrays allocated by getaddrinfo(). + */ + struct freeaddrinfo_deleter { + void operator() (struct addrinfo *ai) const + { + freeaddrinfo(ai); + } + }; + + using addrinfo_up = std::unique_ptr; + /* * malloc_up is a std::unique_ptr<> which uses free() to * destroy the wrapped pointer. This can be used to wrap