From 42d6cea0ded03cc8dfc249911b06a75b46bceed2 Mon Sep 17 00:00:00 2001 From: Mohanson Date: Mon, 18 Nov 2024 11:20:17 +0800 Subject: [PATCH] Add a comment to describe the writing 0 scenario (#127) * Early return success when writing 0 * Add a tips for writing 0 --- src/syscalls/native.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/syscalls/native.rs b/src/syscalls/native.rs index 5651bcc..258e672 100644 --- a/src/syscalls/native.rs +++ b/src/syscalls/native.rs @@ -735,6 +735,10 @@ pub fn read(fd: u64, buffer: &mut [u8]) -> Result { /// 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 { let mut l: u64 = buffer.len() as u64;