seaweedfs/weed/server/volume_server_udp_handlers.go

49 lines
945 B
Go
Raw Normal View History

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
glog.V(0).Infof("Serving writes from %s", c.RemoteAddr().String())
2021-03-13 18:16:32 +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 {
glog.Errorf("read command from %s: %v", c.RemoteAddr().String(), err)
}
2021-03-13 18:59:29 +00:00
return
}
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
}
}