syscall write returns -1 and set errno is a trivial case. I am interested in the status of errno if write call returning zero or positive. The wrapper of Go simply returns err if errno is not zero, which also includes the case of write call returns positive.
In reading the man page, you are confusing the behavior of the C library function write with the system call write. Go's syscall package invokes the system call directly. The system call in effect returns two values: the number of bytes written, and an error value. Those translate directly into the values returned by syscall.Write.
Hi @ianlancetaylor, thanks for your clarification. I think this issue points to the difference between C write call and Go syscall.Write, which is unclear for developers.
According to the man page, the 0 return is clearly defined in C write call for to files and for non-blocking sockets, but it's unclear whether there are non-error conditions for a blocking socket which would result in a write() not blocking, returning 0, and (presumably) possibly succeeding later if retried.
Indeed Go directly wraps system call write. However, the following code snippet seems not safe because written equals to zero is a case that may trigger err but we don't want to break the loop: