keep connections open

This commit is contained in:
Your Name 2021-08-16 19:55:59 -04:00
parent 0e745fe5a1
commit 69f2573e26
1 changed files with 46 additions and 53 deletions

19
main.go
View File

@ -11,9 +11,9 @@ import (
_ "github.com/go-sql-driver/mysql"
"log"
"net"
"net/textproto"
"os"
"sort"
"net/textproto"
"sync"
"time"
)
@ -196,13 +196,13 @@ type cachecommand struct {
func handleConnection(conn net.Conn, UC MetadataCache, PC MetadataCache) {
log.Println("handleConnection started")
var buf string
var m *MetadataCache
reader := bufio.NewReader(conn)
tp := textproto.NewReader(reader)
for {
buf, err := tp.ReadLine()
if err != nil {
log.Printf("tp.ReadLine returned %s\n", err.Error())
conn.Close()
return
}
var c cachecommand
@ -210,7 +210,6 @@ func handleConnection(conn net.Conn, UC MetadataCache, PC MetadataCache) {
if err != nil {
log.Printf("json.Unmarshal: %s returned %s", buf, err.Error())
}
log.Printf("JSON got: %#v", c)
var values []string
if c.ObjectType == "u" {
m = &UC
@ -221,22 +220,16 @@ func handleConnection(conn net.Conn, UC MetadataCache, PC MetadataCache) {
values, err = m.Get(c.ObjectId, c.Key)
if err != nil {
conn.Write([]byte("404"))
conn.Close()
return
}
} else {
p, err := phpserialize.Marshal(values, nil)
if err != nil {
log.Fatalf("phpserialize.Marshal: %s", err.Error())
}
conn.Write(p)
conn.Close()
return
}
if c.Command=="d" {
} else if c.Command == "d" {
m.Delete(c.ObjectId)
conn.Write([]byte("200"))
conn.Close()
return
}
}
}