maybe non blocking with a new reader
Some checks failed
Build and Publish / BuildAndDeployAmd64 (push) Failing after 29s
Build and Publish / BuildAndDeploy (push) Successful in 2m20s

This commit is contained in:
matst80
2024-11-12 15:19:28 +01:00
parent d32cb07a0d
commit 28ebe47606
4 changed files with 16 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"bufio"
"encoding/binary"
"io"
"log"
@@ -100,8 +101,9 @@ func (m *TCPServerMux) HandleConnection(connection net.Conn) error {
defer connection.Close()
var packet Packet
reader := bufio.NewReader(connection)
for {
err := ReadPacket(connection, &packet)
err := ReadPacket(reader, &packet)
if err != nil {
if err == io.EOF {
return nil
@@ -113,7 +115,7 @@ func (m *TCPServerMux) HandleConnection(connection net.Conn) error {
log.Printf("Incorrect package version: %v\n", err)
continue
}
data, err := GetPacketData(connection, packet.DataLength)
data, err := GetPacketData(reader, packet.DataLength)
if err != nil {
log.Printf("Error receiving packet data: %v\n", err)
}