dispatchrun / wasi-go

A Go implementation of the WebAssembly System Interface (WASI)
Apache License 2.0
124 stars 7 forks source link

Add SocketsExtension method by default in the System interface #47

Closed achille-roussel closed 1 year ago

achille-roussel commented 1 year ago

The separation of SocketsExtension from System causes a lot of checks from compile time to run time. Creating wrappers of the System interface can easily miss that they have to implement SocketsExtension if the underlying type does, resulting in unexpectedly disabling socket capabilities.

Since the implementation of the System and SocketsExtension interface is decoupled from the ABI, I would like to suggest that we merge the methods into System and remove the SocketsExtension interface.

For situations where a backend does not provide socket capabilities, I would suggest that we add a type which has the socket extension methods returning ENOSYS, that types can embed in order to easily declare that they don't support sockets. For example:

type MySystemWithoutSockets struct {
    wasi.SocketsNotSupported
    ...
}
package wasi

type SocketsNotSupported struct{}

func (SocketsNotSupported) SockOpen(ctx context.Context, family ProtocolFamily, socketType SocketType, protocol Protocol, rightsBase, rightsInheriting Rights) (FD, Errno) {
    return -1, ENOSYS
}

...

This is somewhat the inverse of the approach we have taken; instead of having extensions, implementations of System can declare the parts of the total interface that they don't support.

Let me know what you think!

chriso commented 1 year ago

Makes sense. It's been error prone having to check whether System implementations also implement SocketsExtension, and we don't have any use cases for System implementations that do not also implement SocketsExtension