// Precondition: No newlines in the input string
No newlines in the input string
No newlines in the input string
pub fn write(&mut self, v: &[u8]) -> Result<(), WorkerError> {
        // Passing in a newline violates the contract of this method
        if v.contains(&b'\n') {
            return Err(WorkerErrorKind::InvalidSerialization("contains newline", v.to_vec()).into());
        }
        // Push a newline at the end to terminate the input
        let mut v = Vec::from(v);
        v.push(b'\n');
        let (c_in_fd, _) = self.get_fds()?;
        let deadline = Instant::now() + Duration::from_millis(PIPE_IO_TIMEOUT_MS);
        let mut write_idx = 0;
        while write_idx < v.len() && Instant::now() < deadline {
            trace!("Polling {:?}", self.component_input_fifo_path);
            // Wait until ready
            let poll_flags = PollFlags::POLLOUT;
            poll(
                &mut [PollFd::new(c_in_fd, poll_flags)],
                (deadline - Instant::now()).as_millis().try_into()?,
            )?;
            // Then write the bytes
            let written_bytes = write(c_in_fd, &v[write_idx..])?;
            write_idx += written_bytes;
        }
        // If we didn't write everything, we timed out
        if write_idx < v.len() {
            return Err(WorkerErrorKind::OperationTimedOut("pipe writing").into());
        }
        Ok(())
    }
pub fn write ( & mut self , v : & [ u8 ] ) -> Result < ( ) , WorkerError > { // Passing in a newline violates the contract of this method if v . contains ( & b'\n' ) { return Err ( WorkerErrorKind :: InvalidSerialization ( " " , v . to_vec ( ) ) . into ( ) ) ; } // Push a newline at the end to terminate the input let mut v = Vec :: from ( v ) ; v . push ( b'\n' ) ; let ( c_in_fd , _ ) = self . get_fds ( ) ? ; let deadline = Instant :: now ( ) + Duration :: from_millis ( PIPE_IO_TIMEOUT_MS ) ; let mut write_idx = 0 ; while write_idx < v . len ( ) && Instant :: now ( ) < deadline { trace ! ( " " self component_input_fifo_path ) ; // Wait until ready let poll_flags = PollFlags :: POLLOUT ; poll ( & mut [ PollFd :: new ( c_in_fd , poll_flags ) ] , ( deadline - Instant :: now ( ) ) . as_millis ( ) . try_into ( ) ? , ) ? ; // Then write the bytes let written_bytes = write ( c_in_fd , & v [ write_idx .. ] ) ? ; write_idx += written_bytes ; } // If we didn't write everything, we timed out if write_idx < v . len ( ) { return Err ( WorkerErrorKind :: OperationTimedOut ( " " ) . into ( ) ) ; } Ok ( ( ) ) }
Precondition: No newlines in the input string
Precondition : No newlines in the input string
&mut self
v
&[u8]