From nobody Sun May 19 00:17:11 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 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 1580354699721299.2610263759731; Wed, 29 Jan 2020 19:24:59 -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-76-mFgNg_vXPsS3j7ehLTCgNA-1; Wed, 29 Jan 2020 22:24:56 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D61B71882CCD; Thu, 30 Jan 2020 03:24:50 +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 A59935C219; Thu, 30 Jan 2020 03:24:50 +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 6134818089CE; Thu, 30 Jan 2020 03:24:50 +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 00U3ORQJ023392 for ; Wed, 29 Jan 2020 22:24:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3CEC02166B29; Thu, 30 Jan 2020 03:24:27 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38C1A2166B27 for ; Thu, 30 Jan 2020 03:24:25 +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 7420B185AB82 for ; Thu, 30 Jan 2020 03:24:25 +0000 (UTC) Received: from dodo.xh.is (dodo.xh.is [144.202.88.237]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-287-I1GpsJzVMxO5_Bx-49nngQ-2; Wed, 29 Jan 2020 22:24:23 -0500 Received: by dodo.xh.is (OpenSMTPD) with ESMTPSA id 7ef97bd4 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Wed, 29 Jan 2020 19:24:20 -0800 (PST) Received: from liushuyu.lan (unknown [172.22.1.1]) by hermes.aosc.io (Postfix) with ESMTPS id 99E5A489A3; Thu, 30 Jan 2020 03:24:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580354698; 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=AHq4y5YBMuZ9eL1iyBy7aNMr1d+eZ6WqcNyVz80pUeM=; b=ZuJKGqgJ0Z+F/Em1tutvYWpOzyQ/WyViQxLNaULkYMU4bOP2SGyYwEk88bGZ5HjSYl9CdO EwtkXXawnu5yso/FW/f0tJk3yhgn0mQ9wGjuzF2kxJIQCdd5aZMqSqvrQ2md8WEJawUbZh 1wNFhpQ99qK8yW3NG88LYhyhgyu0WAc= From: Zixing Liu To: libvir-list@redhat.com Subject: [libvirt-rust PATCH v3 1/4] libvirt-rust: stream: add more functions in stream Date: Wed, 29 Jan 2020 20:24:11 -0700 Message-Id: <20200130032414.9026-2-liushuyu@aosc.io> In-Reply-To: <20200130032414.9026-1-liushuyu@aosc.io> References: <20200130032414.9026-1-liushuyu@aosc.io> MIME-Version: 1.0 X-Spamd-Result: default: False [0.40 / 15.00] BAYES_HAM(-2.50)[100.00%] REPLY(-2.00)[] R_MISSING_CHARSET(2.50)[] MID_CONTAINS_FROM(1.00)[] BROKEN_CONTENT_TYPE(1.50)[] ASN(0.00)[asn:56300, ipnet:172.22.1.1/32, country:SG] RCPT_COUNT_THREE(0.00)[3] MAILCOW_MOO(0.00)[] FROM_HAS_DN(0.00)[] DKIM_SIGNED(0.00)[] TO_DN_ALL(0.00)[] RCVD_COUNT_TWO(0.00)[2] FROM_EQ_ENVFROM(0.00)[] MIME_GOOD(-0.10)[text/plain] TO_MATCH_ENVRCPT_ALL(0.00)[] X-Rspamd-Server: rspamd X-Rspamd-Scan-Time: 0.01 X-Rspamd-Queue-ID: 99E5A489A3 X-MC-Unique: I1GpsJzVMxO5_Bx-49nngQ-2 X-MC-Unique: mFgNg_vXPsS3j7ehLTCgNA-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 00U3ORQJ023392 X-loop: libvir-list@redhat.com Cc: Zixing Liu , sahid.ferdjaoui@canonical.com 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.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 --- src/stream.rs | 43 ++++++++++++++++++++++++++++++++++++++++++- tests/stream.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 tests/stream.rs diff --git a/src/stream.rs b/src/stream.rs index a110695..96e37cb 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,10 @@ 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, @@ -44,6 +50,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; @@ -52,6 +61,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, @@ -71,7 +83,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 @@ -128,4 +150,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.25.0 From nobody Sun May 19 00:17:11 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 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 1580354683391150.8430050404919; Wed, 29 Jan 2020 19:24: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-198-hhKu0nsnN-WzYM42TVp2LA-1; Wed, 29 Jan 2020 22:24:39 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 91F4E8010C7; Thu, 30 Jan 2020 03:24: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 B4423167A3; Thu, 30 Jan 2020 03:24:33 +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 B650487A64; Thu, 30 Jan 2020 03:24:28 +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 00U3OQvp023387 for ; Wed, 29 Jan 2020 22:24:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id BEAC0ED150; Thu, 30 Jan 2020 03:24:26 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BAA1FF18D0 for ; Thu, 30 Jan 2020 03:24:26 +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 99BEC800F57 for ; Thu, 30 Jan 2020 03:24:26 +0000 (UTC) Received: from dodo.xh.is (dodo.xh.is [144.202.88.237]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-287-0La6SZ7mNimqjThS6HqTlw-3; Wed, 29 Jan 2020 22:24:24 -0500 Received: by dodo.xh.is (OpenSMTPD) with ESMTPSA id 1272f7dc (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Wed, 29 Jan 2020 19:24:21 -0800 (PST) Received: from liushuyu.lan (unknown [172.22.1.1]) by hermes.aosc.io (Postfix) with ESMTPS id 378F2489A4; Thu, 30 Jan 2020 03:24:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580354682; 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=j2w0P7P0s79X2RuqvzNVC0U2xwlYp0IkIJ4FioYnY40=; b=a8L4cnDefihrZFwIdjoJd0V8G6/fXHOoIq06iYH6asqGp72F6tBxzSWAKEoTxf5rMPyw1v YF30ZMgA8OT5TVgSmw50JBBURL+ccv1vHnpDDMoyPjVoQUd6AlqBZzCUqL6peASABeiPxL SSJon1x9Nmii1p+xpdFcPF3wztt8vgs= From: Zixing Liu To: libvir-list@redhat.com Subject: [libvirt-rust PATCH v3 2/4] libvirt-rust: stream: add more functions in stream Date: Wed, 29 Jan 2020 20:24:12 -0700 Message-Id: <20200130032414.9026-3-liushuyu@aosc.io> In-Reply-To: <20200130032414.9026-1-liushuyu@aosc.io> References: <20200130032414.9026-1-liushuyu@aosc.io> MIME-Version: 1.0 X-Spamd-Result: default: False [0.40 / 15.00] BAYES_HAM(-2.50)[100.00%] REPLY(-2.00)[] R_MISSING_CHARSET(2.50)[] MID_CONTAINS_FROM(1.00)[] BROKEN_CONTENT_TYPE(1.50)[] ASN(0.00)[asn:56300, ipnet:172.22.1.1/32, country:SG] RCPT_COUNT_THREE(0.00)[3] MAILCOW_MOO(0.00)[] FROM_HAS_DN(0.00)[] DKIM_SIGNED(0.00)[] TO_DN_ALL(0.00)[] RCVD_COUNT_TWO(0.00)[2] FROM_EQ_ENVFROM(0.00)[] MIME_GOOD(-0.10)[text/plain] TO_MATCH_ENVRCPT_ALL(0.00)[] X-Rspamd-Server: rspamd X-Rspamd-Scan-Time: 0.01 X-Rspamd-Queue-ID: 378F2489A4 X-MC-Unique: 0La6SZ7mNimqjThS6HqTlw-3 X-MC-Unique: hhKu0nsnN-WzYM42TVp2LA-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 00U3OQvp023387 X-loop: libvir-list@redhat.com Cc: Zixing Liu , sahid.ferdjaoui@canonical.com 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.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 --- src/stream.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/stream.rs b/src/stream.rs index 96e37cb..3a83b34 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -50,6 +50,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; @@ -64,9 +70,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 { @@ -79,6 +102,13 @@ impl Drop for Stream { ) } } + 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 @@ -94,7 +124,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 { @@ -151,6 +181,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.25.0 From nobody Sun May 19 00:17:11 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 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 158035470895447.30590895294188; Wed, 29 Jan 2020 19:25:08 -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-365-a13yTKJEMbOTsqoo2ADzkA-1; Wed, 29 Jan 2020 22:25:03 -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 A2BA7107ACC5; Thu, 30 Jan 2020 03:24:57 +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 6E71D60BE0; Thu, 30 Jan 2020 03:24:57 +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 2B44818089CF; Thu, 30 Jan 2020 03:24:57 +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 00U3OTO1023401 for ; Wed, 29 Jan 2020 22:24:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id 11F80F18CA; Thu, 30 Jan 2020 03:24:29 +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 0D8D2ED150 for ; Thu, 30 Jan 2020 03:24:29 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.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 E6F3A1011E39 for ; Thu, 30 Jan 2020 03:24:28 +0000 (UTC) Received: from dodo.xh.is (dodo.xh.is [144.202.88.237]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-287-aUCmz0bHOwCAAAQVRxIsYw-4; Wed, 29 Jan 2020 22:24:25 -0500 Received: by dodo.xh.is (OpenSMTPD) with ESMTPSA id 302ec6af (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Wed, 29 Jan 2020 19:24:22 -0800 (PST) Received: from liushuyu.lan (unknown [172.22.1.1]) by hermes.aosc.io (Postfix) with ESMTPS id 33E04489A6; Thu, 30 Jan 2020 03:24:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580354707; 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=zETPEjYRb2g2V4rIjRGLo6t499lui7R7bF9SYXaOyHU=; b=hN2BPZtF5ngDJDor9hqwJDKektBs2/aXKp2744j4uJFm5k5hheYK77PRR3HvM1Fq2hdl4J /XjJsL3wcJ/GyzJlJH9p9JggKdqxbWOkLLqIrbUcGF9vDskdhu6gsxZxTyks0phPIe/39e 3Jkd9IC3fQO+/bU657JyZhVF0bYT9pU= From: Zixing Liu To: libvir-list@redhat.com Subject: [libvirt-rust PATCH v3 3/4] libvirt-rust: use reference instead of moving Date: Wed, 29 Jan 2020 20:24:13 -0700 Message-Id: <20200130032414.9026-4-liushuyu@aosc.io> In-Reply-To: <20200130032414.9026-1-liushuyu@aosc.io> References: <20200130032414.9026-1-liushuyu@aosc.io> MIME-Version: 1.0 X-Spamd-Result: default: False [2.76 / 15.00] REPLY(-2.00)[] R_MISSING_CHARSET(2.50)[] MID_CONTAINS_FROM(1.00)[] BROKEN_CONTENT_TYPE(1.50)[] ASN(0.00)[asn:56300, ipnet:172.22.1.1/32, country:SG] BAYES_HAM(-0.14)[69.96%] RCPT_COUNT_THREE(0.00)[3] MAILCOW_MOO(0.00)[] FROM_HAS_DN(0.00)[] DKIM_SIGNED(0.00)[] TO_DN_ALL(0.00)[] RCVD_COUNT_TWO(0.00)[2] FROM_EQ_ENVFROM(0.00)[] MIME_GOOD(-0.10)[text/plain] TO_MATCH_ENVRCPT_ALL(0.00)[] X-Rspamd-Server: rspamd X-Rspamd-Scan-Time: 0.02 X-Rspamd-Queue-ID: 33E04489A6 X-MC-Unique: aUCmz0bHOwCAAAQVRxIsYw-4 X-MC-Unique: a13yTKJEMbOTsqoo2ADzkA-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 00U3OTO1023401 X-loop: libvir-list@redhat.com Cc: Zixing Liu , sahid.ferdjaoui@canonical.com 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 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Zixing Liu --- src/domain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/domain.rs b/src/domain.rs index 121d0f9..5de66c6 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -1644,7 +1644,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(), --=20 2.25.0 From nobody Sun May 19 00:17:11 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 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 1580354687067168.13022652993186; Wed, 29 Jan 2020 19:24:47 -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-233-c2Va75s3MruAmTqatJqYjw-1; Wed, 29 Jan 2020 22:24:43 -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 78EB9100550E; Thu, 30 Jan 2020 03:24:37 +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 4A1BD7793A; Thu, 30 Jan 2020 03:24:37 +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 056761809565; Thu, 30 Jan 2020 03:24:36 +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 00U3OWWS023418 for ; Wed, 29 Jan 2020 22:24:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id 56AA610031EA; Thu, 30 Jan 2020 03:24:32 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5243010A50DF for ; Thu, 30 Jan 2020 03:24:30 +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 EF2A8800F59 for ; Thu, 30 Jan 2020 03:24:29 +0000 (UTC) Received: from dodo.xh.is (dodo.xh.is [144.202.88.237]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-287-3Fi4H1lrMyesMP_FCDV2Qg-5; Wed, 29 Jan 2020 22:24:27 -0500 Received: by dodo.xh.is (OpenSMTPD) with ESMTPSA id 91efbab6 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Wed, 29 Jan 2020 19:24:23 -0800 (PST) Received: from liushuyu.lan (unknown [172.22.1.1]) by hermes.aosc.io (Postfix) with ESMTPS id 46497489A7; Thu, 30 Jan 2020 03:24:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580354685; 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=aCIgHpew7dXhNhFjZH/SFslO2PgtB8YZG1Yuxic9ZDo=; b=NUc57hg4sU9f7oVUKcswjYDrcpv6xaO2O07w/pkRTY/4bUrK35NFt+w+sJPpj2h/TVuFbi MXHjEIEVN4mJOPnjDqPxCAgQTuxxSVsNtURx7fxccYz2gLFZYk0dB2gXwqNks8v5bWLOgG ezKMNiRNWtWv1b25agN/j+Hvbm3pleI= From: Zixing Liu To: libvir-list@redhat.com Subject: [libvirt-rust PATCH v3 4/4] libvirt-rust: stream: addressed comments Date: Wed, 29 Jan 2020 20:24:14 -0700 Message-Id: <20200130032414.9026-5-liushuyu@aosc.io> In-Reply-To: <20200130032414.9026-1-liushuyu@aosc.io> References: <20200130032414.9026-1-liushuyu@aosc.io> MIME-Version: 1.0 X-Spamd-Result: default: False [0.40 / 15.00] BAYES_HAM(-2.50)[100.00%] REPLY(-2.00)[] R_MISSING_CHARSET(2.50)[] MID_CONTAINS_FROM(1.00)[] BROKEN_CONTENT_TYPE(1.50)[] ASN(0.00)[asn:56300, ipnet:172.22.1.1/32, country:SG] RCPT_COUNT_THREE(0.00)[3] MAILCOW_MOO(0.00)[] FROM_HAS_DN(0.00)[] DKIM_SIGNED(0.00)[] TO_DN_ALL(0.00)[] RCVD_COUNT_TWO(0.00)[2] FROM_EQ_ENVFROM(0.00)[] MIME_GOOD(-0.10)[text/plain] TO_MATCH_ENVRCPT_ALL(0.00)[] X-Rspamd-Server: rspamd X-Rspamd-Scan-Time: 0.01 X-Rspamd-Queue-ID: 46497489A7 X-MC-Unique: 3Fi4H1lrMyesMP_FCDV2Qg-5 X-MC-Unique: c2Va75s3MruAmTqatJqYjw-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 00U3OWWS023418 X-loop: libvir-list@redhat.com Cc: Zixing Liu , sahid.ferdjaoui@canonical.com 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 X-Mimecast-Originator: redhat.com 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 --- src/stream.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/stream.rs b/src/stream.rs index 3a83b34..10145eb 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -114,17 +114,18 @@ 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 { - Stream { ptr: Some(ptr), callback: None } + fn from_ptr(ptr: sys::virStreamPtr) -> Stream { + Stream { + ptr: Some(ptr), + callback: None, + } } =20 pub fn as_ptr(&self) -> sys::virStreamPtr { @@ -136,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.25.0