зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1590249 - Vendor Rust. r=chunmin
Differential Revision: https://phabricator.services.mozilla.com/D60616 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
02e4693897
Коммит
0e7bf72221
|
@ -67,11 +67,6 @@ git = "https://github.com/PLSysSec/lucet_sandbox_compiler"
|
|||
replace-with = "vendored-sources"
|
||||
rev = "58498599272e23ef797bb4304d0f181d7455ca57"
|
||||
|
||||
[source."https://github.com/NikVolf/tokio-named-pipes"]
|
||||
branch = "stable"
|
||||
git = "https://github.com/NikVolf/tokio-named-pipes"
|
||||
replace-with = "vendored-sources"
|
||||
|
||||
[source."https://github.com/ChunMinChang/cubeb-coreaudio-rs"]
|
||||
git = "https://github.com/ChunMinChang/cubeb-coreaudio-rs"
|
||||
replace-with = "vendored-sources"
|
||||
|
|
|
@ -92,7 +92,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "audio_thread_priority"
|
||||
version = "0.20.2"
|
||||
version = "0.21.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -107,7 +107,7 @@ dependencies = [
|
|||
name = "audioipc"
|
||||
version = "0.2.4"
|
||||
dependencies = [
|
||||
"audio_thread_priority 0.20.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"audio_thread_priority 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bincode 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -126,7 +126,6 @@ dependencies = [
|
|||
"serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio-io 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio-named-pipes 0.2.0 (git+https://github.com/NikVolf/tokio-named-pipes?branch=stable)",
|
||||
"tokio-reactor 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -135,7 +134,7 @@ dependencies = [
|
|||
name = "audioipc-client"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"audio_thread_priority 0.20.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"audio_thread_priority 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"audioipc 0.2.4",
|
||||
"cubeb-backend 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -148,7 +147,7 @@ dependencies = [
|
|||
name = "audioipc-server"
|
||||
version = "0.2.3"
|
||||
dependencies = [
|
||||
"audio_thread_priority 0.20.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"audio_thread_priority 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"audioipc 0.2.4",
|
||||
"cubeb-core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1464,7 +1463,7 @@ dependencies = [
|
|||
name = "gkrust-shared"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"audio_thread_priority 0.20.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"audio_thread_priority 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"audioipc-client 0.4.0",
|
||||
"audioipc-server 0.2.3",
|
||||
"authenticator 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -3965,18 +3964,6 @@ dependencies = [
|
|||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-named-pipes"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/NikVolf/tokio-named-pipes?branch=stable#0afa6247222a7aa6e8b370e949a0f4007f0018b6"
|
||||
dependencies = [
|
||||
"bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mio-named-pipes 0.1.6 (git+https://github.com/alexcrichton/mio-named-pipes)",
|
||||
"tokio 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-reactor"
|
||||
version = "0.1.3"
|
||||
|
@ -4611,7 +4598,7 @@ dependencies = [
|
|||
"checksum atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fb2dcb6e6d35f20276943cc04bb98e538b348d525a04ac79c10021561d202f21"
|
||||
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
|
||||
"checksum audio-mixer 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cd92208b8b0c2477d1123f9fa898e35d9f7d9340e3f26ddda27bf37a608eff99"
|
||||
"checksum audio_thread_priority 0.20.2 (registry+https://github.com/rust-lang/crates.io-index)" = "197b2d259505d11c92d266e1784f01cc935eb764d2f54e16aedf4e5085197871"
|
||||
"checksum audio_thread_priority 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e8391466145513620b0423a4e2f477686aed475f8e3c992cbfd876ffb33f4120"
|
||||
"checksum authenticator 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c9b93efb62fd39d28cf78aa7ae459dc312f39c287086ae7a5c379e1bf075a9ad"
|
||||
"checksum autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b671c8fb71b457dd4ae18c4ba1e59aa81793daacc361d82fcd410cef0d491875"
|
||||
"checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e"
|
||||
|
@ -4944,7 +4931,6 @@ dependencies = [
|
|||
"checksum tokio-executor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "ca6df436c42b0c3330a82d855d2ef017cd793090ad550a6bc2184f4b933532ab"
|
||||
"checksum tokio-fs 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b5cbe4ca6e71cb0b62a66e4e6f53a8c06a6eefe46cc5f665ad6f274c9906f135"
|
||||
"checksum tokio-io 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a5c9635ee806f26d302b8baa1e145689a280d8f5aa8d0552e7344808da54cc21"
|
||||
"checksum tokio-named-pipes 0.2.0 (git+https://github.com/NikVolf/tokio-named-pipes?branch=stable)" = "<none>"
|
||||
"checksum tokio-reactor 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8703a5762ff6913510dc64272c714c4389ffd8c4b3cf602879b8bd14ff06b604"
|
||||
"checksum tokio-tcp 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5b4c329b47f071eb8a746040465fa751bd95e4716e98daef6a9b4e434c17d565"
|
||||
"checksum tokio-threadpool 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "f0c32ffea4827978e9aa392d2f743d973c1dfa3730a2ed3f22ce1e6984da848c"
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"Cargo.toml":"363ab43ea4980149350eb3a4da691a93f0b7c61a5d3b4ce8b59f73cde5866a92","Makefile":"0f9a771cfb30c7c4b9961d82fdca4e9e229a955bb2e636474a4101389e18e938","README.md":"bcfa4948edf52fdacd485200a0c1c886a92232cc1931eeb4e1044050f46ec253","atp_test.cpp":"8075a040941a65fb9e3f7cbf0535853ca6661c3ac442ec35569b42b24bbec797","audio_thread_priority.h":"f0ecaf1b674f794cde0dc834028e074d4e4675d22ae96acf08b2ae1dceb3474e","generate_osx_bindings.sh":"06e4e03450f788ced18d31fff5660919e6f6ec1119ddace363ffeb82f0518a71","src/lib.rs":"516388cf4ccf55f23a6ccb248f56ab525b759a24819e67605cd12f640517ddd3","src/mach_sys.rs":"352560fcb9b41d877cff92e5b3b04d6dc68b1f30508ce4b9aed78940120a883e","src/rt_linux.rs":"b4db36baa754ab166b40f3801acc4f2046d226a2645f0e136dbbfa1bc771344e","src/rt_mach.rs":"5fce324b9a64305ff221fdd185eaa4b1c7386b6e61edc32cf63e424f9f3d90ef","src/rt_win.rs":"f8f5b7af21cadd686cf7d8099d1972d3265c3889574020bd4ea088b832fbfa51"},"package":"197b2d259505d11c92d266e1784f01cc935eb764d2f54e16aedf4e5085197871"}
|
||||
{"files":{"Cargo.toml":"37f3e58612d632aa6fe4a2a2330317921f7a090faa071660e4665f3be63c96c0","Makefile":"0f9a771cfb30c7c4b9961d82fdca4e9e229a955bb2e636474a4101389e18e938","README.md":"bcfa4948edf52fdacd485200a0c1c886a92232cc1931eeb4e1044050f46ec253","atp_test.cpp":"8075a040941a65fb9e3f7cbf0535853ca6661c3ac442ec35569b42b24bbec797","audio_thread_priority.h":"f0ecaf1b674f794cde0dc834028e074d4e4675d22ae96acf08b2ae1dceb3474e","generate_osx_bindings.sh":"06e4e03450f788ced18d31fff5660919e6f6ec1119ddace363ffeb82f0518a71","src/lib.rs":"6103fbdd7b27b5680c8f70a1413a9bf707eee28b8e0717268ecaab4b2e4ef148","src/mach_sys.rs":"352560fcb9b41d877cff92e5b3b04d6dc68b1f30508ce4b9aed78940120a883e","src/rt_linux.rs":"d68a064bbe6617b9a277c55abc308510e4f719a74ebe2e2206e990ae6ba87149","src/rt_mach.rs":"3f864805297b1172ed39b0ffe8888d21ec51cdc6183b31273f3f915473e31234","src/rt_win.rs":"3aabdcf6db810e23086c8710f55027f322e721b43a28dc7c544ca32a6d7964a5"},"package":"e8391466145513620b0423a4e2f477686aed475f8e3c992cbfd876ffb33f4120"}
|
|
@ -13,7 +13,7 @@
|
|||
[package]
|
||||
edition = "2018"
|
||||
name = "audio_thread_priority"
|
||||
version = "0.20.2"
|
||||
version = "0.21.0"
|
||||
authors = ["Paul Adenot <paul@paul.cx>"]
|
||||
description = "Bump a thread to real-time priority, for audio work, on Linux, Windows and macOS"
|
||||
license = "MPL-2.0"
|
||||
|
|
|
@ -3,14 +3,50 @@
|
|||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#[warn(missing_docs)]
|
||||
use cfg_if::cfg_if;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
|
||||
#[macro_use]
|
||||
extern crate cfg_if;
|
||||
#[cfg(feature = "terminal-logging")]
|
||||
extern crate simple_logger;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[derive(Debug)]
|
||||
pub struct AudioThreadPriorityError {
|
||||
message: String,
|
||||
inner: Option<Box<dyn Error + 'static>>,
|
||||
}
|
||||
|
||||
impl AudioThreadPriorityError {
|
||||
fn new_with_inner(message: &str, inner: Box<dyn Error>) -> AudioThreadPriorityError {
|
||||
AudioThreadPriorityError {
|
||||
message: message.into(),
|
||||
inner: Some(inner),
|
||||
}
|
||||
}
|
||||
fn new(message: &str) -> AudioThreadPriorityError {
|
||||
AudioThreadPriorityError {
|
||||
message: message.into(),
|
||||
inner: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for AudioThreadPriorityError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let mut rv = write!(f, "AudioThreadPriorityError: {}", &self.message);
|
||||
if let Some(inner) = &self.inner {
|
||||
rv = write!(f, " ({})", inner);
|
||||
}
|
||||
rv
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for AudioThreadPriorityError {
|
||||
fn description(&self) -> &str {
|
||||
&self.message
|
||||
}
|
||||
|
||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||
self.inner.as_ref().map(|e| e.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(target_os = "macos")] {
|
||||
|
@ -46,14 +82,14 @@ cfg_if! {
|
|||
} else {
|
||||
// blanket implementations for Android and other systems.
|
||||
pub struct RtPriorityHandleInternal {}
|
||||
pub fn promote_current_thread_to_real_time_internal(_: u32, audio_samplerate_hz: u32) -> Result<RtPriorityHandle, ()> {
|
||||
pub fn promote_current_thread_to_real_time_internal(_: u32, audio_samplerate_hz: u32) -> Result<RtPriorityHandle, AudioThreadPriorityError> {
|
||||
if audio_samplerate_hz == 0 {
|
||||
return Err(());
|
||||
return Err(AudioThreadPriorityError("sample rate is zero"));
|
||||
}
|
||||
// no-op
|
||||
Ok(RtPriorityHandle{})
|
||||
}
|
||||
pub fn demote_current_thread_from_real_time_internal(_: RtPriorityHandle) -> Result<(), ()> {
|
||||
pub fn demote_current_thread_from_real_time_internal(_: RtPriorityHandle) -> Result<(), AudioThreadPriorityError> {
|
||||
// no-op
|
||||
Ok(())
|
||||
}
|
||||
|
@ -84,7 +120,7 @@ pub type RtPriorityThreadInfo = RtPriorityThreadInfoInternal;
|
|||
///
|
||||
/// Ok in case of success, with an opaque structure containing relevant info for the platform, Err
|
||||
/// otherwise.
|
||||
pub fn get_current_thread_info() -> Result<RtPriorityThreadInfo, ()> {
|
||||
pub fn get_current_thread_info() -> Result<RtPriorityThreadInfo, AudioThreadPriorityError> {
|
||||
return get_current_thread_info_internal();
|
||||
}
|
||||
|
||||
|
@ -210,9 +246,9 @@ pub fn promote_thread_to_real_time(
|
|||
thread_info: RtPriorityThreadInfo,
|
||||
audio_buffer_frames: u32,
|
||||
audio_samplerate_hz: u32,
|
||||
) -> Result<RtPriorityHandle, ()> {
|
||||
) -> Result<RtPriorityHandle, AudioThreadPriorityError> {
|
||||
if audio_samplerate_hz == 0 {
|
||||
return Err(());
|
||||
return Err(AudioThreadPriorityError::new("sample rate is zero"));
|
||||
}
|
||||
return promote_thread_to_real_time_internal(
|
||||
thread_info,
|
||||
|
@ -231,7 +267,7 @@ pub fn promote_thread_to_real_time(
|
|||
/// # Return value
|
||||
///
|
||||
/// `Ok` in case of success, `Err` otherwise.
|
||||
pub fn demote_thread_from_real_time(thread_info: RtPriorityThreadInfo) -> Result<(), ()> {
|
||||
pub fn demote_thread_from_real_time(thread_info: RtPriorityThreadInfo) -> Result<(), AudioThreadPriorityError> {
|
||||
return demote_thread_from_real_time_internal(thread_info);
|
||||
}
|
||||
|
||||
|
@ -329,9 +365,9 @@ pub extern "C" fn atp_set_real_time_limit(audio_buffer_frames: u32,
|
|||
pub fn promote_current_thread_to_real_time(
|
||||
audio_buffer_frames: u32,
|
||||
audio_samplerate_hz: u32,
|
||||
) -> Result<RtPriorityHandle, ()> {
|
||||
) -> Result<RtPriorityHandle, AudioThreadPriorityError> {
|
||||
if audio_samplerate_hz == 0 {
|
||||
return Err(());
|
||||
return Err(AudioThreadPriorityError::new("sample rate is zero"));
|
||||
}
|
||||
return promote_current_thread_to_real_time_internal(audio_buffer_frames, audio_samplerate_hz);
|
||||
}
|
||||
|
@ -346,7 +382,9 @@ pub fn promote_current_thread_to_real_time(
|
|||
/// # Return value
|
||||
///
|
||||
/// `Ok` in scase of success, `Err` otherwise.
|
||||
pub fn demote_current_thread_from_real_time(handle: RtPriorityHandle) -> Result<(), ()> {
|
||||
pub fn demote_current_thread_from_real_time(
|
||||
handle: RtPriorityHandle,
|
||||
) -> Result<(), AudioThreadPriorityError> {
|
||||
return demote_current_thread_from_real_time_internal(handle);
|
||||
}
|
||||
|
||||
|
@ -442,9 +480,11 @@ mod tests {
|
|||
match promote_current_thread_to_real_time(0, 44100) {
|
||||
Ok(rt_prio_handle) => {
|
||||
demote_current_thread_from_real_time(rt_prio_handle).unwrap();
|
||||
assert!(true);
|
||||
}
|
||||
Err(e) => {
|
||||
panic!(e);
|
||||
eprintln!("{}", e.description());
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -452,17 +492,22 @@ mod tests {
|
|||
match promote_current_thread_to_real_time(512, 44100) {
|
||||
Ok(rt_prio_handle) => {
|
||||
demote_current_thread_from_real_time(rt_prio_handle).unwrap();
|
||||
assert!(true);
|
||||
}
|
||||
Err(e) => {
|
||||
panic!(e);
|
||||
eprintln!("{}", e.description());
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
match promote_current_thread_to_real_time(512, 44100) {
|
||||
Ok(_) => {}
|
||||
Ok(_) => {
|
||||
assert!(true);
|
||||
}
|
||||
Err(e) => {
|
||||
panic!(e);
|
||||
eprintln!("{}", e.description());
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
// automatically deallocated, but not demoted until the thread exits.
|
||||
|
@ -479,9 +524,11 @@ mod tests {
|
|||
let info = get_current_thread_info().unwrap();
|
||||
match promote_thread_to_real_time(info, 512, 44100) {
|
||||
Ok(_) => {
|
||||
assert!(true);
|
||||
}
|
||||
Err(e) => {
|
||||
panic!(e);
|
||||
eprintln!("{}", e);
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -516,6 +563,7 @@ mod tests {
|
|||
}
|
||||
Err(_) => {
|
||||
eprintln!("promotion Err");
|
||||
kill(child, SIGKILL).expect("Could not kill the child?");
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
|
@ -537,7 +585,7 @@ mod tests {
|
|||
match write(wr, &bytes) {
|
||||
Ok(_) => {
|
||||
loop {
|
||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
std::thread::sleep(std::time::Duration::from_millis(1000));
|
||||
eprintln!("child sleeping, waiting to be promoted...");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,12 +13,26 @@ use std::io::Error as OSError;
|
|||
|
||||
use dbus::{Connection, BusType, Props, MessageItem, Message};
|
||||
|
||||
use crate::AudioThreadPriorityError;
|
||||
|
||||
const DBUS_SOCKET_TIMEOUT: i32 = 10_000;
|
||||
const RT_PRIO_DEFAULT: u32 = 10;
|
||||
// This is different from libc::pid_t, which is 32 bits, and is defined in sys/types.h.
|
||||
#[allow(non_camel_case_types)]
|
||||
type kernel_pid_t = libc::c_long;
|
||||
|
||||
impl From<dbus::Error> for AudioThreadPriorityError {
|
||||
fn from(error: dbus::Error) -> Self {
|
||||
AudioThreadPriorityError::new(&format!("{}:{}", error.name().unwrap(), error.message().unwrap()))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Box<dyn Error>> for AudioThreadPriorityError {
|
||||
fn from(error: Box<dyn Error>) -> Self {
|
||||
AudioThreadPriorityError::new(&format!("{}", error.description()))
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct RtPriorityThreadInfoInternal {
|
||||
|
@ -31,9 +45,7 @@ pub struct RtPriorityThreadInfoInternal {
|
|||
/// process.
|
||||
pthread_id: libc::pthread_t,
|
||||
/// ...
|
||||
policy: libc::c_int,
|
||||
/// ...
|
||||
param: libc::sched_param,
|
||||
policy: libc::c_int
|
||||
}
|
||||
|
||||
impl RtPriorityThreadInfoInternal {
|
||||
|
@ -59,11 +71,11 @@ pub struct RtPriorityHandleInternal {
|
|||
thread_info: RtPriorityThreadInfoInternal,
|
||||
}
|
||||
|
||||
fn item_as_i64(i: MessageItem) -> Result<i64, Box<dyn Error>> {
|
||||
fn item_as_i64(i: MessageItem) -> Result<i64, AudioThreadPriorityError> {
|
||||
match i {
|
||||
MessageItem::Int32(i) => Ok(i as i64),
|
||||
MessageItem::Int64(i) => Ok(i),
|
||||
_ => Err(Box::from(&*format!("Property is not integer ({:?})", i)))
|
||||
_ => Err(AudioThreadPriorityError::new(&format!("Property is not integer ({:?})", i)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,7 +102,7 @@ fn rtkit_set_realtime(thread: u64, pid: u64, prio: u32) -> Result<(), Box<dyn Er
|
|||
|
||||
/// Returns the maximum priority, maximum real-time time slice, and the current real-time time
|
||||
/// slice for this process.
|
||||
fn get_limits() -> Result<(i64, u64, libc::rlimit64), Box<dyn Error>> {
|
||||
fn get_limits() -> Result<(i64, u64, libc::rlimit64), AudioThreadPriorityError> {
|
||||
let c = Connection::get_private(BusType::System)?;
|
||||
|
||||
let p = Props::new(&c, "org.freedesktop.RealtimeKit1", "/org/freedesktop/RealtimeKit1",
|
||||
|
@ -102,29 +114,28 @@ fn get_limits() -> Result<(i64, u64, libc::rlimit64), Box<dyn Error>> {
|
|||
|
||||
let max_prio = item_as_i64(p.get("MaxRealtimePriority")?)?;
|
||||
if max_prio < 0 {
|
||||
return Err(Box::from("invalid negative MaxRealtimePriority"));
|
||||
return Err(AudioThreadPriorityError::new("invalid negative MaxRealtimePriority"));
|
||||
}
|
||||
|
||||
let max_rttime = item_as_i64(p.get("RTTimeUSecMax")?)?;
|
||||
if max_rttime < 0 {
|
||||
return Err(Box::from("invalid negative RTTimeUSecMax"));
|
||||
return Err(AudioThreadPriorityError::new("invalid negative RTTimeUSecMax"));
|
||||
}
|
||||
|
||||
if unsafe { libc::getrlimit64(libc::RLIMIT_RTTIME, &mut current_limit) } < 0 {
|
||||
error!("getrlimit64: {}", OSError::last_os_error().raw_os_error().unwrap());
|
||||
return Err(Box::from("getrlimit failed"));
|
||||
return Err(AudioThreadPriorityError::new_with_inner(&"getrlimit64", Box::new(OSError::last_os_error())));
|
||||
}
|
||||
|
||||
Ok((max_prio, (max_rttime as u64), current_limit))
|
||||
}
|
||||
|
||||
fn set_limits(request: u64, max: u64) -> Result<(), Box<dyn Error>> {
|
||||
fn set_limits(request: u64, max: u64) -> Result<(), AudioThreadPriorityError> {
|
||||
// Set a soft limit to the limit requested, to be able to handle going over the limit using
|
||||
// SIGXCPU. Set the hard limit to the maxium slice to prevent getting SIGKILL.
|
||||
let new_limit = libc::rlimit64 { rlim_cur: request,
|
||||
rlim_max: max };
|
||||
if unsafe { libc::setrlimit64(libc::RLIMIT_RTTIME, &new_limit) } < 0 {
|
||||
return Err(Box::from("setrlimit failed"));
|
||||
return Err(AudioThreadPriorityError::new_with_inner("setrlimit64", Box::new(OSError::last_os_error())));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -132,27 +143,28 @@ fn set_limits(request: u64, max: u64) -> Result<(), Box<dyn Error>> {
|
|||
|
||||
pub fn promote_current_thread_to_real_time_internal(audio_buffer_frames: u32,
|
||||
audio_samplerate_hz: u32)
|
||||
-> Result<RtPriorityHandleInternal, ()> {
|
||||
-> Result<RtPriorityHandleInternal, AudioThreadPriorityError> {
|
||||
let thread_info = get_current_thread_info_internal()?;
|
||||
promote_thread_to_real_time_internal(thread_info, audio_buffer_frames, audio_samplerate_hz)
|
||||
}
|
||||
|
||||
pub fn demote_current_thread_from_real_time_internal(rt_priority_handle: RtPriorityHandleInternal)
|
||||
-> Result<(), ()> {
|
||||
-> Result<(), AudioThreadPriorityError> {
|
||||
assert!(unsafe { libc::pthread_self() } == rt_priority_handle.thread_info.pthread_id);
|
||||
|
||||
let param = unsafe { std::mem::zeroed::<libc::sched_param>() };
|
||||
|
||||
if unsafe { libc::pthread_setschedparam(rt_priority_handle.thread_info.pthread_id,
|
||||
rt_priority_handle.thread_info.policy,
|
||||
&rt_priority_handle.thread_info.param) } < 0 {
|
||||
error!("could not demote thread {}", OSError::last_os_error().raw_os_error().unwrap());
|
||||
return Err(());
|
||||
¶m) } < 0 {
|
||||
return Err(AudioThreadPriorityError::new_with_inner(&"could not demote thread", Box::new(OSError::last_os_error())));
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
/// This can be called by sandboxed code, it only restores priority to what they were.
|
||||
pub fn demote_thread_from_real_time_internal(thread_info: RtPriorityThreadInfoInternal)
|
||||
-> Result<(), ()> {
|
||||
-> Result<(), AudioThreadPriorityError> {
|
||||
let param = unsafe { std::mem::zeroed::<libc::sched_param>() };
|
||||
|
||||
// https://github.com/rust-lang/libc/issues/1511
|
||||
|
@ -161,8 +173,7 @@ pub fn demote_thread_from_real_time_internal(thread_info: RtPriorityThreadInfoIn
|
|||
if unsafe { libc::pthread_setschedparam(thread_info.pthread_id,
|
||||
libc::SCHED_OTHER|SCHED_RESET_ON_FORK,
|
||||
¶m) } < 0 {
|
||||
error!("could not demote thread {}", OSError::last_os_error().raw_os_error().unwrap());
|
||||
return Err(());
|
||||
return Err(AudioThreadPriorityError::new_with_inner(&"could not demote thread", Box::new(OSError::last_os_error())));
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -170,15 +181,14 @@ pub fn demote_thread_from_real_time_internal(thread_info: RtPriorityThreadInfoIn
|
|||
/// Get the current thread information, as an opaque struct, that can be serialized and sent
|
||||
/// accross processes. This is enough to capture the current state of the scheduling policy, and
|
||||
/// an identifier to have another thread promoted to real-time.
|
||||
pub fn get_current_thread_info_internal() -> Result<RtPriorityThreadInfoInternal, ()> {
|
||||
pub fn get_current_thread_info_internal() -> Result<RtPriorityThreadInfoInternal, AudioThreadPriorityError> {
|
||||
let thread_id = unsafe { libc::syscall(libc::SYS_gettid) };
|
||||
let pthread_id = unsafe { libc::pthread_self() };
|
||||
let mut param = unsafe { std::mem::zeroed::<libc::sched_param>() };
|
||||
let mut policy = 0;
|
||||
|
||||
if unsafe { libc::pthread_getschedparam(pthread_id, &mut policy, &mut param) } < 0 {
|
||||
error!("pthread_getschedparam error {}", OSError::last_os_error().raw_os_error().unwrap());
|
||||
return Err(());
|
||||
return Err(AudioThreadPriorityError::new_with_inner(&"pthread_getschedparam", Box::new(OSError::last_os_error())));
|
||||
}
|
||||
|
||||
let pid = unsafe { libc::getpid() };
|
||||
|
@ -187,8 +197,7 @@ pub fn get_current_thread_info_internal() -> Result<RtPriorityThreadInfoInternal
|
|||
pid,
|
||||
thread_id,
|
||||
pthread_id,
|
||||
policy,
|
||||
param
|
||||
policy
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -197,7 +206,7 @@ pub fn get_current_thread_info_internal() -> Result<RtPriorityThreadInfoInternal
|
|||
/// because we don't have access to DBUS, so it is hardcoded to 200ms, which is the default in the
|
||||
/// rtkit package.
|
||||
pub fn set_real_time_hard_limit_internal(audio_buffer_frames: u32,
|
||||
audio_samplerate_hz: u32) -> Result<(), ()> {
|
||||
audio_samplerate_hz: u32) -> Result<(), AudioThreadPriorityError> {
|
||||
let buffer_frames = if audio_buffer_frames > 0 {
|
||||
audio_buffer_frames
|
||||
} else {
|
||||
|
@ -208,11 +217,11 @@ pub fn set_real_time_hard_limit_internal(audio_buffer_frames: u32,
|
|||
|
||||
// It's only necessary to set RLIMIT_RTTIME to something when in the child, skip it if it's a
|
||||
// remoting call.
|
||||
let (_, max_rttime, _) = get_limits().map_err(|_| {})?;
|
||||
let (_, max_rttime, _) = get_limits()?;
|
||||
|
||||
// Only take what we need, or cap at the system limit, no further.
|
||||
let rttime_request = cmp::min(budget_us, max_rttime as u64);
|
||||
set_limits(rttime_request, max_rttime).map_err(|_| {})?;
|
||||
set_limits(rttime_request, max_rttime)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -220,23 +229,27 @@ pub fn set_real_time_hard_limit_internal(audio_buffer_frames: u32,
|
|||
/// Promote a thread (possibly in another process) identified by its tid, to real-time.
|
||||
pub fn promote_thread_to_real_time_internal(thread_info: RtPriorityThreadInfoInternal,
|
||||
audio_buffer_frames: u32,
|
||||
audio_samplerate_hz: u32) -> Result<RtPriorityHandleInternal, ()>
|
||||
audio_samplerate_hz: u32) -> Result<RtPriorityHandleInternal, AudioThreadPriorityError>
|
||||
{
|
||||
let RtPriorityThreadInfoInternal { pid, thread_id, .. } = thread_info;
|
||||
|
||||
let handle = RtPriorityHandleInternal { thread_info };
|
||||
|
||||
let (_, _, limits) = get_limits().map_err(|_| {})?;
|
||||
let (_, _, limits) = get_limits()?;
|
||||
set_real_time_hard_limit_internal(audio_buffer_frames, audio_samplerate_hz)?;
|
||||
|
||||
let r = rtkit_set_realtime(thread_id as u64, pid as u64, RT_PRIO_DEFAULT);
|
||||
|
||||
if r.is_err() {
|
||||
if unsafe { libc::setrlimit64(libc::RLIMIT_RTTIME, &limits) } < 0 {
|
||||
error!("setrlimit64: {}", OSError::last_os_error().raw_os_error().unwrap());
|
||||
return Err(());
|
||||
}
|
||||
}
|
||||
|
||||
match r {
|
||||
Ok(_) => {
|
||||
return Ok(handle);
|
||||
}
|
||||
Err(e) => {
|
||||
if unsafe { libc::setrlimit64(libc::RLIMIT_RTTIME, &limits) } < 0 {
|
||||
return Err(AudioThreadPriorityError::new_with_inner(&"setrlimit64", Box::new(OSError::last_os_error())));
|
||||
}
|
||||
return Err(AudioThreadPriorityError::new_with_inner(&"Thread promotion error", e));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ use crate::mach_sys::*;
|
|||
use std::mem::size_of;
|
||||
use mach::mach_time::{mach_timebase_info_data_t, mach_timebase_info};
|
||||
use libc::{pthread_t, pthread_self};
|
||||
use crate::AudioThreadPriorityError;
|
||||
use log::info;
|
||||
|
||||
extern "C" {
|
||||
fn pthread_mach_thread_np(tid: pthread_t) -> mach_port_t;
|
||||
|
@ -54,7 +56,7 @@ impl RtPriorityHandleInternal {
|
|||
}
|
||||
|
||||
pub fn demote_current_thread_from_real_time_internal(rt_priority_handle: RtPriorityHandleInternal)
|
||||
-> Result<(), ()> {
|
||||
-> Result<(), AudioThreadPriorityError> {
|
||||
unsafe {
|
||||
let rv: kern_return_t;
|
||||
let mut h = rt_priority_handle;
|
||||
|
@ -64,11 +66,10 @@ pub fn demote_current_thread_from_real_time_internal(rt_priority_handle: RtPrior
|
|||
thread_policy_t,
|
||||
THREAD_TIME_CONSTRAINT_POLICY_COUNT!());
|
||||
if rv != KERN_SUCCESS as i32 {
|
||||
warn!("thread demotion error: thread_policy_set: RT");
|
||||
return Err(());
|
||||
return Err(AudioThreadPriorityError::new("thread demotion error: thread_policy_get: RT"));
|
||||
}
|
||||
|
||||
warn!("thread {} priority restored.", h.tid);
|
||||
info!("thread {} priority restored.", h.tid);
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
|
@ -76,7 +77,7 @@ pub fn demote_current_thread_from_real_time_internal(rt_priority_handle: RtPrior
|
|||
|
||||
pub fn promote_current_thread_to_real_time_internal(audio_buffer_frames: u32,
|
||||
audio_samplerate_hz: u32)
|
||||
-> Result<RtPriorityHandleInternal, ()> {
|
||||
-> Result<RtPriorityHandleInternal, AudioThreadPriorityError> {
|
||||
|
||||
let mut rt_priority_handle = RtPriorityHandleInternal::new();
|
||||
|
||||
|
@ -113,8 +114,7 @@ pub fn promote_current_thread_to_real_time_internal(audio_buffer_frames: u32,
|
|||
&mut get_default);
|
||||
|
||||
if rv != KERN_SUCCESS as i32 {
|
||||
error!("thread promotion error: thread_policy_get: time_constraint");
|
||||
return Err(());
|
||||
return Err(AudioThreadPriorityError::new("thread promotion error: thread_policy_get: time_constraint"));
|
||||
}
|
||||
|
||||
rt_priority_handle.previous_time_constraint_policy = time_constraints;
|
||||
|
@ -139,8 +139,7 @@ pub fn promote_current_thread_to_real_time_internal(audio_buffer_frames: u32,
|
|||
(&mut time_constraints) as *mut _ as thread_policy_t,
|
||||
THREAD_TIME_CONSTRAINT_POLICY_COUNT!());
|
||||
if rv != KERN_SUCCESS as i32 {
|
||||
warn!("thread promotion error: thread_policy_set: time_constraint");
|
||||
return Err(());
|
||||
return Err(AudioThreadPriorityError::new("thread promotion error: thread_policy_set: time_constraint"));
|
||||
}
|
||||
|
||||
info!("thread {} bumped to real time priority.", tid);
|
||||
|
|
|
@ -7,6 +7,10 @@ use winapi::shared::ntdef::HANDLE;
|
|||
use winapi::shared::minwindef::DWORD;
|
||||
use winapi::um::errhandlingapi::GetLastError;
|
||||
|
||||
use crate::AudioThreadPriorityError;
|
||||
|
||||
use log::info;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RtPriorityHandleInternal {
|
||||
mmcss_task_index: DWORD,
|
||||
|
@ -23,12 +27,11 @@ impl RtPriorityHandleInternal {
|
|||
}
|
||||
|
||||
pub fn demote_current_thread_from_real_time_internal(rt_priority_handle: RtPriorityHandleInternal)
|
||||
-> Result<(), ()> {
|
||||
-> Result<(), AudioThreadPriorityError> {
|
||||
unsafe {
|
||||
let rv = AvRevertMmThreadCharacteristics(rt_priority_handle.task_handle);
|
||||
if rv == 0 {
|
||||
warn!("Unable to restore the thread priority ({})", GetLastError());
|
||||
return Err(())
|
||||
return Err(AudioThreadPriorityError::new(&format!("Unable to restore the thread priority ({})", GetLastError())));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,15 +42,14 @@ pub fn demote_current_thread_from_real_time_internal(rt_priority_handle: RtPrior
|
|||
|
||||
pub fn promote_current_thread_to_real_time_internal(_audio_buffer_frames: u32,
|
||||
_audio_samplerate_hz: u32)
|
||||
-> Result<RtPriorityHandleInternal, ()> {
|
||||
-> Result<RtPriorityHandleInternal, AudioThreadPriorityError> {
|
||||
let mut handle = RtPriorityHandleInternal::new();
|
||||
|
||||
unsafe {
|
||||
handle.task_handle = AvSetMmThreadCharacteristicsA("Audio\0".as_ptr() as _, &mut handle.mmcss_task_index);
|
||||
|
||||
if handle.task_handle.is_null() {
|
||||
warn!("Unable to use mmcss to bump the thread priority ({})", GetLastError());
|
||||
return Err(())
|
||||
return Err(AudioThreadPriorityError::new(&format!("Unable to restore the thread priority ({})", GetLastError())));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
{"files":{"Cargo.toml":"1e278b68a4af7dc6212bf86cf8fa94a52ce1e3b318eb5d086053e614cc1e6dbd","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"030621290d10cb2eec6393f553117a1b4245d024efe159eac70c4b57dc121e79","appveyor.yml":"87f3eab680a0ab6a891f8cf109a355d0ce3f4d8bee4728c2e3d45596677ade82","src/lib.rs":"06e5e32338ef81ef6fe1a7efd12a90419463e5b6c54fe179a076dc629eb43e0d"},"package":null}
|
|
@ -1,19 +0,0 @@
|
|||
[package]
|
||||
name = "tokio-named-pipes"
|
||||
version = "0.2.0"
|
||||
authors = ["Alex Crichton <alex@alexcrichton.com>"]
|
||||
license = "MIT/Apache-2.0"
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/alexcrichton/tokio-named-pipes"
|
||||
homepage = "https://github.com/alexcrichton/tokio-named-pipes"
|
||||
documentation = "http://alexcrichton.com/tokio-named-pipes"
|
||||
description = """
|
||||
Windows named pipe bindings for tokio.
|
||||
"""
|
||||
|
||||
[dependencies]
|
||||
mio = "0.6"
|
||||
tokio = "0.1"
|
||||
mio-named-pipes = { git = "https://github.com/alexcrichton/mio-named-pipes" }
|
||||
futures = "0.1"
|
||||
bytes = "0.4"
|
|
@ -1,201 +0,0 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -1,25 +0,0 @@
|
|||
Copyright (c) 2014 Alex Crichton
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
|
@ -1,31 +0,0 @@
|
|||
# tokio-named-pipes
|
||||
[![Build status](https://ci.appveyor.com/api/projects/status/motwon3ro35xwb2x?svg=true)](https://ci.appveyor.com/project/NikolayVolf/tokio-named-pipes)
|
||||
|
||||
[Documentation](http://alexcrichton.com/tokio-named-pipes)
|
||||
|
||||
A library for integrating Windows [Named Pipes] with [tokio].
|
||||
|
||||
[Named Pipes]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365590(v=vs.85).aspx
|
||||
[tokio]: https://github.com/tokio-rs/tokio
|
||||
|
||||
```toml
|
||||
# Cargo.toml
|
||||
[dependencies]
|
||||
tokio-named-pipes = { git = "https://github.com/NikVolf/tokio-named-pipes", branch = "stable" }
|
||||
```
|
||||
|
||||
Next, add this to your crate:
|
||||
|
||||
```rust
|
||||
extern crate tokio_named_pipes;
|
||||
```
|
||||
|
||||
# License
|
||||
|
||||
`tokio-named-pipes` is primarily distributed under the terms of both the MIT
|
||||
license and the Apache License (Version 2.0), with portions covered by various
|
||||
BSD-like licenses.
|
||||
|
||||
See LICENSE-APACHE, and LICENSE-MIT for details.
|
||||
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
environment:
|
||||
matrix:
|
||||
- TARGET: x86_64-pc-windows-msvc
|
||||
|
||||
install:
|
||||
- curl -sSf -o rustup-init.exe https://win.rustup.rs/
|
||||
- rustup-init.exe -y --default-host %TARGET%
|
||||
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin;C:\MinGW\bin
|
||||
|
||||
- rustc -vV
|
||||
- cargo -vV
|
||||
|
||||
build: false
|
||||
|
||||
test_script:
|
||||
- cargo test
|
|
@ -1,154 +0,0 @@
|
|||
#![cfg(windows)]
|
||||
|
||||
extern crate tokio;
|
||||
extern crate bytes;
|
||||
extern crate mio;
|
||||
extern crate mio_named_pipes;
|
||||
extern crate futures;
|
||||
|
||||
use std::ffi::OsStr;
|
||||
use std::fmt;
|
||||
use std::io::{Read, Write};
|
||||
use std::os::windows::io::*;
|
||||
|
||||
use futures::{Async, Poll};
|
||||
use bytes::{BufMut, Buf};
|
||||
use mio::Ready;
|
||||
use tokio::reactor::{Handle, PollEvented2};
|
||||
use tokio::io::{AsyncRead, AsyncWrite};
|
||||
|
||||
pub struct NamedPipe {
|
||||
io: PollEvented2<mio_named_pipes::NamedPipe>,
|
||||
}
|
||||
|
||||
impl NamedPipe {
|
||||
pub fn new<P: AsRef<OsStr>>(p: P, handle: &Handle) -> std::io::Result<NamedPipe> {
|
||||
NamedPipe::_new(p.as_ref(), handle)
|
||||
}
|
||||
|
||||
fn _new(p: &OsStr, handle: &Handle) -> std::io::Result<NamedPipe> {
|
||||
let inner = try!(mio_named_pipes::NamedPipe::new(p));
|
||||
NamedPipe::from_pipe(inner, handle)
|
||||
}
|
||||
|
||||
pub fn from_pipe(pipe: mio_named_pipes::NamedPipe, handle: &Handle)
|
||||
-> std::io::Result<NamedPipe> {
|
||||
Ok(NamedPipe {
|
||||
io: PollEvented2::new_with_handle(pipe, handle)?,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn connect(&self) -> std::io::Result<()> {
|
||||
self.io.get_ref().connect()
|
||||
}
|
||||
|
||||
pub fn disconnect(&self) -> std::io::Result<()> {
|
||||
self.io.get_ref().disconnect()
|
||||
}
|
||||
|
||||
pub fn poll_read_ready_readable(&mut self) -> tokio::io::Result<Async<Ready>> {
|
||||
self.io.poll_read_ready(Ready::readable())
|
||||
}
|
||||
|
||||
pub fn poll_write_ready(&mut self) -> tokio::io::Result<Async<Ready>> {
|
||||
self.io.poll_write_ready()
|
||||
}
|
||||
|
||||
fn io_mut(&mut self) -> &mut PollEvented2<mio_named_pipes::NamedPipe> {
|
||||
&mut self.io
|
||||
}
|
||||
}
|
||||
|
||||
impl Read for NamedPipe {
|
||||
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
|
||||
self.io.read(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl Write for NamedPipe {
|
||||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
||||
self.io.write(buf)
|
||||
}
|
||||
fn flush(&mut self) -> std::io::Result<()> {
|
||||
self.io.flush()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Read for &'a NamedPipe {
|
||||
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
|
||||
(&self.io).read(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Write for &'a NamedPipe {
|
||||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
||||
(&self.io).write(buf)
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> std::io::Result<()> {
|
||||
(&self.io).flush()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsyncRead for NamedPipe {
|
||||
unsafe fn prepare_uninitialized_buffer(&self, _: &mut [u8]) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn read_buf<B: BufMut>(&mut self, buf: &mut B) -> Poll<usize, std::io::Error> {
|
||||
if let Async::NotReady = self.io.poll_read_ready(Ready::readable())? {
|
||||
return Ok(Async::NotReady)
|
||||
}
|
||||
|
||||
let mut stack_buf = [0u8; 1024];
|
||||
let bytes_read = self.io_mut().read(&mut stack_buf);
|
||||
match bytes_read {
|
||||
Err(ref e) if e.kind() == std::io::ErrorKind::WouldBlock => {
|
||||
self.io_mut().clear_read_ready(Ready::readable())?;
|
||||
return Ok(Async::NotReady);
|
||||
},
|
||||
Err(e) => Err(e),
|
||||
Ok(bytes_read) => {
|
||||
buf.put_slice(&stack_buf[0..bytes_read]);
|
||||
Ok(Async::Ready(bytes_read))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AsyncWrite for NamedPipe {
|
||||
fn shutdown(&mut self) -> Poll<(), std::io::Error> {
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
fn write_buf<B: Buf>(&mut self, buf: &mut B) -> Poll<usize, std::io::Error> {
|
||||
if let Async::NotReady = self.io.poll_write_ready()? {
|
||||
return Ok(Async::NotReady)
|
||||
}
|
||||
|
||||
let bytes_wrt = self.io_mut().write(buf.bytes());
|
||||
match bytes_wrt {
|
||||
Err(ref e) if e.kind() == std::io::ErrorKind::WouldBlock => {
|
||||
self.io_mut().clear_write_ready()?;
|
||||
return Ok(Async::NotReady);
|
||||
},
|
||||
Err(e) => Err(e),
|
||||
Ok(bytes_wrt) => {
|
||||
buf.advance(bytes_wrt);
|
||||
Ok(Async::Ready(bytes_wrt))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for NamedPipe {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.io.get_ref().fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRawHandle for NamedPipe {
|
||||
fn as_raw_handle(&self) -> RawHandle {
|
||||
self.io.get_ref().as_raw_handle()
|
||||
}
|
||||
}
|
|
@ -40,7 +40,7 @@ storage = { path = "../../../../storage/rust" }
|
|||
bookmark_sync = { path = "../../../components/places/bookmark_sync", optional = true }
|
||||
shift_or_euc_c = "0.1.0"
|
||||
chardetng_c = "0.1.1"
|
||||
audio_thread_priority = "0.20.2"
|
||||
audio_thread_priority = "0.21"
|
||||
mdns_service = { path="../../../../media/mtransport/mdns_service", optional = true }
|
||||
neqo_glue = { path = "../../../../netwerk/socket/neqo_glue" }
|
||||
rlbox_lucet_sandbox = { version = "0.1.0", optional = true }
|
||||
|
|
Загрузка…
Ссылка в новой задаче