Skip to content

Commit

Permalink
fix: naively handle errno 6 EAGAIN on write
Browse files Browse the repository at this point in the history
temp fix: keep retrying writing until succeed on EAGAIN

Signed-off-by: Gaukas Wang <[email protected]>
  • Loading branch information
gaukas committed Jun 21, 2024
1 parent 41095ba commit 329a77d
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions tinygo/v1/net/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,19 @@ func (c *TCPConn) Read(b []byte) (n int, err error) {

// Write implements [net.Conn.Write].
func (c *TCPConn) Write(b []byte) (n int, writeErr error) {
if wdl := c.writeDeadline; wdl.IsZero() {
// if no deadline set, behavior depends on blocking mode of the
// underlying file descriptor.
return syscallFnFd(c.rawConn, func(fd uintptr) (int, error) {
return writeFD(fd, b)
})
} else {
// writeDeadline is set, if EAGAIN/EWOULDBLOCK is returned,
// we retry until the deadline is reached.
if err := c.rawConn.Write(func(fd uintptr) (done bool) {
n, writeErr = writeFD(fd, b)
if errors.Is(writeErr, syscall.EAGAIN) {
if time.Now().Before(wdl) {
return false
}
writeErr = os.ErrDeadlineExceeded
if err := c.rawConn.Write(func(fd uintptr) (done bool) {
n, writeErr = writeFD(fd, b)
if errors.Is(writeErr, syscall.EAGAIN) {
if wdl := c.writeDeadline; wdl.IsZero() || time.Now().Before(wdl) {
return false
}
return true
}); err != nil {
return 0, err
writeErr = os.ErrDeadlineExceeded
}
return
return true
}); err != nil {
return n, err
}
return
}

// Close implements [net.Conn.Close].
Expand Down

0 comments on commit 329a77d

Please sign in to comment.