-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: backport tinygo/v1 fd_write fixes
Backport following commits for tinygo/v0: * fix: unfairWorker may fail due to partial write * refactor: use == comparison for basic errors Signed-off-by: Gaukas Wang <[email protected]>
- Loading branch information
Showing
4 changed files
with
115 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package net | ||
|
||
import "syscall" | ||
|
||
// writeFD writes data to the file descriptor fd. When a partial write occurs, | ||
// it will continue with the remaining data until all data is written or an | ||
// error occurs. If no progress is made in a single write call, it will return | ||
// syscall.EIO. | ||
// | ||
// It is ported from (*FD).Write in golang/go/src/internal/poll/fd_unix.go | ||
func writeFD(fd uintptr, p []byte) (int, error) { | ||
var nn int | ||
for { | ||
n, err := ignoringEINTRIO(syscall.Write, syscallFd(fd), p[nn:]) | ||
if n > 0 { | ||
nn += n | ||
} | ||
if nn == len(p) { | ||
return nn, err | ||
} | ||
if err != nil { | ||
return nn, err | ||
} | ||
if n == 0 { | ||
return nn, syscall.EIO | ||
} | ||
|
||
// // TODO: retry if EAGAIN or no progress? | ||
// if n == 0 { | ||
// noprogress++ | ||
// } | ||
// if noprogress == 10 { | ||
// return nn, syscall.EIO | ||
// } | ||
// runtime.Gosched() | ||
} | ||
} | ||
|
||
// ignoringEINTRIO is like ignoringEINTR, but just for IO calls. | ||
func ignoringEINTRIO(fn func(fd syscallFd, p []byte) (int, error), fd syscallFd, p []byte) (int, error) { | ||
for { | ||
n, err := fn(fd, p) | ||
if err != syscall.EINTR { | ||
return n, err | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters