From nobody Fri May 3 10:56:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1577171624; cv=none; d=zohomail.com; s=zohoarc; b=dyCtCbkDBNdFqwPJZ5JoyAUyAZXte8C4pXSUsH/lDcOq5PzJDBdrgXGiZBfi0Q2dEPoxkE0fU+kfkLj2TDwaRlyMCI2LeTchGNa+ODFutgYoV9i7wpieYoeyQA7OCvTJtbPZPSjkDywjPQvOGElWwttUnyerzGrNz+wCea+yIE4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577171624; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NKMIcCU1v6dMXMyjZK4VWxXsbmtetSS6DB+YKvT67x4=; b=aggVvhbokP2MX7/fSvPcONcX6EMi36lGEUdmpbPWrLAUao6oTz/ldnjs3gfQDZKGaqWlFs6OktNhtYmBJjej8AkNvnJSyQWuVMRIEaXqSi67mHS6xKuEiX4EqJGL9qsQkYgTKUhS7wyHSU2AfwP3+06UQteCyHghNkEydZAZ4dQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1577171621851917.5326061168598; Mon, 23 Dec 2019 23:13:41 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-266-PIkf8_gcMxKKEqTDpFs1-g-1; Tue, 24 Dec 2019 02:13:35 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D2D7C800EBF; Tue, 24 Dec 2019 07:13:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AD2F366FF9; Tue, 24 Dec 2019 07:13:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 68F0B252CA; Tue, 24 Dec 2019 07:13:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBO7D8cg028178 for ; Tue, 24 Dec 2019 02:13:08 -0500 Received: by smtp.corp.redhat.com (Postfix) id 288722026D67; Tue, 24 Dec 2019 07:13:08 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 233D52026D68 for ; Tue, 24 Dec 2019 07:13:06 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 02A7E801E74 for ; Tue, 24 Dec 2019 07:13:06 +0000 (UTC) Received: from balrog.mythic-beasts.com (balrog.mythic-beasts.com [46.235.227.24]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-325-J0XR-JGDNr2gxordxu9xzg-1; Tue, 24 Dec 2019 02:13:02 -0500 Received: from [199.195.250.187] (port=44236 helo=hermes.aosc.io) by balrog.mythic-beasts.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1ijeNI-0001lN-OZ; Tue, 24 Dec 2019 07:13:01 +0000 Received: from liushuyu.lan (unknown [172.22.1.1]) by hermes.aosc.io (Postfix) with ESMTPS id 2E15241B74; Tue, 24 Dec 2019 07:12:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577171618; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=NKMIcCU1v6dMXMyjZK4VWxXsbmtetSS6DB+YKvT67x4=; b=DunpQurNGGUgtU/A9nMvrKOoCJh6RLJOvWga2asrGMuYp0u6qybGvd21vKNFXrdnH/Asq0 EBERyCvZvAyi8rNzGYZHwl6T7VCgGx65W6JFgc4lGfyPc4X587EJdeSg4uX4F14V+P6ZLL BOyMZL7GW3WcClVELPaHt5z/Ohf5l4U= From: Zixing Liu To: libvir-list@redhat.com Date: Tue, 24 Dec 2019 00:12:51 -0700 Message-Id: <20191224071255.174037-2-liushuyu@aosc.io> In-Reply-To: <20191224071255.174037-1-liushuyu@aosc.io> References: <20191224071255.174037-1-liushuyu@aosc.io> MIME-Version: 1.0 X-Spamd-Result: default: False [0.40 / 15.00] BAYES_HAM(-2.50)[100.00%] BROKEN_CONTENT_TYPE(1.50)[] REPLY(-2.00)[] R_MISSING_CHARSET(2.50)[] MID_CONTAINS_FROM(1.00)[] TO_DN_ALL(0.00)[] FROM_EQ_ENVFROM(0.00)[] MAILCOW_MOO(0.00)[] ASN(0.00)[asn:56300, ipnet:172.22.1.1/32, country:SG] FROM_HAS_DN(0.00)[] TO_MATCH_ENVRCPT_ALL(0.00)[] RCPT_COUNT_THREE(0.00)[3] RCVD_COUNT_TWO(0.00)[2] MIME_GOOD(-0.10)[text/plain] X-Rspamd-Server: rspamd X-Rspamd-Scan-Time: 0.01 X-Rspamd-Queue-ID: 2E15241B74 X-BlackCat-Spam-Score: 50 X-Spam-Status: No, score=5.0 X-MC-Unique: J0XR-JGDNr2gxordxu9xzg-1 X-MC-Unique: PIkf8_gcMxKKEqTDpFs1-g-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id xBO7D8cg028178 X-loop: libvir-list@redhat.com Cc: Zixing Liu , sahid.ferdjaoui@canonical.com Subject: [libvirt] [rust PATCH v2 1/5] libvirt-rust: stream: add more functions in stream X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" * added new functions: virStreamNew virStreamEventUpdateCallback virStreamEventRemoveCallback * added new constants: VIR_STREAM_NONBLOCK * added new types/aliases: StreamFlags * changed the previous `new` associate function to `from_ptr` to avoid naming conflicts * added basic tests to test the creation of Stream struct (can not test the correctness of virStreamEventRemoveCallback and virStreamEventUpdateCallback due to "unsupported by the connection driver") Signed-off-by: Zixing Liu Reviewed-by: Sahid Orentino Ferdjaoui --- src/stream.rs | 42 +++++++++++++++++++++++++++++++++++++++++- tests/stream.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/stream.rs diff --git a/src/stream.rs b/src/stream.rs index 8bcdf4b..de272ab 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -18,6 +18,8 @@ =20 extern crate libc; =20 +use connect::Connect; +use connect::sys::virConnectPtr; use std::convert::TryFrom; =20 use error::Error; @@ -31,6 +33,9 @@ pub mod sys { =20 #[link(name =3D "virt")] extern "C" { + fn virStreamNew(c: virConnectPtr, + flags: libc::c_uint) + -> sys::virStreamPtr; fn virStreamSend(c: sys::virStreamPtr, data: *const libc::c_char, nbytes: libc::size_t) @@ -42,6 +47,9 @@ extern "C" { fn virStreamFree(c: sys::virStreamPtr) -> libc::c_int; fn virStreamAbort(c: sys::virStreamPtr) -> libc::c_int; fn virStreamFinish(c: sys::virStreamPtr) -> libc::c_int; + fn virStreamEventUpdateCallback(c: sys::virStreamPtr, + events: libc::c_int) -> libc::c_int; + fn virStreamEventRemoveCallback(c: sys::virStreamPtr) -> libc::c_int; } =20 pub type StreamEventType =3D self::libc::c_uint; @@ -50,6 +58,9 @@ pub const VIR_STREAM_EVENT_WRITABLE: StreamEventType =3D = (1 << 1); pub const VIR_STREAM_EVENT_ERROR: StreamEventType =3D (1 << 2); pub const VIR_STREAM_EVENT_HANGUP: StreamEventType =3D (1 << 3); =20 +pub type StreamFlags =3D self::libc::c_uint; +pub const VIR_STREAM_NONBLOCK: StreamFlags =3D (1 << 0); + #[derive(Debug)] pub struct Stream { ptr: Option, @@ -68,7 +79,17 @@ impl Drop for Stream { } =20 impl Stream { - pub fn new(ptr: sys::virStreamPtr) -> Stream { + pub fn new(conn: &Connect, flags: StreamFlags) -> Result { + unsafe { + let ptr =3D virStreamNew(conn.as_ptr(), flags as libc::c_uint); + if ptr.is_null() { + return Err(Error::new()); + } + return Ok(Stream::from_ptr(ptr)); + } + } + + pub fn from_ptr(ptr: sys::virStreamPtr) -> Stream { Stream { ptr: Some(ptr) } } =20 @@ -125,4 +146,23 @@ impl Stream { }; usize::try_from(ret).map_err(|_| Error::new()) } + + pub fn event_update_callback(&self, events: StreamEventType) -> Result= <(), Error> { + let ret =3D unsafe { + virStreamEventUpdateCallback(self.as_ptr(), events as libc::c_= int) + }; + if ret =3D=3D -1 { + return Err(Error::new()); + } + return Ok(()); + } + + pub fn event_remove_callback(&self) -> Result<(), Error> { + unsafe { + if virStreamEventRemoveCallback(self.as_ptr()) =3D=3D -1 { + return Err(Error::new()); + } + return Ok(()); + } + } } diff --git a/tests/stream.rs b/tests/stream.rs new file mode 100644 index 0000000..16531b3 --- /dev/null +++ b/tests/stream.rs @@ -0,0 +1,40 @@ +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + * Sahid Orentino Ferdjaoui + */ + +extern crate virt; + +mod common; + +use virt::stream::Stream; +use virt::stream::VIR_STREAM_NONBLOCK; + +#[test] +fn test_create_blocking() { + let c =3D common::conn(); + let s =3D Stream::new(&c, 0).unwrap(); + drop(s); + common::close(c); +} + +#[test] +fn test_create_non_blocking() { + let c =3D common::conn(); + let s =3D Stream::new(&c, VIR_STREAM_NONBLOCK).unwrap(); + drop(s); + common::close(c); +} --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 10:56:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1577171603; cv=none; d=zohomail.com; s=zohoarc; b=lOYa4N8W//3UlRp5oifGLLBXZ8WIbt/EqNwdX5/79GdgBO9SkhTGHcEa7p89t4zDndFe+0H+FILkVg3cVcNm/LMdNgTVFuiqR3AEhtDNEO4AYiHfPRbtQmogJXvFOk+fwm1VNpgdz/gExoHAdMK18s4HTc0A0d3GTIZ+k5KrRz4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577171603; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iN9RiEuqSBSajPOvH+J0ITl9zkS37E2mAeh+eC6hPzk=; b=Li3DnT8+AfzDtX0pfjN2iMqOGcbRzeqENKIRRJhDYFPCau+HDM6+R/5DVp3zTMUa1MRZkWpgkBNvkmrbmLTjNtRpI1qdipsD3f20yOYtJf3q4JPErNyduNb2U8nqJC4utnNh2LWyZH62jfV75hlT0SOBwerO2KVYGLemQsT1KdQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1577171603065966.8542937875402; Mon, 23 Dec 2019 23:13:23 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-11-g8uCAMCSMTSam4L_ucW1WQ-1; Tue, 24 Dec 2019 02:13:19 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 67E52801E66; Tue, 24 Dec 2019 07:13:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF26360BE2; Tue, 24 Dec 2019 07:13:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BB8D71809563; Tue, 24 Dec 2019 07:13:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBO7D6ge028156 for ; Tue, 24 Dec 2019 02:13:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7E1022166B27; Tue, 24 Dec 2019 07:13:06 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 791FC2166B2C for ; Tue, 24 Dec 2019 07:13:04 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 72D87801572 for ; Tue, 24 Dec 2019 07:13:04 +0000 (UTC) Received: from balrog.mythic-beasts.com (balrog.mythic-beasts.com [46.235.227.24]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-273-IdDEoWcuM5ijIqDUnGMSSw-1; Tue, 24 Dec 2019 02:13:02 -0500 Received: from [199.195.250.187] (port=44244 helo=hermes.aosc.io) by balrog.mythic-beasts.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1ijeNI-0001lP-NL; Tue, 24 Dec 2019 07:13:01 +0000 Received: from liushuyu.lan (unknown [172.22.1.1]) by hermes.aosc.io (Postfix) with ESMTPS id 221C845CC8; Tue, 24 Dec 2019 07:12:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577171602; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=iN9RiEuqSBSajPOvH+J0ITl9zkS37E2mAeh+eC6hPzk=; b=DKzRAfLVM8ZzgoMYqpsc+oVxpJ27akivPK7dg+J2kq22MizY8aVeMP0/GRxClk0n+EYh3X VhCBbH4xXGXY81/J4gfEoyJiybSLcdkz44CxKIQwftQh0tQdHBDODRdYU9Kp4tr3gqBlHT dns0TivAW2lIypZAhSa3wcDFywomiFA= From: Zixing Liu To: libvir-list@redhat.com Date: Tue, 24 Dec 2019 00:12:52 -0700 Message-Id: <20191224071255.174037-3-liushuyu@aosc.io> In-Reply-To: <20191224071255.174037-1-liushuyu@aosc.io> References: <20191224071255.174037-1-liushuyu@aosc.io> MIME-Version: 1.0 X-Spamd-Result: default: False [0.40 / 15.00] BAYES_HAM(-2.50)[100.00%] BROKEN_CONTENT_TYPE(1.50)[] REPLY(-2.00)[] R_MISSING_CHARSET(2.50)[] MID_CONTAINS_FROM(1.00)[] TO_DN_ALL(0.00)[] FROM_EQ_ENVFROM(0.00)[] MAILCOW_MOO(0.00)[] ASN(0.00)[asn:56300, ipnet:172.22.1.1/32, country:SG] FROM_HAS_DN(0.00)[] TO_MATCH_ENVRCPT_ALL(0.00)[] RCPT_COUNT_THREE(0.00)[3] RCVD_COUNT_TWO(0.00)[2] MIME_GOOD(-0.10)[text/plain] X-Rspamd-Server: rspamd X-Rspamd-Scan-Time: 0.01 X-Rspamd-Queue-ID: 221C845CC8 X-BlackCat-Spam-Score: 50 X-Spam-Status: No, score=5.0 X-MC-Unique: IdDEoWcuM5ijIqDUnGMSSw-1 X-MC-Unique: g8uCAMCSMTSam4L_ucW1WQ-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id xBO7D6ge028156 X-loop: libvir-list@redhat.com Cc: Zixing Liu , sahid.ferdjaoui@canonical.com Subject: [libvirt] [rust PATCH v2 2/5] libvirt-rust: stream: add more functions in stream X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" * added virStreamEventAddCallback function * added new types: StreamEventCallback and FreeCallback * added new field: callback for storing event callback * drop: will drop the Box if any * added wrapper event_callback for easier callback authoring for the user (so that closures with Fn or FnMut references could be used) * added padding function event_free to just makes it compile (Rust should not need this, because Rust sticks to RAII) Signed-off-by: Zixing Liu Reviewed-by: Sahid Orentino Ferdjaoui --- src/stream.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/stream.rs b/src/stream.rs index de272ab..1ffd186 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -47,6 +47,12 @@ extern "C" { fn virStreamFree(c: sys::virStreamPtr) -> libc::c_int; fn virStreamAbort(c: sys::virStreamPtr) -> libc::c_int; fn virStreamFinish(c: sys::virStreamPtr) -> libc::c_int; + fn virStreamEventAddCallback(c: sys::virStreamPtr, + event: libc::c_int, + callback: StreamEventCallback, + opaque: *const libc::c_void, + ff: FreeCallback) + -> libc::c_int; fn virStreamEventUpdateCallback(c: sys::virStreamPtr, events: libc::c_int) -> libc::c_int; fn virStreamEventRemoveCallback(c: sys::virStreamPtr) -> libc::c_int; @@ -61,9 +67,26 @@ pub const VIR_STREAM_EVENT_HANGUP: StreamEventType =3D (= 1 << 3); pub type StreamFlags =3D self::libc::c_uint; pub const VIR_STREAM_NONBLOCK: StreamFlags =3D (1 << 0); =20 -#[derive(Debug)] +pub type StreamEventCallback =3D extern "C" fn(sys::virStreamPtr, libc::c_= int, *const libc::c_void); +pub type FreeCallback =3D extern "C" fn(*mut libc::c_void); + +// wrapper for callbacks +extern "C" fn event_callback(c: sys::virStreamPtr, flags: libc::c_int, opa= que: *const libc::c_void) { + let flags =3D flags as StreamFlags; + let shadow_self =3D unsafe { + &mut*(opaque as *mut Stream) + }; + if let Some(callback) =3D &mut shadow_self.callback { + callback(&Stream::from_ptr(c), flags); + } +} + +extern "C" fn event_free(_opaque: *mut libc::c_void) {} + +// #[derive(Debug)] pub struct Stream { ptr: Option, + callback: Option>, } =20 impl Drop for Stream { @@ -75,6 +98,13 @@ impl Drop for Stream { e.message) } } + if self.callback.is_some() { + if let Err(e) =3D self.event_remove_callback() { + panic!("Unable to remove event callback for Stream, code {= }, message: {}", + e.code, + e.message) + } + } } } =20 @@ -90,7 +120,7 @@ impl Stream { } =20 pub fn from_ptr(ptr: sys::virStreamPtr) -> Stream { - Stream { ptr: Some(ptr) } + Stream { ptr: Some(ptr), callback: None } } =20 pub fn as_ptr(&self) -> sys::virStreamPtr { @@ -147,6 +177,18 @@ impl Stream { usize::try_from(ret).map_err(|_| Error::new()) } =20 + pub fn event_add_callback(&mut self, events: StreamEventType, cb: F) -> Result<(), Error> { + let ret =3D unsafe { + let ptr =3D &*self as *const _ as *const _; + virStreamEventAddCallback(self.as_ptr(), events as libc::c_int= , event_callback, ptr, event_free) + }; + if ret =3D=3D -1 { + return Err(Error::new()); + } + self.callback =3D Some(Box::new(cb)); + return Ok(()); + } + pub fn event_update_callback(&self, events: StreamEventType) -> Result= <(), Error> { let ret =3D unsafe { virStreamEventUpdateCallback(self.as_ptr(), events as libc::c_= int) --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 10:56:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1577171602; cv=none; d=zohomail.com; s=zohoarc; b=jo31N3IawiEntLf0JrYbOK8EAPjlJRbvs1+VyT4C2JS1PWOe/RyqXZF/TKMZutGEwy7lUpybSngKxTVovsZBT/qdIXqzwr9Cpcsf/gV8jqtMQAiuAbbYpKAYcxwcWneo+I/0KuWM4uNRYrFCmqI8Z8vGXCPVV/Y5uc9WJpsNjd0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577171602; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NhVPOZgoQpbOzIKz69pqWomLEKio6Lgg5599+OYxqCg=; b=lwOY1667r4D9bswfgllQXdlJn+R3fq8YcZjQu+uHh2AKJLyQKqxy9jyyPuFhk7Ct92Lq2bHG7BZLxDZrwE0T2QWHDA2tfoHvVKMK1h89ILuFdYPFk8vH52RcWO3z7Fd/kHMP7cf4ZEhxUR0BYaAYn26yQUCBlzFyCIACOFz7/o0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1577171602187187.14020212310913; Mon, 23 Dec 2019 23:13:22 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-25-Uhq6hX_-Od-Ap3-w1CDcHg-1; Tue, 24 Dec 2019 02:13:18 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 54C992EDA; Tue, 24 Dec 2019 07:13:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA1B960BF4; Tue, 24 Dec 2019 07:13:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B8828825B7; Tue, 24 Dec 2019 07:13:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBO7D7QP028165 for ; Tue, 24 Dec 2019 02:13:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id 214522166B29; Tue, 24 Dec 2019 07:13:07 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1CCF22166B27 for ; Tue, 24 Dec 2019 07:13:07 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D9D4B1018C44 for ; Tue, 24 Dec 2019 07:13:06 +0000 (UTC) Received: from haggis.mythic-beasts.com (haggis.mythic-beasts.com [46.235.224.141]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-274-uO49JCSmOP6oKFkMefJE9g-1; Tue, 24 Dec 2019 02:13:05 -0500 Received: from [199.195.250.187] (port=56102 helo=hermes.aosc.io) by haggis.mythic-beasts.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1ijeNK-00053z-PT; Tue, 24 Dec 2019 07:13:03 +0000 Received: from liushuyu.lan (unknown [172.22.1.1]) by hermes.aosc.io (Postfix) with ESMTPS id 1F85345CCA; Tue, 24 Dec 2019 07:13:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577171601; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=NhVPOZgoQpbOzIKz69pqWomLEKio6Lgg5599+OYxqCg=; b=PFRMBPob5mJAAaYUydaJr/r9WmKt49qnEU5Fe1T2vTUXss+HVcDBhsVbKaoBmu3bCh3t+K dK7B4PinD4CJ8koEfhnxGTag1kRPRFZT479feEbpamw9sTGBuWu7wgmk1qWolBWJh1I34V 9mmmGc5kg6jXCu8E8h7+PFd5znBqfAg= From: Zixing Liu To: libvir-list@redhat.com Date: Tue, 24 Dec 2019 00:12:53 -0700 Message-Id: <20191224071255.174037-4-liushuyu@aosc.io> In-Reply-To: <20191224071255.174037-1-liushuyu@aosc.io> References: <20191224071255.174037-1-liushuyu@aosc.io> MIME-Version: 1.0 X-Spamd-Result: default: False [0.62 / 15.00] BROKEN_CONTENT_TYPE(1.50)[] BAYES_HAM(-2.28)[98.85%] REPLY(-2.00)[] R_MISSING_CHARSET(2.50)[] MID_CONTAINS_FROM(1.00)[] TO_DN_ALL(0.00)[] FROM_EQ_ENVFROM(0.00)[] MAILCOW_MOO(0.00)[] ASN(0.00)[asn:56300, ipnet:172.22.1.1/32, country:SG] FROM_HAS_DN(0.00)[] TO_MATCH_ENVRCPT_ALL(0.00)[] RCPT_COUNT_THREE(0.00)[3] RCVD_COUNT_TWO(0.00)[2] MIME_GOOD(-0.10)[text/plain] X-Rspamd-Server: rspamd X-Rspamd-Scan-Time: 0.01 X-Rspamd-Queue-ID: 1F85345CCA X-BlackCat-Spam-Score: 50 X-Spam-Status: No, score=5.0 X-MC-Unique: uO49JCSmOP6oKFkMefJE9g-1 X-MC-Unique: Uhq6hX_-Od-Ap3-w1CDcHg-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id xBO7D7QP028165 X-loop: libvir-list@redhat.com Cc: Zixing Liu , sahid.ferdjaoui@canonical.com Subject: [libvirt] [rust PATCH v2 3/5] libvirt-rust: stream: automated lint X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" * used rustfmt to clean up the code Signed-off-by: Zixing Liu --- src/stream.rs | 97 +++++++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 41 deletions(-) diff --git a/src/stream.rs b/src/stream.rs index 1ffd186..0d84fd7 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -18,8 +18,8 @@ =20 extern crate libc; =20 -use connect::Connect; use connect::sys::virConnectPtr; +use connect::Connect; use std::convert::TryFrom; =20 use error::Error; @@ -33,28 +33,28 @@ pub mod sys { =20 #[link(name =3D "virt")] extern "C" { - fn virStreamNew(c: virConnectPtr, - flags: libc::c_uint) - -> sys::virStreamPtr; - fn virStreamSend(c: sys::virStreamPtr, - data: *const libc::c_char, - nbytes: libc::size_t) - -> libc::c_int; - fn virStreamRecv(c: sys::virStreamPtr, - data: *mut libc::c_char, - nbytes: libc::size_t) - -> libc::c_int; + fn virStreamNew(c: virConnectPtr, flags: libc::c_uint) -> sys::virStre= amPtr; + fn virStreamSend( + c: sys::virStreamPtr, + data: *const libc::c_char, + nbytes: libc::size_t, + ) -> libc::c_int; + fn virStreamRecv( + c: sys::virStreamPtr, + data: *mut libc::c_char, + nbytes: libc::size_t, + ) -> libc::c_int; fn virStreamFree(c: sys::virStreamPtr) -> libc::c_int; fn virStreamAbort(c: sys::virStreamPtr) -> libc::c_int; fn virStreamFinish(c: sys::virStreamPtr) -> libc::c_int; - fn virStreamEventAddCallback(c: sys::virStreamPtr, - event: libc::c_int, - callback: StreamEventCallback, - opaque: *const libc::c_void, - ff: FreeCallback) - -> libc::c_int; - fn virStreamEventUpdateCallback(c: sys::virStreamPtr, - events: libc::c_int) -> libc::c_int; + fn virStreamEventAddCallback( + c: sys::virStreamPtr, + event: libc::c_int, + callback: StreamEventCallback, + opaque: *const libc::c_void, + ff: FreeCallback, + ) -> libc::c_int; + fn virStreamEventUpdateCallback(c: sys::virStreamPtr, events: libc::c_= int) -> libc::c_int; fn virStreamEventRemoveCallback(c: sys::virStreamPtr) -> libc::c_int; } =20 @@ -71,14 +71,16 @@ pub type StreamEventCallback =3D extern "C" fn(sys::vir= StreamPtr, libc::c_int, *co pub type FreeCallback =3D extern "C" fn(*mut libc::c_void); =20 // wrapper for callbacks -extern "C" fn event_callback(c: sys::virStreamPtr, flags: libc::c_int, opa= que: *const libc::c_void) { - let flags =3D flags as StreamFlags; - let shadow_self =3D unsafe { - &mut*(opaque as *mut Stream) - }; - if let Some(callback) =3D &mut shadow_self.callback { - callback(&Stream::from_ptr(c), flags); - } +extern "C" fn event_callback( + c: sys::virStreamPtr, + flags: libc::c_int, + opaque: *const libc::c_void, +) { + let flags =3D flags as StreamFlags; + let shadow_self =3D unsafe { &mut *(opaque as *mut Stream) }; + if let Some(callback) =3D &mut shadow_self.callback { + callback(&Stream::from_ptr(c), flags); + } } =20 extern "C" fn event_free(_opaque: *mut libc::c_void) {} @@ -93,16 +95,18 @@ impl Drop for Stream { fn drop(&mut self) { if self.ptr.is_some() { if let Err(e) =3D self.free() { - panic!("Unable to drop memory for Stream, code {}, message= : {}", - e.code, - e.message) + panic!( + "Unable to drop memory for Stream, code {}, message: {= }", + e.code, e.message + ) } } if self.callback.is_some() { if let Err(e) =3D self.event_remove_callback() { - panic!("Unable to remove event callback for Stream, code {= }, message: {}", - e.code, - e.message) + panic!( + "Unable to remove event callback for Stream, code {}, = message: {}", + e.code, e.message + ) } } } @@ -120,7 +124,10 @@ impl Stream { } =20 pub fn from_ptr(ptr: sys::virStreamPtr) -> Stream { - Stream { ptr: Some(ptr), callback: None } + Stream { + ptr: Some(ptr), + callback: None, + } } =20 pub fn as_ptr(&self) -> sys::virStreamPtr { @@ -160,7 +167,7 @@ impl Stream { virStreamSend( self.as_ptr(), data.as_ptr() as *mut libc::c_char, - data.len() + data.len(), ) }; usize::try_from(ret).map_err(|_| Error::new()) @@ -177,10 +184,20 @@ impl Stream { usize::try_from(ret).map_err(|_| Error::new()) } =20 - pub fn event_add_callback(&mut self, events: StreamEventType, cb: F) -> Result<(), Error> { + pub fn event_add_callback( + &mut self, + events: StreamEventType, + cb: F, + ) -> Result<(), Error> { let ret =3D unsafe { let ptr =3D &*self as *const _ as *const _; - virStreamEventAddCallback(self.as_ptr(), events as libc::c_int= , event_callback, ptr, event_free) + virStreamEventAddCallback( + self.as_ptr(), + events as libc::c_int, + event_callback, + ptr, + event_free, + ) }; if ret =3D=3D -1 { return Err(Error::new()); @@ -190,9 +207,7 @@ impl Stream { } =20 pub fn event_update_callback(&self, events: StreamEventType) -> Result= <(), Error> { - let ret =3D unsafe { - virStreamEventUpdateCallback(self.as_ptr(), events as libc::c_= int) - }; + let ret =3D unsafe { virStreamEventUpdateCallback(self.as_ptr(), e= vents as libc::c_int) }; if ret =3D=3D -1 { return Err(Error::new()); } --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 10:56:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1577171619; cv=none; d=zohomail.com; s=zohoarc; b=A9IcjafLhLRXB8adiwLILAED0rxiRG+MPo0XRrGXULHMlYehdb3fJ5iWvJFxmJk7KnnW5d250EG7pjXj2sCytwGtfZA8+XpZWHvtcBjsHALEALlXv/ZCQaR/Ewo9/UshDY0ghvz+LArZ2kVae/Qk86jsDz2bPdootktzhjk+Zc0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577171619; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aFJcEY6wuK+MN7PDeCpHWOmztv3JtisSJuYsnyZw7hs=; b=i6SpXm1ZNzL7Yz1U08oVyQKzT2MLqSQGHY3pnuDx4TGEQq603USAmDdrpluPqctvyOid2Ea01aTCMX5aDR87uqzhQJxF42t14DnKJweiSpAx+jgzly9ndrBwMklDBW9DAHeDkAn3rhZ96Kblt4t48G6WT2jXo8CSWpwog077cKA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1577171619745148.5265749555066; Mon, 23 Dec 2019 23:13:39 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-193-ac0hwp2JNDKcS9tO_-gtVQ-1; Tue, 24 Dec 2019 02:13:37 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EF374107ACC5; Tue, 24 Dec 2019 07:13:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBD2569400; Tue, 24 Dec 2019 07:13:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5AB8018089CD; Tue, 24 Dec 2019 07:13:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBO7D7iJ028166 for ; Tue, 24 Dec 2019 02:13:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2EE161000D9B; Tue, 24 Dec 2019 07:13:07 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 29BF6103D237 for ; Tue, 24 Dec 2019 07:13:07 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 11EA9801E65 for ; Tue, 24 Dec 2019 07:13:07 +0000 (UTC) Received: from haggis.mythic-beasts.com (haggis.mythic-beasts.com [46.235.224.141]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-318-akjR5oayMvGugPUEZKjQPg-1; Tue, 24 Dec 2019 02:13:05 -0500 Received: from [199.195.250.187] (port=56111 helo=hermes.aosc.io) by haggis.mythic-beasts.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1ijeNK-000545-Pw; Tue, 24 Dec 2019 07:13:03 +0000 Received: from liushuyu.lan (unknown [172.22.1.1]) by hermes.aosc.io (Postfix) with ESMTPS id 16F6045CCC; Tue, 24 Dec 2019 07:13:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577171619; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=aFJcEY6wuK+MN7PDeCpHWOmztv3JtisSJuYsnyZw7hs=; b=cztPlgzihobaXvvs7In8ga6PXpZsuzUhmgs7Y7jLSEbzPwOZm4cg81GAKIFf2zOW+wn6zb IOURfld0ntZa2W1oViyyOwoT72PNW9Q4nUsd89am5MqiSM2Vb8lib1DlBMIblTvT4yZQIX VqcRxQ7qnRw/la3p4urICHB4fexcf4E= From: Zixing Liu To: libvir-list@redhat.com Date: Tue, 24 Dec 2019 00:12:54 -0700 Message-Id: <20191224071255.174037-5-liushuyu@aosc.io> In-Reply-To: <20191224071255.174037-1-liushuyu@aosc.io> References: <20191224071255.174037-1-liushuyu@aosc.io> MIME-Version: 1.0 X-Spamd-Result: default: False [2.90 / 15.00] BROKEN_CONTENT_TYPE(1.50)[] REPLY(-2.00)[] R_MISSING_CHARSET(2.50)[] MID_CONTAINS_FROM(1.00)[] TO_DN_ALL(0.00)[] BAYES_HAM(-0.00)[36.88%] FROM_EQ_ENVFROM(0.00)[] MAILCOW_MOO(0.00)[] ASN(0.00)[asn:56300, ipnet:172.22.1.1/32, country:SG] FROM_HAS_DN(0.00)[] TO_MATCH_ENVRCPT_ALL(0.00)[] RCPT_COUNT_THREE(0.00)[3] RCVD_COUNT_TWO(0.00)[2] MIME_GOOD(-0.10)[text/plain] X-Rspamd-Server: rspamd X-Rspamd-Scan-Time: 0.02 X-Rspamd-Queue-ID: 16F6045CCC X-BlackCat-Spam-Score: 50 X-Spam-Status: No, score=5.0 X-MC-Unique: akjR5oayMvGugPUEZKjQPg-1 X-MC-Unique: ac0hwp2JNDKcS9tO_-gtVQ-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id xBO7D7iJ028166 X-loop: libvir-list@redhat.com Cc: Zixing Liu , sahid.ferdjaoui@canonical.com Subject: [libvirt] [rust PATCH v2 4/5] libvirt-rust: use reference instead of moving X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Zixing Liu Reviewed-by: Sahid Orentino Ferdjaoui --- src/domain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/domain.rs b/src/domain.rs index 40a18d8..61ca411 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -1546,7 +1546,7 @@ impl Domain { } } =20 - pub fn open_console(&self, name: &str, stream: Stream, flags: u32) -> = Result { + pub fn open_console(&self, name: &str, stream: &Stream, flags: u32) ->= Result { unsafe { let ret =3D virDomainOpenConsole(self.as_ptr(), string_to_c_chars!(name), --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 10:56:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1577171623; cv=none; d=zohomail.com; s=zohoarc; b=UnfAoVQAZKoGY+BznzF5kFnEAX3e/SZcWTBrEDnXixPmfkiyG0D8EzPHWKSsCO/xLur4Tvh6wxKDCq7/OVCb5Hfc/mqoT1WxbSZ1ECHJw1d5har2QEdc0ccPWLXItkGMaVcT97Gd4u1MHe3UNf7rHJQpK+nz/CkplOwdYI9fx+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577171623; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Za0zeSGr3TfrCS/k6+NXc1aMSndgAtQqtTsU3Xy0eu4=; b=RdiZUiwtOm5Vs6dPB7cgnYjBqtXYSHJx23dkzU9UP9iGMoBhBjr0P9LasNdh5zCO18vtaBtix9DSZz2DXyXqIKmPYb89YY74mDIbTk8tlKcK7PiJaYMde7BN8lxm9/nVkoC9CtSfnYWaHyntxzU1SUo5G1MtMlYtpSxaAA5NQ3k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1577171623574118.04563957810615; Mon, 23 Dec 2019 23:13:43 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-306-L7-ExMxUMbyaSi4L2i_UUA-1; Tue, 24 Dec 2019 02:13:39 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C92A4107ACCA; Tue, 24 Dec 2019 07:13:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A36ED6090B; Tue, 24 Dec 2019 07:13:34 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 63821825A1; Tue, 24 Dec 2019 07:13:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBO7D8Gq028188 for ; Tue, 24 Dec 2019 02:13:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id DE2BDC690C; Tue, 24 Dec 2019 07:13:08 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D973DC6910 for ; Tue, 24 Dec 2019 07:13:07 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2B64D802884 for ; Tue, 24 Dec 2019 07:13:07 +0000 (UTC) Received: from balrog.mythic-beasts.com (balrog.mythic-beasts.com [46.235.227.24]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-64-L9YE3zZpP1akcuhaOx36fQ-1; Tue, 24 Dec 2019 02:13:05 -0500 Received: from [199.195.250.187] (port=44267 helo=hermes.aosc.io) by balrog.mythic-beasts.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1ijeNL-0001m0-OL; Tue, 24 Dec 2019 07:13:03 +0000 Received: from liushuyu.lan (unknown [172.22.1.1]) by hermes.aosc.io (Postfix) with ESMTPS id 138A943DD6; Tue, 24 Dec 2019 07:13:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577171622; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Za0zeSGr3TfrCS/k6+NXc1aMSndgAtQqtTsU3Xy0eu4=; b=Xxb7G6d13G2qcPGe15n7P3OFkI9FANNCgxI5d3SLIFGvsHPnzbYQYNWWNdYtS8L6YHD45a OgfHbLxD+Ib4iLE6iYE4KPm/lwkHwUourHJIlHy0vknmY6vWopMvZaxEmaYeUlfE3DuKPV ilaAOOsGT9usGmw8WxMqqAM6KzLVuYE= From: Zixing Liu To: libvir-list@redhat.com Date: Tue, 24 Dec 2019 00:12:55 -0700 Message-Id: <20191224071255.174037-6-liushuyu@aosc.io> In-Reply-To: <20191224071255.174037-1-liushuyu@aosc.io> References: <20191224071255.174037-1-liushuyu@aosc.io> MIME-Version: 1.0 X-Spamd-Result: default: False [0.62 / 15.00] BROKEN_CONTENT_TYPE(1.50)[] BAYES_HAM(-2.28)[98.85%] REPLY(-2.00)[] R_MISSING_CHARSET(2.50)[] MID_CONTAINS_FROM(1.00)[] TO_DN_ALL(0.00)[] FROM_EQ_ENVFROM(0.00)[] MAILCOW_MOO(0.00)[] ASN(0.00)[asn:56300, ipnet:172.22.1.1/32, country:SG] FROM_HAS_DN(0.00)[] TO_MATCH_ENVRCPT_ALL(0.00)[] RCPT_COUNT_THREE(0.00)[3] RCVD_COUNT_TWO(0.00)[2] MIME_GOOD(-0.10)[text/plain] X-Rspamd-Server: rspamd X-Rspamd-Scan-Time: 0.01 X-Rspamd-Queue-ID: 138A943DD6 X-BlackCat-Spam-Score: 50 X-Spam-Status: No, score=5.0 X-MC-Unique: L9YE3zZpP1akcuhaOx36fQ-1 X-MC-Unique: L7-ExMxUMbyaSi4L2i_UUA-1 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id xBO7D8Gq028188 X-loop: libvir-list@redhat.com Cc: Zixing Liu , sahid.ferdjaoui@canonical.com Subject: [libvirt] [rust PATCH v2 5/5] libvirt-rust: stream: addressed comments X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" * minimized unsafe scope * removed pub from `from_ptr` function Signed-off-by: Zixing Liu Reviewed-by: Sahid Orentino Ferdjaoui --- src/stream.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/stream.rs b/src/stream.rs index 0d84fd7..ea623f6 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -114,16 +114,14 @@ impl Drop for Stream { =20 impl Stream { pub fn new(conn: &Connect, flags: StreamFlags) -> Result { - unsafe { - let ptr =3D virStreamNew(conn.as_ptr(), flags as libc::c_uint); - if ptr.is_null() { - return Err(Error::new()); - } - return Ok(Stream::from_ptr(ptr)); + let ptr =3D unsafe { virStreamNew(conn.as_ptr(), flags as libc::c_= uint) }; + if ptr.is_null() { + return Err(Error::new()); } + return Ok(Stream::from_ptr(ptr)); } =20 - pub fn from_ptr(ptr: sys::virStreamPtr) -> Stream { + fn from_ptr(ptr: sys::virStreamPtr) -> Stream { Stream { ptr: Some(ptr), callback: None, @@ -139,9 +137,9 @@ impl Stream { if virStreamFree(self.as_ptr()) =3D=3D -1 { return Err(Error::new()); } - self.ptr =3D None; - return Ok(()); } + self.ptr =3D None; + return Ok(()); } =20 pub fn finish(self) -> Result<(), Error> { --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list