Garux / netradiant-custom

The open-source, cross-platform level editor for id Tech based games.
https://garux.github.io/NRC/
Other
334 stars 59 forks source link

fix linux build process monitoring #205

Closed Vorschreibung closed 5 months ago

Vorschreibung commented 5 months ago

Currently on Linux when building maps with Build Process Monitoring enabled, there is a high chance that the build won't start, throwing the following failure instead:

Failed to get a listening socket on port 39000.
Try running with Build monitoring disabled if you can't fix this.

This error occurs when Radiant attempts to re-bind the 39000 TCP socket in libs/l_net/l_net_berkley.c.

It does not look to be a timing issue, as Radiant seems to correctly order the steps of attempting to close the 39000 TCP socket connection before recreating it again.


The following commit resolves this issue in the following ways:

Firstly the socket option SO_REUSEADDR is used to allow new sockets to rebind to an address that is already in use.

Secondly sockets are now shutdown more cleanly via shutdown using SHUT_RDWR, which immediately aborts standing/queued communication.

Merely closing a socket on Linux does apparently not "invalidate" the "socket cache", and can therefore disallow rebinding the same address, even despite using SO_REUSEADDR.

As such both changes are required in tandem to resolve the issue.

Vorschreibung commented 5 months ago

Ready for review :blush:

Garux commented 5 months ago

Excellent! We were trying to debug this floating problem with @Aciz without success, happy to have this disturbing stuff fixed.