morpheus_network::state::disk_writer

Struct DiskWriterState

Source
pub struct DiskWriterState {
    state: WriterState,
    config: DiskWriterConfig,
    current_sector: u64,
    next_request_id: u32,
    pending: [PendingWrite; 16],
    pending_count: usize,
    progress: DiskWriterProgress,
    error: Option<DiskWriterError>,
}
Expand description

ISO streaming disk writer state machine.

Manages non-blocking writes of ISO data to disk.

§Usage

let mut writer = DiskWriterState::new(config);
writer.start(&mut block_driver)?;

// Write chunks as they arrive from HTTP
while let Some(chunk) = http_download.next_chunk() {
    match writer.write_chunk(&mut block_driver, chunk_phys, chunk.len()) {
        Ok(()) => {},
        Err(DiskWriterError::QueueFull) => {
            // Backpressure: wait for completions
        }
        Err(e) => return Err(e),
    }
}

// Flush and wait for all completions
writer.finish();
while writer.step(&mut block_driver).is_pending() {
    // Poll completions
}

Fields§

§state: WriterState

Current state.

§config: DiskWriterConfig

Configuration.

§current_sector: u64

Current sector for next write.

§next_request_id: u32

Next request ID.

§pending: [PendingWrite; 16]

Pending writes.

§pending_count: usize

Number of active pending writes.

§progress: DiskWriterProgress

Progress tracking.

§error: Option<DiskWriterError>

Error (if any).

Implementations§

Source§

impl DiskWriterState

Source

pub fn new(config: DiskWriterConfig) -> Self

Create new disk writer with configuration.

Source

pub fn state(&self) -> WriterState

Get current state.

Source

pub fn progress(&self) -> DiskWriterProgress

Get write progress.

Source

pub fn error(&self) -> Option<DiskWriterError>

Get error (if in Failed state).

Source

pub fn can_write(&self) -> bool

Check if writer can accept more writes.

Returns false if:

  • Write queue is full (backpressure)
  • Writer is not in Ready/Writing state
Source

pub fn is_complete(&self) -> bool

Check if all writes are complete.

Source

pub fn has_pending(&self) -> bool

Check if writer has pending writes.

Source

pub fn start<D: BlockDriver>( &mut self, driver: &D, ) -> Result<(), DiskWriterError>

Start the writer.

Validates that disk has sufficient space.

Source

pub fn write_chunk<D: BlockDriver>( &mut self, driver: &mut D, buffer_phys: u64, len: usize, ) -> Result<(), DiskWriterError>

Write a chunk of data to disk.

§Arguments
  • driver: Block driver to use
  • buffer_phys: Physical address of data buffer
  • len: Length of data in bytes
§Returns
  • Ok(()): Write submitted
  • Err(QueueFull): Backpressure, try again after polling completions
  • Err(...): Write failed
§Contract
  • len should be multiple of sector_size for best performance
  • Buffer must remain valid until completion
Source

pub fn finish(&mut self)

Mark writing as finished (no more data coming).

Transitions to Flushing state to wait for pending completions.

Source

pub fn step<D: BlockDriver>(&mut self, driver: &mut D) -> StepResult

Step the state machine (poll completions).

Should be called regularly to process write completions.

§Returns
  • Pending: More completions expected
  • Done: All writes completed
  • Failed: A write failed
Source

fn handle_completion(&mut self, completion: BlockCompletion)

Process a write completion.

Source

fn find_free_slot(&self) -> Option<usize>

Find a free pending slot.

Source

pub fn next_sector(&self) -> u64

Get the next sector to write to.

Source

pub fn remaining_bytes(&self) -> Option<u64>

Get remaining bytes to write (if total known).

Source

pub fn set_total_bytes(&mut self, total: u64)

Update total bytes (e.g., after HTTP Content-Length received).

Auto Trait Implementations§

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<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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.