Go internal/poll/fd_unix.go 代码在这里
// Write implements io.Writer.
func (fd *FD) Write(p []byte) (int, error) {
if err := fd.writeLock(); err != nil {
return 0, err
}
defer fd.writeUnlock()
......
}
java代码java.net.SocketOutputStream#socketWrite在这里
private void socketWrite(byte b[], int off, int len) throws IOException {
if (len <= 0 || off < 0 || len > b.length - off) {
if (len == 0) {
return;
}
throw new ArrayIndexOutOfBoundsException("len == " + len
+ " off == " + off + " buffer length == " + b.length);
}
FileDescriptor fd = impl.acquireFD();
try {
socketWrite0(fd, b, off, len);
} catch (SocketException se) {
......
我不知道为什么我们需要锁定它。另一个问题是 syscall.Write 等效于 <unistd.h> 用 C 编写吗?
婷婷同学_
慕码人2483693
相关分类