Skip to content

Commit 61b4272

Browse files
committed
fix large TCP sends
1 parent 6966225 commit 61b4272

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

tcp_wasip2.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,15 @@ func (c wasip2TcpSocket) Send(buf []byte, flags int, deadline time.Time) (int, e
138138
return -1, fmt.Errorf("send called on a socket without open streams")
139139
}
140140

141-
res := c.BlockingWriteAndFlush(cm.ToList([]uint8(buf)))
141+
cw, err, iserr := c.CheckWrite().Result()
142+
if iserr {
143+
return -1, fmt.Errorf("failed to do check-write on the output stream: %s", err.String())
144+
}
145+
if cw < uint64(len(buf)) {
146+
return -1, fmt.Errorf("failed to send: writeable %d < length %d", cw, len(buf))
147+
}
148+
149+
res := c.Write(cm.ToList([]uint8(buf)))
142150
if res.IsErr() {
143151
return -1, fmt.Errorf("failed to write to output stream: %s", res.Err().String())
144152
}

0 commit comments

Comments
 (0)