mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-18 05:41:50 +01:00
remove PayloadWriter trait
This commit is contained in:
parent
ec09d6fbe6
commit
219baf3323
@ -19,7 +19,7 @@ use crate::request::Request;
|
|||||||
use crate::response::Response;
|
use crate::response::Response;
|
||||||
|
|
||||||
use super::codec::Codec;
|
use super::codec::Codec;
|
||||||
use super::payload::{Payload, PayloadSender, PayloadStatus, PayloadWriter};
|
use super::payload::{Payload, PayloadSender, PayloadStatus};
|
||||||
use super::{Message, MessageType};
|
use super::{Message, MessageType};
|
||||||
|
|
||||||
const LW_BUFFER_SIZE: usize = 4096;
|
const LW_BUFFER_SIZE: usize = 4096;
|
||||||
|
@ -14,7 +14,7 @@ pub use self::client::{ClientCodec, ClientPayloadCodec};
|
|||||||
pub use self::codec::Codec;
|
pub use self::codec::Codec;
|
||||||
pub use self::dispatcher::Dispatcher;
|
pub use self::dispatcher::Dispatcher;
|
||||||
pub use self::expect::ExpectHandler;
|
pub use self::expect::ExpectHandler;
|
||||||
pub use self::payload::{Payload, PayloadWriter};
|
pub use self::payload::Payload;
|
||||||
pub use self::service::{H1Service, H1ServiceHandler, OneRequest};
|
pub use self::service::{H1Service, H1ServiceHandler, OneRequest};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -97,58 +97,35 @@ impl Stream for Payload {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for Payload {
|
|
||||||
fn clone(&self) -> Payload {
|
|
||||||
Payload {
|
|
||||||
inner: Rc::clone(&self.inner),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Payload writer interface.
|
|
||||||
pub trait PayloadWriter {
|
|
||||||
/// Set stream error.
|
|
||||||
fn set_error(&mut self, err: PayloadError);
|
|
||||||
|
|
||||||
/// Write eof into a stream which closes reading side of a stream.
|
|
||||||
fn feed_eof(&mut self);
|
|
||||||
|
|
||||||
/// Feed bytes into a payload stream
|
|
||||||
fn feed_data(&mut self, data: Bytes);
|
|
||||||
|
|
||||||
/// Need read data
|
|
||||||
fn need_read(&self) -> PayloadStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sender part of the payload stream
|
/// Sender part of the payload stream
|
||||||
pub struct PayloadSender {
|
pub struct PayloadSender {
|
||||||
inner: Weak<RefCell<Inner>>,
|
inner: Weak<RefCell<Inner>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PayloadWriter for PayloadSender {
|
impl PayloadSender {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn set_error(&mut self, err: PayloadError) {
|
pub fn set_error(&mut self, err: PayloadError) {
|
||||||
if let Some(shared) = self.inner.upgrade() {
|
if let Some(shared) = self.inner.upgrade() {
|
||||||
shared.borrow_mut().set_error(err)
|
shared.borrow_mut().set_error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn feed_eof(&mut self) {
|
pub fn feed_eof(&mut self) {
|
||||||
if let Some(shared) = self.inner.upgrade() {
|
if let Some(shared) = self.inner.upgrade() {
|
||||||
shared.borrow_mut().feed_eof()
|
shared.borrow_mut().feed_eof()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn feed_data(&mut self, data: Bytes) {
|
pub fn feed_data(&mut self, data: Bytes) {
|
||||||
if let Some(shared) = self.inner.upgrade() {
|
if let Some(shared) = self.inner.upgrade() {
|
||||||
shared.borrow_mut().feed_data(data)
|
shared.borrow_mut().feed_data(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn need_read(&self) -> PayloadStatus {
|
pub fn need_read(&self) -> PayloadStatus {
|
||||||
// we check need_read only if Payload (other side) is alive,
|
// we check need_read only if Payload (other side) is alive,
|
||||||
// otherwise always return true (consume payload)
|
// otherwise always return true (consume payload)
|
||||||
if let Some(shared) = self.inner.upgrade() {
|
if let Some(shared) = self.inner.upgrade() {
|
||||||
|
@ -776,7 +776,7 @@ impl PayloadBuffer {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use actix_http::h1::{Payload, PayloadWriter};
|
use actix_http::h1::Payload;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures::unsync::mpsc;
|
use futures::unsync::mpsc;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user