Skip to content

Commit

Permalink
improvement: stop set nonblocking by default
Browse files Browse the repository at this point in the history
This change should not break any existing behavior. If the WebAssembly did not explicitly call set_nonblocking or equivalent within, wazero is unaware of the fd is in nonblocking state and will not work in non-blocking mode when serving WASI API.
  • Loading branch information
gaukas committed Jan 2, 2024
1 parent 026f8c9 commit 3c0bc56
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 49 deletions.
31 changes: 0 additions & 31 deletions socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import (
"fmt"
"net"
"os"
"syscall"

"github.com/gaukas/water/internal/log"
)

// InsertConn implements Core.
Expand All @@ -17,11 +14,6 @@ func (c *core) InsertConn(conn net.Conn) (fd int32, err error) {

switch conn := conn.(type) {
case *net.TCPConn:
// make it non-blocking
if err := setNonblock(conn); err != nil {
return 0, fmt.Errorf("water: error setting non-blocking mode: %w", err)
}

key, ok := c.instance.InsertTCPConn(conn)
if !ok {
return 0, fmt.Errorf("water: (*wazero.Module).InsertTCPConn returned false")
Expand All @@ -44,11 +36,6 @@ func (c *core) InsertListener(listener net.Listener) (fd int32, err error) {

switch listener := listener.(type) {
case *net.TCPListener:
// make it non-blocking
if err := setNonblock(listener); err != nil {
return 0, fmt.Errorf("water: error setting non-blocking mode: %w", err)
}

key, ok := c.instance.InsertTCPListener(listener)
if !ok {
return 0, fmt.Errorf("water: (*wazero.Module).InsertTCPListener returned false")
Expand All @@ -69,11 +56,6 @@ func (c *core) InsertFile(osFile *os.File) (fd int32, err error) {
return 0, fmt.Errorf("water: cannot insert File before instantiation")
}

// make it non-blocking
if err := setNonblock(osFile); err != nil {
return 0, fmt.Errorf("water: error setting non-blocking mode: %w", err)
}

key, ok := c.instance.InsertOSFile(osFile)
if !ok {
return 0, fmt.Errorf("water: (*wazero.Module).InsertFile returned false")
Expand All @@ -84,16 +66,3 @@ func (c *core) InsertFile(osFile *os.File) (fd int32, err error) {

return key, nil
}

func setNonblock(conn syscall.Conn) error {
rawConn, err := conn.SyscallConn()
if err != nil {
return err
}

return rawConn.Control(func(fd uintptr) {
if err := syscall.SetNonblock(platformSpecificFd(fd), true); err != nil {
log.Errorf("failed to set non-blocking: %v", err)
}
})
}
7 changes: 0 additions & 7 deletions socket_unix.go

This file was deleted.

11 changes: 0 additions & 11 deletions socket_windows.go

This file was deleted.

0 comments on commit 3c0bc56

Please sign in to comment.