Skip to content

Commit

Permalink
refine code
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Sep 5, 2024
1 parent 8ec95a6 commit 176716a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use crate::{
error::{Error, OutOfRangeData},
handle::{SafeEvent, UnsafeHandle},
session,
session::Session,
util::{self},
wintun_raw, Wintun,
};
Expand Down Expand Up @@ -146,7 +146,7 @@ impl Adapter {
///
/// Capacity is the size in bytes of the ring buffer used internally by the driver. Must be
/// a power of two between [`crate::MIN_RING_CAPACITY`] and [`crate::MAX_RING_CAPACITY`] inclusive.
pub fn start_session(self: &Arc<Self>, capacity: u32) -> Result<Arc<session::Session>, Error> {
pub fn start_session(self: &Arc<Self>, capacity: u32) -> Result<Arc<Session>, Error> {
Self::validate_capacity(capacity)?;

let result = unsafe { self.wintun.WintunStartSession(self.adapter.0, capacity) };
Expand All @@ -156,7 +156,7 @@ impl Adapter {
}
// Manual reset, because we use this event once and it must fire on all threads
let shutdown_event = SafeEvent::new(true, false)?;
Ok(Arc::new(session::Session {
Ok(Arc::new(Session {
session: UnsafeHandle(result),
read_event: OnceLock::new(),
shutdown_event: Arc::new(shutdown_event),
Expand Down
10 changes: 5 additions & 5 deletions src/async_session.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::handle::UnsafeHandle;
use crate::{handle::UnsafeHandle, session::Session};
use futures::{AsyncRead, AsyncWrite};
use std::future::Future;
use std::pin::Pin;
Expand All @@ -24,20 +24,20 @@ enum ReadState {

#[derive(Clone)]
pub struct AsyncSession {
session: Arc<crate::session::Session>,
session: Arc<Session>,
read_state: ReadState,
}

impl std::ops::Deref for AsyncSession {
type Target = crate::session::Session;
type Target = Session;

fn deref(&self) -> &Self::Target {
&self.session
}
}

impl From<Arc<crate::session::Session>> for AsyncSession {
fn from(session: Arc<crate::session::Session>) -> Self {
impl From<Arc<Session>> for AsyncSession {
fn from(session: Arc<Session>) -> Self {
Self {
session,
read_state: ReadState::Idle,
Expand Down
4 changes: 2 additions & 2 deletions src/packet.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::session;
use crate::session::Session;
use std::sync::Arc;

pub(crate) enum Kind {
Expand Down Expand Up @@ -38,7 +38,7 @@ pub struct Packet {

/// Share ownership of session to prevent the session from being dropped before packets that
/// belong to it
pub(crate) session: Arc<session::Session>,
pub(crate) session: Arc<Session>,
}

impl Packet {
Expand Down

0 comments on commit 176716a

Please sign in to comment.