Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/firecracker
Path: blob/main/src/devices/tests/serial_utils/mod.rs
1958 views
1
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
// SPDX-License-Identifier: Apache-2.0
3
4
use devices::legacy::ReadableFd;
5
use std::io;
6
use std::os::raw::c_void;
7
use std::os::unix::io::AsRawFd;
8
use std::os::unix::io::RawFd;
9
10
pub struct MockSerialInput(pub RawFd);
11
12
impl io::Read for MockSerialInput {
13
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
14
let count = unsafe { libc::read(self.0, buf.as_mut_ptr() as *mut c_void, buf.len()) };
15
if count < 0 {
16
return Err(io::Error::last_os_error());
17
}
18
19
Ok(count as usize)
20
}
21
}
22
23
impl AsRawFd for MockSerialInput {
24
fn as_raw_fd(&self) -> RawFd {
25
self.0
26
}
27
}
28
29
impl ReadableFd for MockSerialInput {}
30
31