Increase the buffer of another scanner

This commit is contained in:
M. Mert Yildiran 2021-09-17 03:27:54 +03:00
parent 5e6b5ed438
commit 2dd1883c65
No known key found for this signature in database
GPG Key ID: D42ADB236521BF7A

View File

@ -68,6 +68,8 @@ func readConnectionSingle(wg *sync.WaitGroup, conn net.Conn, entry *map[string]i
defer wg.Done() defer wg.Done()
for { for {
scanner := bufio.NewScanner(conn) scanner := bufio.NewScanner(conn)
buf := make([]byte, 0, 64*1024)
scanner.Buffer(buf, 209715200)
for { for {
ok := scanner.Scan() ok := scanner.Scan()
@ -76,6 +78,13 @@ func readConnectionSingle(wg *sync.WaitGroup, conn net.Conn, entry *map[string]i
command := handleCommands(text) command := handleCommands(text)
if !command { if !command {
fmt.Printf("\b\b** %s\n> ", text) fmt.Printf("\b\b** %s\n> ", text)
if text == "" {
err := scanner.Err()
fmt.Printf("err: %v\n", err)
return
}
if err := json.Unmarshal([]byte(text), entry); err != nil { if err := json.Unmarshal([]byte(text), entry); err != nil {
panic(err) panic(err)
} }