Browse Source

simplify

test_udp
Chris Lu 4 years ago
parent
commit
5495497876
  1. 1
      weed/server/volume_server_udp_handlers.go
  2. 39
      weed/wdclient/volume_udp_client.go

1
weed/server/volume_server_udp_handlers.go

@ -23,6 +23,7 @@ func (vs *VolumeServer) HandleUdpConnection(c net.Conn) {
} }
return return
} }
println("received", cmd)
cmd = cmd[:len(cmd)-1] cmd = cmd[:len(cmd)-1]
switch cmd[0] { switch cmd[0] {
case '+': case '+':

39
weed/wdclient/volume_udp_client.go

@ -5,15 +5,12 @@ import (
"github.com/chrislusf/seaweedfs/weed/pb" "github.com/chrislusf/seaweedfs/weed/pb"
"github.com/chrislusf/seaweedfs/weed/udptransfer" "github.com/chrislusf/seaweedfs/weed/udptransfer"
"github.com/chrislusf/seaweedfs/weed/util" "github.com/chrislusf/seaweedfs/weed/util"
"github.com/chrislusf/seaweedfs/weed/wdclient/net2"
"io" "io"
"net" "net"
"time"
) )
// VolumeUdpClient put/get/delete file chunks directly on volume servers without replication // VolumeUdpClient put/get/delete file chunks directly on volume servers without replication
type VolumeUdpClient struct { type VolumeUdpClient struct {
cp net2.ConnectionPool
} }
type VolumeUdpConn struct { type VolumeUdpConn struct {
@ -23,41 +20,7 @@ type VolumeUdpConn struct {
} }
func NewVolumeUdpClient() *VolumeUdpClient { func NewVolumeUdpClient() *VolumeUdpClient {
MaxIdleTime := 10 * time.Second
return &VolumeUdpClient{ return &VolumeUdpClient{
cp: net2.NewMultiConnectionPool(net2.ConnectionOptions{
MaxActiveConnections: 16,
MaxIdleConnections: 1,
MaxIdleTime: &MaxIdleTime,
DialMaxConcurrency: 0,
Dial: func(network string, address string) (net.Conn, error) {
listener, err := udptransfer.NewEndpoint(&udptransfer.Params{
LocalAddr: "",
Bandwidth: 100,
FastRetransmit: true,
FlatTraffic: true,
IsServ: false,
})
if err != nil {
return nil, err
}
conn, err := listener.Dial(address)
if err != nil {
return nil, err
}
return &VolumeUdpConn{
conn,
bufio.NewWriter(conn),
bufio.NewReader(conn),
}, err
},
NowFunc: nil,
ReadTimeout: 0,
WriteTimeout: 0,
}),
} }
} }
func (c *VolumeUdpClient) PutFileChunk(volumeServerAddress string, fileId string, fileSize uint32, fileReader io.Reader) (err error) { func (c *VolumeUdpClient) PutFileChunk(volumeServerAddress string, fileId string, fileSize uint32, fileReader io.Reader) (err error) {
@ -77,6 +40,7 @@ func (c *VolumeUdpClient) PutFileChunk(volumeServerAddress string, fileId string
if err != nil { if err != nil {
return err return err
} }
defer listener.Close()
conn, err := listener.Dial(udpAddress) conn, err := listener.Dial(udpAddress)
if err != nil { if err != nil {
@ -100,7 +64,6 @@ func (c *VolumeUdpClient) PutFileChunk(volumeServerAddress string, fileId string
if err != nil { if err != nil {
return return
} }
bufWriter.Write([]byte("!\n"))
bufWriter.Flush() bufWriter.Flush()
return nil return nil

Loading…
Cancel
Save