From 6b764b82c28a2ed56f91f866b72b56c5fc96c6dc Mon Sep 17 00:00:00 2001 From: mohanson Date: Mon, 18 Nov 2024 11:04:33 +0800 Subject: [PATCH] Add a tips for writing 0 --- src/syscalls/native.rs | 7 ++++--- src/syscalls/simulator.rs | 3 --- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/syscalls/native.rs b/src/syscalls/native.rs index a684b71..258e672 100644 --- a/src/syscalls/native.rs +++ b/src/syscalls/native.rs @@ -735,12 +735,13 @@ 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; - if l == 0 { - return Ok(0); - } let ret = unsafe { syscall( fd, diff --git a/src/syscalls/simulator.rs b/src/syscalls/simulator.rs index bc799ad..a0397fb 100644 --- a/src/syscalls/simulator.rs +++ b/src/syscalls/simulator.rs @@ -345,9 +345,6 @@ pub fn read(fd: u64, buffer: &mut [u8]) -> Result { pub fn write(fd: u64, buffer: &[u8]) -> Result { let mut l = buffer.len(); - if l == 0 { - return Ok(0); - } let ret = sim::ckb_write(fd, buffer.as_ptr() as *mut c_void, &mut l as *mut usize) as u64; match ret { 0 => Ok(l as usize),