From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.3 (2019-12-06) on atuin.qyliss.net X-Spam-Level: X-Spam-Status: No, score=-1.2 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.3 Received: by atuin.qyliss.net (Postfix, from userid 496) id B06AE18307; Mon, 6 Jul 2020 16:02:03 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by atuin.qyliss.net (Postfix) with ESMTP id CADFA18292; Mon, 6 Jul 2020 16:02:00 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 496) id 7A7CA1826F; Mon, 6 Jul 2020 16:01:58 +0000 (UTC) Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by atuin.qyliss.net (Postfix) with ESMTPS id 8A5D91828B for ; Mon, 6 Jul 2020 16:01:56 +0000 (UTC) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 018455C01B6; Mon, 6 Jul 2020 12:01:56 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Mon, 06 Jul 2020 12:01:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alyssa.is; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=bPgfzDyR6fm7T 9jveM78WhiBPJZvyBfjQExgoGoGc7I=; b=vY/SG1++KfpA9LX9l9N9Z2QOG2hyC nwUjKFplIUBY5loDGQb89Frsyj9SfvxycaByS0nhUepntce+m/sUJ/9RS5XWR7LT fj4Gd1dMbPaJeTHoD4M1YQKsdqQS3eUlzLQOaC8N2MZgdfTbF6mGSbESNHEX5IBw XtzZOrh91nb5Q8tpdig9RkZay8/AHKLkGqy/glfHXG600dx1z3VlsVB313rvDmyB D9SyLqTiih2MtY9iwvM5SUOY3fvDl5ZrU0+d0FHu+g4s4+hhfb5K/aCtfqKvqW0E f5ounNtBMyMc025v7+fTFDYKFB1rB8VGNd+IvUCpdXkO30yjtmyg4P4Ww== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=bPgfzDyR6fm7T9jveM78WhiBPJZvyBfjQExgoGoGc7I=; b=QGEY2mbx Tz+829khq+KJaqWopuKZR29jRSI2qldvbfxOxA154jQOfppUxP0modbsYjBN1GMv 0bIT8zY8nuT0EpheawviCo8vqm+OOhqivlJ+5AcGa1Nw52artXUNC9c6FltLgg/A YSIh3xux7jiuo+e2l0pX0gADD3/yq/b+EFFPsfj9BCHiDq196x4ROChZzJIURVIN odMpTfH7+EmbOlTgyuKG9+/1pznw6u16gzShIFozhnhpTymOtCti7lg4/O+K5K7E wr/RehO7jDxG+8fav/HXreVjwtfE09FjVbf20cTG6O11QUSvtp/AhnamyDliMkup j9TLxIfFDq1/lQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrudefgdelkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomheptehlhihsshgr ucftohhsshcuoehhihesrghlhihsshgrrdhisheqnecuggftrfgrthhtvghrnhepgfefud ekvdelieelledufeevheeglefggedvudejvddtffeuueevffehleejkedvnecukfhppeej ledrvdefhedruddviedrudejleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehqhihlihhsshesgidvvddtrdhqhihlihhsshdrnhgvth X-ME-Proxy: Received: from x220.qyliss.net (p4feb7eb3.dip0.t-ipconnect.de [79.235.126.179]) by mail.messagingengine.com (Postfix) with ESMTPA id 9C3F530653F0; Mon, 6 Jul 2020 12:01:55 -0400 (EDT) Received: by x220.qyliss.net (Postfix, from userid 1000) id 5A9483AF; Mon, 6 Jul 2020 16:01:54 +0000 (UTC) From: Alyssa Ross To: devel@spectrum-os.org Subject: [PATCH crosvm 2/2] sys_util: expand on UnixSeqpacket documentation Date: Mon, 6 Jul 2020 15:59:15 +0000 Message-Id: <20200706155913.18065-2-hi@alyssa.is> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200706155913.18065-1-hi@alyssa.is> References: <20200706155913.18065-1-hi@alyssa.is> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: G7O3GBWLQ53NCMZLFT2TCM4ELQPWLX25 X-Message-ID-Hash: G7O3GBWLQ53NCMZLFT2TCM4ELQPWLX25 X-MailFrom: qyliss@x220.qyliss.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Cole Helbling X-Mailman-Version: 3.3.1 Precedence: list List-Id: Patches and low-level development discussion Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: --- sys_util/src/net.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/sys_util/src/net.rs b/sys_util/src/net.rs index 82b4f5bb0..0e1cf6e55 100644 --- a/sys_util/src/net.rs +++ b/sys_util/src/net.rs @@ -197,7 +197,9 @@ impl UnixSeqpacket { } } =20 - /// Receive data from the socket fd to a given buffer. + /// Receive a message from the socket fd to a given buffer. The mes= sage will then + /// be removed from the socket, whether `buf` was large enough to ho= ld all of it or + /// not. /// /// # Arguments /// * `buf` - A mut reference to the data buffer. @@ -205,6 +207,30 @@ impl UnixSeqpacket { /// # Returns /// * `usize` - The size of bytes read to the buffer. /// + /// # Examples + /// + /// ``` + /// # fn main() -> Result<(), sys_util::Error> { + /// # use sys_util::net::UnixSeqpacket; + /// let (s1, s2) =3D UnixSeqpacket::pair()?; + /// s1.send(b"First message")?; + /// s1.send(b"Second message")?; + /// s1.send(b"Third message")?; + /// + /// let mut buf =3D [0; 13]; + /// assert_eq!(s2.recv(&mut buf)?, 13); + /// assert_eq!(&buf, b"First message"); + /// + /// // Even reading into a buffer zero bytes long will consume a mes= sage. + /// assert_eq!(s2.recv(&mut [])?, 0); + /// + /// let mut buf =3D [0; 5]; + /// assert_eq!(s2.recv(&mut buf)?, 5); + /// assert_eq!(&buf, b"Third"); + /// # Ok(()) + /// # } + /// ``` + /// /// # Errors /// Returns error when `libc::recv` failed. pub fn recv(&self, buf: &mut [u8]) -> io::Result { --=20 2.26.2