dotnet / dotnet-wasi-sdk

An SDK for building .NET projects as standalone WASI-compliant modules
MIT License
276 stars 12 forks source link

Explicitly set listener FD to non-blocking mode #9

Open rvolosatovs opened 1 year ago

rvolosatovs commented 1 year ago

Implementation assumes the listener to be in non-blocking mode (see errno !=__WASI_ERRNO_AGAIN check on L64), but it never actually ensures it is.

This commit changes that and ensures that the listener is non-blocking.

Refs https://github.com/bytecodealliance/wasmtime/pull/5633

rvolosatovs commented 1 year ago

For the record, I have not actually tested this, but looks like fcntl is correctly handled by wasi-libc https://github.com/WebAssembly/wasi-libc/blob/659ff414560721b1660a19685110e484a081c3d4/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c#L18-L57 , so I would expect this to behave just like a usual C program would

jarkkojs commented 1 year ago

You could perhaps use https://man7.org/linux/man-pages/man3/strerror.3.html.

rvolosatovs commented 1 year ago

You could perhaps use man7.org/linux/man-pages/man3/strerror.3.html.

True, but I decided not to for consistency with existing error handing approach in this function https://github.com/rvolosatovs/dotnet-wasi-sdk/blob/644e1d07f6e41e3efd48a096a1ede4dc7fab5e55/src/Wasi.AspNetCore.Server.Native/native/tcp_listener_loop.c#L65-L66