aboutsummaryrefslogtreecommitdiff
path: root/xP
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-09-14 07:10:49 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-09-14 07:11:05 +0200
commit92f2f6895b41ecb60e3aaf59e3ea5bc20d9cd314 (patch)
tree3889ad63336c9e5a81e281ef0a43a251acd63642 /xP
parentc1d2e38840c0596efd10e97ff5a9edaa20d5457e (diff)
downloadxK-92f2f6895b41ecb60e3aaf59e3ea5bc20d9cd314.tar.gz
xK-92f2f6895b41ecb60e3aaf59e3ea5bc20d9cd314.tar.xz
xK-92f2f6895b41ecb60e3aaf59e3ea5bc20d9cd314.zip
xP: use buffered reads
Diffstat (limited to 'xP')
-rw-r--r--xP/xP.go10
1 files changed, 6 insertions, 4 deletions
diff --git a/xP/xP.go b/xP/xP.go
index 2d6e096..7e0285c 100644
--- a/xP/xP.go
+++ b/xP/xP.go
@@ -4,6 +4,7 @@
package main
import (
+ "bufio"
"context"
"encoding/binary"
"encoding/json"
@@ -27,14 +28,14 @@ var (
// -----------------------------------------------------------------------------
-func relayReadJSON(conn net.Conn) []byte {
+func relayReadJSON(r io.Reader) []byte {
var length uint32
- if err := binary.Read(conn, binary.BigEndian, &length); err != nil {
+ if err := binary.Read(r, binary.BigEndian, &length); err != nil {
log.Println("Event receive failed: " + err.Error())
return nil
}
b := make([]byte, length)
- if _, err := io.ReadFull(conn, b); err != nil {
+ if _, err := io.ReadFull(r, b); err != nil {
log.Println("Event receive failed: " + err.Error())
return nil
}
@@ -60,10 +61,11 @@ func relayReadJSON(conn net.Conn) []byte {
func relayMakeReceiver(ctx context.Context, conn net.Conn) <-chan []byte {
p := make(chan []byte, 1)
+ r := bufio.NewReader(conn)
go func() {
defer close(p)
for {
- j := relayReadJSON(conn)
+ j := relayReadJSON(r)
if j == nil {
return
}