Increase TCP buffer size, fix truncation bug; it should truncate before

trying to read
This commit is contained in:
Kelvin Ly 2023-05-16 10:25:57 -04:00
parent af7627a15a
commit 0934e2df8d
1 changed files with 6 additions and 5 deletions

View File

@ -168,19 +168,20 @@ func InitTcpServer(db *sql.DB, state *ShroomState) {
}()
// deal with the read side of the connection
buf := make([]byte, 128)
buf := make([]byte, 1024)
left := buf
for {
if len(left) == 0 {
log.Println("overflow detected, truncating data")
left = buf
}
num_read, err := conn.Read(left)
//log.Println("received: ", string(left[:num_read]))
left = left[num_read:]
//log.Println("buf ", buf)
//log.Println("left ", left)
if len(left) == 0 {
log.Println("overflow detected, truncating data")
left = buf
}
if err != nil {
log.Println("tcp read error: ", err)