WebAssembly / wasi-sockets

WASI API proposal for managing sockets
243 stars 22 forks source link

Should socket.local_address() throw an invalid-state error? #82

Closed manekinekko closed 10 months ago

manekinekko commented 10 months ago

Hi, I am currently implementing wasi-sockets for jco, and I am encountering an unspecificed behavior.

The test_tcp_connect_dual_stack test inside of the test programm preview2_tcp_connect.rs, creates av6_client socket that connects to the v4_listener socket. In the following line, we are accessing v6_client.local_address() that is supposed to throw an invalid-state if the socket is not bound (according to the WIT file), but the test is not asserting for that. Did I understand this correctly? I would like to have more details about this specific case.

@pchickey @badeend

badeend commented 10 months ago

In that example, the line above it calls Connect, which performs an implicit bind. This is [standard POSIX behavior](https://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html#:~:text=If%20the%20socket%20has%20not%20already%20been%20bound%20to%20a%20local%20address%2C%20connect()%20shall%20bind%20it%20to%20an%20address%20which%2C%20unless%20the%20socket%27s%20address%20family%20is%20AF_UNIX%2C%20is%20an%20unused%20local%20address.):

If the socket has not already been bound to a local address, connect() shall bind it to an address which (...) is an unused local address.

I'd say the test case is correct and the WIT file could use a clarification.

manekinekko commented 10 months ago

Gotcha! That's what I assumed as well. Thank you for clarifying that.

manekinekko commented 10 months ago

Closing this issue (for implementation progress see https://github.com/bytecodealliance/jco/issues/154)

badeend commented 10 months ago

BTW, the same applies to accept'ed client sockets

manekinekko commented 10 months ago

Great! Will update the impl. Thanks.