Fix build error on FreeBSD. Closes #1243

This commit is contained in:
Gabe Kangas
2021-08-13 15:26:44 -07:00
parent a0a8257cb7
commit 04bb97bffc
5 changed files with 68 additions and 31 deletions

View File

@@ -1,29 +1,15 @@
package chat
import (
"syscall"
import "syscall"
log "github.com/sirupsen/logrus"
)
// Set the soft file handler limit as 70% of
// the max as the client connection limit.
func handleMaxConnectionCount() uint {
func getMaximumConcurrentConnectionLimit() int64 {
var rLimit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil {
panic(err)
}
originalLimit := rLimit.Cur
// Set the limit to 70% of max so the machine doesn't die even if it's maxed out for some reason.
proposedLimit := int(float32(rLimit.Max) * 0.7)
// Return the limit to 70% of max so the machine doesn't die even if it's maxed out for some reason.
proposedLimit := int64(float32(rLimit.Max) * 0.7)
rLimit.Cur = uint64(proposedLimit)
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil {
panic(err)
}
log.Traceln("Max process connection count increased from", originalLimit, "to", proposedLimit)
return uint(float32(rLimit.Cur))
return proposedLimit
}