Skip to main content

UploadWriter

Struct UploadWriter 

Source
pub struct UploadWriter { /* private fields */ }
Expand description

The writing end of a streamed UploadBody, from UploadBody::channel.

The writer and the upload run together. So a caller writes from a task other than the task that awaits Fetcher::upload, or joins the two futures.

§Frames

Writes fill a frame of 64 KiB. The writer gives a full frame to the connection through a slot of one frame. If the slot is still full, a write waits until hyper takes the frame in it.

  • flush hands over a part-filled frame, and waits until hyper takes it.
  • close hands over the rest, ends the body, and waits until hyper takes the end.

A flush of less than 4 KiB hands over a copy of the bytes and keeps the frame buffer. A larger frame moves to the connection as it is, and the next write allocates the next buffer.

§Memory

The writer holds at most two frames: the frame that it fills and the frame in the slot. The connection holds more for each upload in flight.

Over HTTP/1.1, hyper takes another frame while it holds fewer than 16 frames and less than 408 KiB. So it holds up to 472 KiB. Over HTTP/2, it holds up to two frames.

§Stalls

After the upload hands its request to the connection, a frame can wait in the slot for the progress_timeout of its fetcher. If it does, the wait fails with io::ErrorKind::TimedOut, and the body fails. Before the hand-over, a wait has no bound of its own.

§Failures

If the writer is dropped before close, the body fails. So hyper ends the request unfinished, and the server never receives a truncated body as a whole body. A writer dropped before the hand-over leaves the request unsent.

A write fails with io::ErrorKind::BrokenPipe in these cases:

  • after close
  • after the upload is done with the body
  • after the response ended before the body.

A failure is latched: each later call fails in the same way.

Implementations§

Source§

impl UploadWriter

Source

pub fn is_handed_over(&self) -> bool

Returns true if the request of this body is handed over to a connection.

The value becomes true at the hand-over. It becomes false again if the connection gives the request back unwritten, until the next round hands it over. A caller that counts the bytes that a request sent counts the bytes that it wrote after the hand-over.

Trait Implementations§

Source§

impl AsyncWrite for UploadWriter

The write trait of futures-io.

Source§

fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>

Attempt to write bytes from buf into the object. Read more
Source§

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Attempt to flush the object, ensuring that any buffered data reach their destination. Read more
Source§

fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Attempt to close the object. Read more
Source§

fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, Error>>

Attempt to write bytes from bufs into the object using vectored IO operations. Read more
Source§

impl Debug for UploadWriter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for UploadWriter

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl Forget for UploadWriter

§

impl Freeze for UploadWriter
where *const ArcInner<Exchange> is !null: Freeze, PhantomData<ArcInner<Exchange>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const (): Freeze, &'static RawWakerVTable: Freeze,

§

impl Move for UploadWriter

§

impl RefUnwindSafe for UploadWriter

§

impl Send for UploadWriter
where Arc<Exchange>: Send, RawVecInner: Send, Waker: Send,

§

impl Sync for UploadWriter
where Arc<Exchange>: Sync, RawVecInner: Sync, Waker: Sync,

§

impl Unpin for UploadWriter
where Arc<Exchange>: Unpin, *const u8 is !null: Unpin, Waker: Unpin,

§

impl UnsafeUnpin for UploadWriter
where *const ArcInner<Exchange> is !null: UnsafeUnpin, PhantomData<ArcInner<Exchange>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const (): UnsafeUnpin, &'static RawWakerVTable: UnsafeUnpin,

§

impl UnwindSafe for UploadWriter
where Arc<Exchange>: UnwindSafe, RawVecInner: UnwindSafe, *const (): UnwindSafe, &'static RawWakerVTable: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<W> AsyncWriteExt for W
where W: AsyncWrite + ?Sized,

Source§

fn write<'a>(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self> ⓘ
where Self: Unpin,

Writes some bytes into the byte stream. Read more
Source§

fn write_vectored<'a>( &'a mut self, bufs: &'a [IoSlice<'a>], ) -> WriteVectoredFuture<'a, Self> ⓘ
where Self: Unpin,

Like write(), except that it writes a slice of buffers. Read more
Source§

fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self> ⓘ
where Self: Unpin,

Writes an entire buffer into the byte stream. Read more
Source§

fn flush(&mut self) -> FlushFuture<'_, Self> ⓘ
where Self: Unpin,

Flushes the stream to ensure that all buffered contents reach their destination. Read more
Source§

fn close(&mut self) -> CloseFuture<'_, Self> ⓘ
where Self: Unpin,

Closes the writer. Read more
Source§

fn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + Send + 'a>>
where Self: Sized + Send + 'a,

Available on crate feature alloc only.
Boxes the writer and changes its type to dyn AsyncWrite + Send + 'a. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more