Make the loopback buffers configurable

This commit is contained in:
notsure2 2023-01-05 18:49:27 +02:00
parent 786607d31e
commit 4a989ccd14
1 changed files with 23 additions and 15 deletions

View File

@ -26,6 +26,8 @@ type RawConfig struct {
DatabasePath string
KeepAlive int
CncMode bool
LoopbackTcpSendBuffer int
LoopbackTcpReceiveBuffer int
}
// State type stores the global state of the program
@ -175,14 +177,20 @@ func InitState(preParse RawConfig, worldState common.WorldState) (sta *State, er
}
return c.Control(func(fd uintptr) {
err := syscall.SetsockoptInt(platformfd(fd), syscall.SOL_SOCKET, syscall.SO_SNDBUF, 32*1024)
if preParse.LoopbackTcpSendBuffer > 0 {
log.Debugf("Setting loopback connection tcp send buffer: %d", preParse.LoopbackTcpSendBuffer)
err := syscall.SetsockoptInt(platformfd(fd), syscall.SOL_SOCKET, syscall.SO_SNDBUF, preParse.LoopbackTcpSendBuffer)
if err != nil {
log.Println("setsocketopt SO_SNDBUF: ", err)
log.Errorf("setsocketopt SO_SNDBUF: %s\n", err)
}
}
err = syscall.SetsockoptInt(platformfd(fd), syscall.SOL_SOCKET, syscall.SO_RCVBUF, 32*1024)
if preParse.LoopbackTcpReceiveBuffer > 0 {
log.Debugf("Setting loopback connection tcp receive buffer: %d", preParse.LoopbackTcpReceiveBuffer)
err = syscall.SetsockoptInt(platformfd(fd), syscall.SOL_SOCKET, syscall.SO_RCVBUF, preParse.LoopbackTcpReceiveBuffer)
if err != nil {
log.Println("setsocketopt SO_RCVBUF: ", err)
log.Errorf("setsocketopt SO_RCVBUF: %s\n", err)
}
}
})
}