forked from tetratelabs/wazero
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: wasi fd subject to garbage collection on unix
commit 81e41c5 Author: Edoardo Vacchi <[email protected]> Date: Thu Dec 28 11:07:28 2023 +0100 wasi: sockets, share most logic across Windows and Unix Signed-off-by: Edoardo Vacchi <[email protected]> commit 4f9f569 Author: Edoardo Vacchi <[email protected]> Date: Thu Dec 28 10:10:06 2023 +0100 wasi: sockets, use the same strategy for impl as Windows Signed-off-by: Edoardo Vacchi <[email protected]>
- Loading branch information
Showing
6 changed files
with
287 additions
and
366 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,29 @@ | ||
//go:build linux || darwin || windows | ||
|
||
package sysfs | ||
|
||
import ( | ||
"syscall" | ||
|
||
experimentalsys "github.com/tetratelabs/wazero/experimental/sys" | ||
) | ||
|
||
// syscallConnControl extracts a syscall.RawConn from the given syscall.Conn and applies | ||
// the given fn to a file descriptor, returning an integer or a nonzero syscall.Errno on failure. | ||
// | ||
// syscallConnControl streamlines the pattern of extracting the syscall.Rawconn, | ||
// invoking its syscall.RawConn.Control method, then handling properly the errors that may occur | ||
// within fn or returned by syscall.RawConn.Control itself. | ||
func syscallConnControl(conn syscall.Conn, fn func(fd uintptr) (int, experimentalsys.Errno)) (n int, errno experimentalsys.Errno) { | ||
syscallConn, err := conn.SyscallConn() | ||
if err != nil { | ||
return 0, experimentalsys.UnwrapOSError(err) | ||
} | ||
// Prioritize the inner errno over Control | ||
if controlErr := syscallConn.Control(func(fd uintptr) { | ||
n, errno = fn(fd) | ||
}); errno == 0 { | ||
errno = experimentalsys.UnwrapOSError(controlErr) | ||
} | ||
return | ||
} |
Oops, something went wrong.