Skip to content

Commit

Permalink
build: Add support for macOS
Browse files Browse the repository at this point in the history
Signed-off-by: Akira Moroo <[email protected]>
  • Loading branch information
retrage committed Aug 24, 2024
1 parent 3a41323 commit a01de72
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tonic-conn = ["tonic"]
bytes = "1.3.0"
futures = "0.3"
libc = "0.2.138"
vsock = "0.5.0"
vsock = { git = "https://github.com/rust-vsock/vsock-rs", rev = "2223f5a" }
tokio = { version = "1", features = ["net", "sync"] }
tonic = { version = "0.12.0", optional = true }

Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ pub use stream::VsockStream;
#[cfg(feature = "tonic-conn")]
#[cfg_attr(docsrs, doc(cfg(feature = "tonic-conn")))]
pub use tonic_support::VsockConnectInfo;
pub use vsock::{
VsockAddr, VMADDR_CID_ANY, VMADDR_CID_HOST, VMADDR_CID_HYPERVISOR, VMADDR_CID_LOCAL,
};
#[cfg(any(target_os = "linux", target_os = "android"))]
pub use vsock::VMADDR_CID_LOCAL;
pub use vsock::{VsockAddr, VMADDR_CID_ANY, VMADDR_CID_HOST, VMADDR_CID_HYPERVISOR};
4 changes: 2 additions & 2 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ impl VsockStream {

/// Open a connection to a remote host.
pub async fn connect(addr: VsockAddr) -> Result<Self> {
let socket = unsafe { socket(AF_VSOCK, SOCK_STREAM | SOCK_CLOEXEC, 0) };
let socket = unsafe { socket(AF_VSOCK, SOCK_STREAM, 0) };
if socket < 0 {
return Err(Error::last_os_error());
}

if unsafe { fcntl(socket, F_SETFL, O_NONBLOCK) } < 0 {
if unsafe { fcntl(socket, F_SETFL, O_NONBLOCK | O_CLOEXEC) } < 0 {
let _ = unsafe { close(socket) };
return Err(Error::last_os_error());
}
Expand Down
6 changes: 5 additions & 1 deletion tests/vsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
use rand::RngCore;
use sha2::{Digest, Sha256};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio_vsock::{VsockAddr, VsockListener, VsockStream};
#[cfg(target_os = "linux")]
use tokio_vsock::VsockListener;
use tokio_vsock::{VsockAddr, VsockStream};

const TEST_BLOB_SIZE: usize = 100_000;
const TEST_BLOCK_SIZE: usize = 5_000;
Expand Down Expand Up @@ -90,6 +92,7 @@ async fn test_vsock_conn_error() {
///
/// source: https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/tests/tcp_split.rs
#[tokio::test]
#[cfg(target_os = "linux")]
async fn split_vsock() {
const MSG: &[u8] = b"split";
const PORT: u32 = 8002;
Expand Down Expand Up @@ -139,6 +142,7 @@ async fn split_vsock() {
///
/// source: https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/tests/tcp_split.rs
#[tokio::test]
#[cfg(target_os = "linux")]
async fn into_split_vsock() {
const MSG: &[u8] = b"split";
const PORT: u32 = 8001;
Expand Down

0 comments on commit a01de72

Please sign in to comment.