Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: Add basic smoke test for net functionality #6838

Merged
merged 4 commits into from
Oct 29, 2020

Conversation

LemonBoy
Copy link
Contributor

Barely enough testing to make sure net doesn't keep on breaking every damn time.
The async tests are broken as exepcted, patches welcome.

Open questions:

  • What the everloving fuck is a socket_t? Are we minting our own faux-libc types? Why not SocketHandle?
  • Why the hell does the IPAddress struct hold a port? It's an ip address!
  • Why is IPAddress a wrapper over sockaddr_in rather than something saner like a fixed-size array of octets? The number of casts and pointer reinterpretations needed to fill/access them is making (me and) the stage1 compiler sick. Zig currently barfs when trying to parse an ip at comptime!
  • Why the IPv6 parser is doing syscalls in the parsing routine?? The ipv6 scope should be kept as a literal and looked up only when needed (since Ip6Address is a sockaddr_in6 you always need to resolve it right away...)

@@ -256,6 +256,41 @@ pub const POLLERR = ws2_32.POLLERR;
pub const POLLHUP = ws2_32.POLLHUP;
pub const POLLNVAL = ws2_32.POLLNVAL;

pub const SOL_SOCKET = 0xffff;

pub const SO_DEBUG = 0x0001;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these come from ws2_32?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I keep losing track of the many places where bits go.

LemonBoy and others added 3 commits October 27, 2020 21:52
std.os.accept already wants to allow null, which matches `man 3p accept`:

>  address     Either a null pointer, or a pointer to a sockaddr structure
>              where the address of the connecting  socket  shall  be  re‐
>              turned.
>
>  address_len Either  a  null pointer, if address is a null pointer, or a
>              pointer to a socklen_t object which on input specifies  the
>              length  of  the  supplied sockaddr structure, and on output
>              specifies the length of the stored address.

Fixes ziglang#6832.
* Use closeSocket on sockets instead of plain old close, the latter
  doesn't work on them.
* Use winsocket2 everywhere, mingw has no BSD sockets.
@LemonBoy
Copy link
Contributor Author

We absolutely need to separate the socket handles from the regular file ones, I've just discovered that you have to call closesocket on the former rather than using close.

x-ref #6600.

@daurnimator
Copy link
Contributor

I've just discovered that you have to call closesocket on the former rather than using close.

Only if you go via win32; not if you use the native api.

@LemonBoy
Copy link
Contributor Author

Only if you go via win32; not if you use the native api.

Isn't winsock the native api?

@daurnimator
Copy link
Contributor

Isn't winsock the native api?

the native api is AFD.

@LemonBoy
Copy link
Contributor Author

the native api is AFD.

Good lord, the undocumented kernel driver that's not supposed to be used from usermode?

@daurnimator
Copy link
Contributor

daurnimator commented Oct 28, 2020

undocumented

not supposed to be used from usermode

According to microsoft the entire NTAPI is "not supposed to be used from usermode" and is mostly undocumented.
Winsocket has gained a lot of cruft over the years; using AFD directly is not only more efficient, but has better APIs.
Note that projects like libuv (and hence the entire node js javascript ecosystem) in several cases use AFD directly: Microsoft won't be breaking it any time soon.

@andrewrk
Copy link
Member

* What the everloving fuck is a `socket_t`? Are we minting our own faux-libc types? Why not `SocketHandle`?

It comes from WASI. I think this a good example of something that would benefit from your points in #6600.

* Why the hell does the `IPAddress` struct hold a port? It's an ip address!

idk, it made sense at the time but I'm not prepared to defend the decision. The std.net code is young, untested, unvetted, and certainly will be reworked, probably more than once.

[other questions]

Zig is a project that has slowly gained quality and robustness by iterating and reworking - not by getting the design right the first time. The short answer to all this stuff is: good points, let's improve things. It's all work-in-progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants