mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 01:54:02 +03:00
FILE / ScuroNeko/mtg
utils/init_tcp.go
Исходный файл и его история в репозитории.
29 lines
645 B
Go
29 lines
645 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
)
|
|
|
|
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(readBufferSize); err != nil {
|
|
return fmt.Errorf("cannot set read buffer size: %w", err)
|
|
}
|
|
|
|
if err := tcpConn.SetWriteBuffer(writeBufferSize); err != nil {
|
|
return fmt.Errorf("cannot set write buffer size: %w", err)
|
|
}
|
|
|
|
if err := tcpConn.SetKeepAlive(true); err != nil {
|
|
return fmt.Errorf("cannot enable keep-alive: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|