mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 17:54:01 +03:00
Add possibility to scale middleproxy buffers
This commit is contained in:
+3
-5
@@ -4,24 +4,22 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/9seconds/mtg/config"
|
||||
)
|
||||
|
||||
const tcpKeepAlivePingPeriod = 2 * time.Second
|
||||
|
||||
func InitTCP(conn net.Conn) error {
|
||||
func InitTCP(conn net.Conn, readBufferSize int, writeBufferSize int) error {
|
||||
tcpConn := conn.(*net.TCPConn)
|
||||
|
||||
if err := tcpConn.SetNoDelay(true); err != nil {
|
||||
return fmt.Errorf("cannot set TCP_NO_DELAY: %w", err)
|
||||
}
|
||||
|
||||
if err := tcpConn.SetReadBuffer(config.C.ReadBuffer); err != nil {
|
||||
if err := tcpConn.SetReadBuffer(readBufferSize); err != nil {
|
||||
return fmt.Errorf("cannot set read buffer size: %w", err)
|
||||
}
|
||||
|
||||
if err := tcpConn.SetWriteBuffer(config.C.WriteBuffer); err != nil {
|
||||
if err := tcpConn.SetWriteBuffer(writeBufferSize); err != nil {
|
||||
return fmt.Errorf("cannot set write buffer size: %w", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user