Skip to content

Commit

Permalink
Add a comment to describe the writing 0 scenario (#127)
Browse files Browse the repository at this point in the history
* Early return success when writing 0

* Add a tips for writing 0
  • Loading branch information
mohanson authored Nov 18, 2024
1 parent b1b841f commit 42d6cea
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/syscalls/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,10 @@ pub fn read(fd: u64, buffer: &mut [u8]) -> Result<usize, SysError> {

/// This syscall writes data to a pipe via a file descriptor. The syscall Write writes up to value pointed by length
/// bytes from the buffer, and the actual length of data written is returned.
///
/// If buffer is empty and fd is avaliable, then write() can still succeed: A data with a length of 0 is written to the
/// pipe. The peer needs to use a read() syscall to consume the empty data, and read() will returns Ok(0).
///
/// Note: available after ckb 2nd hardfork.
pub fn write(fd: u64, buffer: &[u8]) -> Result<usize, SysError> {
let mut l: u64 = buffer.len() as u64;
Expand Down

0 comments on commit 42d6cea

Please sign in to comment.