Skip to content

Commit

Permalink
Fix Windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
joerivanruth committed Apr 12, 2024
1 parent fbd7031 commit 27c328d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/proxy/forward.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{
io::{self, ErrorKind, Read, Write},
mem::MaybeUninit,
ops::ControlFlow::{self, Break, Continue},
vec,
};
Expand Down Expand Up @@ -484,10 +483,11 @@ impl Copying {
Ok(progress)
}

#[cfg(feature = "oob")]
#[allow(dead_code)]
fn recv_oob(r: &mut MioStream) -> io::Result<Option<u8>> {
r.with_socket2(|sock2| {
let mut buf = [MaybeUninit::uninit()];
let mut buf = [std::mem::MaybeUninit::uninit()];
let x = sock2.recv_out_of_band(&mut buf);
match x {
Ok(1) => {
Expand All @@ -504,6 +504,7 @@ impl Copying {
}

#[allow(dead_code)]
#[cfg(feature = "oob")]
fn send_oob(w: &mut MioStream, msg: u8) -> io::Result<usize> {
let ret = w.with_socket2(|sock2| sock2.send_out_of_band(&[msg]));
match ret.as_ref().map_err(|e| e.kind()) {
Expand Down
7 changes: 4 additions & 3 deletions src/proxy/network.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::io::{self, ErrorKind};
use std::mem::ManuallyDrop;
use std::os::fd::{AsRawFd, FromRawFd};
use std::{fs, net};

use mio::net::{TcpListener, TcpStream};
Expand Down Expand Up @@ -242,10 +240,13 @@ impl MioStream {
}
}

#[cfg(feature = "oob")]
pub fn with_socket2<T, F>(&mut self, f: F) -> io::Result<T>
where
F: FnOnce(&mut socket2::Socket) -> io::Result<T>,
{
use std::os::fd::{AsRawFd, FromRawFd};

let fd = match self {
MioStream::Tcp(sock) => sock.as_raw_fd(),
MioStream::Unix(sock) => sock.as_raw_fd(),
Expand All @@ -254,7 +255,7 @@ impl MioStream {
// SAFETY: it's clear from above that fd is always a socket.
socket2::Socket::from_raw_fd(fd)
};
let mut dont_drop = ManuallyDrop::new(sock2);
let mut dont_drop = std::mem::ManuallyDrop::new(sock2);
f(&mut dont_drop)
}
}
Expand Down

0 comments on commit 27c328d

Please sign in to comment.