2021-03-13 18:16:32 +00:00
|
|
|
package weed_server
|
|
|
|
|
|
|
|
import (
|
2021-03-13 22:48:28 +00:00
|
|
|
"bufio"
|
2021-03-13 18:59:29 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
2021-03-13 22:48:28 +00:00
|
|
|
"io"
|
|
|
|
"net"
|
2021-03-13 18:16:32 +00:00
|
|
|
)
|
|
|
|
|
2021-03-13 22:48:28 +00:00
|
|
|
func (vs *VolumeServer) HandleUdpConnection(c net.Conn) {
|
|
|
|
defer c.Close()
|
2021-03-13 18:59:29 +00:00
|
|
|
|
2021-03-13 22:48:28 +00:00
|
|
|
bufReader := bufio.NewReaderSize(c, 1024*1024)
|
|
|
|
bufWriter := bufio.NewWriterSize(c, 1024*1024)
|
2021-03-13 18:59:29 +00:00
|
|
|
|
2021-03-13 22:48:28 +00:00
|
|
|
for {
|
|
|
|
cmd, err := bufReader.ReadString('\n')
|
2021-03-13 18:59:29 +00:00
|
|
|
if err != nil {
|
2021-03-13 22:48:28 +00:00
|
|
|
if err != io.EOF {
|
2021-03-19 05:02:40 +00:00
|
|
|
// glog.Errorf("read command from: %v", err)
|
2021-03-13 22:48:28 +00:00
|
|
|
}
|
2021-03-13 18:59:29 +00:00
|
|
|
return
|
|
|
|
}
|
2021-03-14 03:03:46 +00:00
|
|
|
println("received", cmd)
|
2021-03-13 22:48:28 +00:00
|
|
|
cmd = cmd[:len(cmd)-1]
|
|
|
|
switch cmd[0] {
|
|
|
|
case '+':
|
|
|
|
fileId := cmd[1:]
|
|
|
|
err = vs.handleTcpPut(fileId, bufReader)
|
|
|
|
if err != nil {
|
|
|
|
glog.Errorf("put %s: %v", fileId, err)
|
|
|
|
}
|
|
|
|
case '-':
|
|
|
|
fileId := cmd[1:]
|
|
|
|
err = vs.handleTcpDelete(fileId)
|
|
|
|
if err != nil {
|
|
|
|
glog.Errorf("del %s: %v", fileId, err)
|
|
|
|
}
|
|
|
|
case '?':
|
|
|
|
fileId := cmd[1:]
|
|
|
|
err = vs.handleTcpGet(fileId, bufWriter)
|
|
|
|
case '!':
|
|
|
|
}
|
2021-03-13 18:16:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|