[][src]Struct udp_server::Peer

pub struct Peer<T: Send> {
    pub socket_id: usize,
    pub addr: SocketAddr,
    pub token: Option<RefCell<T>>,
    pub udp_sock: Weak<Mutex<SendHalf>>,
}

Peer 对象 用来标识client socket_id 标识 所在哪个UDPContent,一般只在头一次接收到数据的时候设置 一般用来所在Peer位置,linux 服务器上启用了 reuse_port 所以后续收到数据包不一定来自于此 所在哪个UDPContent 而windows上只有一个socket,所以始终只有1个

token

你可以自定义放一些和用户有关的数据,这样的话方便你对用户进行区别,已提取用户逻辑数据

Fields

socket_id: usizeaddr: SocketAddrtoken: Option<RefCell<T>>udp_sock: Weak<Mutex<SendHalf>>

Implementations

impl<T: Send> Peer<T>[src]

pub async fn send<'_, '_>(
    &'_ mut self,
    data: &'_ [u8]
) -> Result<usize, Box<dyn Error>>
[src]

Send 发送数据包 作为最基本的函数之一,它采用了tokio的async send_to 首先,他会去弱指针里面拿到强指针,如果没有他会爆错

Trait Implementations

impl<T: Debug + Send> Debug for Peer<T>[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for Peer<T>

impl<T> Send for Peer<T>

impl<T> !Sync for Peer<T>

impl<T> Unpin for Peer<T> where
    T: Unpin

impl<T> !UnwindSafe for Peer<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.