keep connections open
This commit is contained in:
parent
0e745fe5a1
commit
69f2573e26
19
main.go
19
main.go
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue