pub struct Connection { /* private fields */ }Expand description
表示一个TCP连接
Connection 封装了一个TCP流和相关的缓冲区,提供了读取请求和发送响应的方法。
它负责处理底层的网络IO操作,并将原始字节数据转换为应用层的请求和响应对象。
Implementations§
Source§impl Connection
impl Connection
Sourcepub fn remote_addr(&self) -> Result<SocketAddr, ZerustError>
pub fn remote_addr(&self) -> Result<SocketAddr, ZerustError>
Sourcepub async fn read_request(&mut self) -> Result<Request, ZerustError>
pub async fn read_request(&mut self) -> Result<Request, ZerustError>
从连接中异步读取一个完整的请求消息
该函数首先读取固定大小的消息头,解析出消息ID和数据长度, 然后根据数据长度读取相应的消息体数据,最后构造成Request对象返回。
§Returns
Result<Request, ZerustError>- 成功时返回解析出的请求对象,失败时返回错误信息
Sourcepub async fn send_response(
&mut self,
resp: &Response,
) -> Result<(), ZerustError>
pub async fn send_response( &mut self, resp: &Response, ) -> Result<(), ZerustError>
Auto Trait Implementations§
impl !Freeze for Connection
impl RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl UnsafeUnpin for Connection
impl UnwindSafe for Connection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more