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