refactor(nix-daemon/framed): simplify partial header read
Rather than having separate branches, just make it part of the state machine discipline. Change-Id: Ib21456227515506495ca06ac2a8a529d04f95fde Reviewed-on: https://cl.snix.dev/c/snix/+/30496 Reviewed-by: Brian Olsen <brian@maven-group.org> Tested-by: besadii Reviewed-by: Florian Klink <flokli@flokli.de>
This commit is contained in:
		
							parent
							
								
									d5c5269ca4
								
							
						
					
					
						commit
						4749964f06
					
				
					 1 changed files with 6 additions and 7 deletions
				
			
		|  | @ -70,6 +70,12 @@ impl<R: AsyncRead> AsyncRead for NixFramedReader<R> { | |||
|                 State::Eof => { | ||||
|                     return Ok(()).into(); | ||||
|                 } | ||||
|                 State::Length { buf, filled: 8 } => { | ||||
|                     *this.state = match NonZeroU64::new(u64::from_le_bytes(*buf)) { | ||||
|                         None => State::Eof, | ||||
|                         Some(remaining) => State::Chunk { remaining }, | ||||
|                     }; | ||||
|                 } | ||||
|                 State::Length { buf, filled } => { | ||||
|                     let bytes_read = { | ||||
|                         let mut b = ReadBuf::new(&mut buf[*filled as usize..]); | ||||
|  | @ -82,13 +88,6 @@ impl<R: AsyncRead> AsyncRead for NixFramedReader<R> { | |||
|                     } | ||||
| 
 | ||||
|                     *filled += bytes_read; | ||||
| 
 | ||||
|                     if *filled == 8 { | ||||
|                         *this.state = match NonZeroU64::new(u64::from_le_bytes(*buf)) { | ||||
|                             None => State::Eof, | ||||
|                             Some(remaining) => State::Chunk { remaining }, | ||||
|                         }; | ||||
|                     } | ||||
|                 } | ||||
|                 State::Chunk { remaining } => { | ||||
|                     let bytes_read = ready!(with_limited(buf, remaining.get(), |buf| { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue