rcelyte / BeatUpRcelyte

A lightweight modded Beat Saber multiplayer server
The Unlicense
17 stars 5 forks source link

Fix Windows support (at least for building in MSYS2) #5

Closed bavis-m closed 2 years ago

bavis-m commented 2 years ago
rcelyte commented 2 years ago

Thanks for the pull request! I've adapted these changes to better fit the style and code structure of the project, as well as taking the opportunity to refactor and deduplicate a bit of net code.

For future reference, there were a few blockers that would have prevented me from merging this as is, regardless of formatting and structure:

bavis-m commented 2 years ago

Thanks for cleaning that up.

Taking a bit of a further look, I think net_close probably requires that close to become closesocket if #ifdef WINDOWS, I missed that one. I'm guessing WSACleanup probably doesn't go there either, it looks like socket operations can happen after net_close (in net_cleanup for sure, net_close is called twice in a row). My personal opinion for my own codebases (take with a huge grain of salt haha) is that, since the socket system is needed (by definition) for the entire lifetime of the server, WSACleanup probably isn't needed at all... we're already trusting Windows will cleanup socket resources (e.g. in a crash).

Thanks for the great project!

rcelyte commented 2 years ago

Citing Microsoft's documentation:

An application must call the WSACleanup function for every successful time the WSAStartup function is called. This means, for example, that if an application calls WSAStartup three times, it must call WSACleanup three times. The first two calls to WSACleanup do nothing except decrement an internal counter; the final WSACleanup call for the task does all necessary resource deallocation for the task.

As for not needing it, BeatUpServer needs to pass validation with Memcheck and AddressSanitizer, so all resources need to be cleaned up.