volume_server_udp_handlers.go 878 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package weed_server
  2. import (
  3. "bufio"
  4. "github.com/chrislusf/seaweedfs/weed/glog"
  5. "io"
  6. "net"
  7. )
  8. func (vs *VolumeServer) HandleUdpConnection(c net.Conn) {
  9. defer c.Close()
  10. bufReader := bufio.NewReaderSize(c, 1024*1024)
  11. bufWriter := bufio.NewWriterSize(c, 1024*1024)
  12. for {
  13. cmd, err := bufReader.ReadString('\n')
  14. if err != nil {
  15. if err != io.EOF {
  16. // glog.Errorf("read command from: %v", err)
  17. }
  18. return
  19. }
  20. println("received", cmd)
  21. cmd = cmd[:len(cmd)-1]
  22. switch cmd[0] {
  23. case '+':
  24. fileId := cmd[1:]
  25. err = vs.handleTcpPut(fileId, bufReader)
  26. if err != nil {
  27. glog.Errorf("put %s: %v", fileId, err)
  28. }
  29. case '-':
  30. fileId := cmd[1:]
  31. err = vs.handleTcpDelete(fileId)
  32. if err != nil {
  33. glog.Errorf("del %s: %v", fileId, err)
  34. }
  35. case '?':
  36. fileId := cmd[1:]
  37. err = vs.handleTcpGet(fileId, bufWriter)
  38. case '!':
  39. }
  40. }
  41. }