mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
simplify
This commit is contained in:
parent
e12600cc8e
commit
5495497876
|
@ -23,6 +23,7 @@ func (vs *VolumeServer) HandleUdpConnection(c net.Conn) {
|
|||
}
|
||||
return
|
||||
}
|
||||
println("received", cmd)
|
||||
cmd = cmd[:len(cmd)-1]
|
||||
switch cmd[0] {
|
||||
case '+':
|
||||
|
|
|
@ -5,15 +5,12 @@ import (
|
|||
"github.com/chrislusf/seaweedfs/weed/pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/udptransfer"
|
||||
"github.com/chrislusf/seaweedfs/weed/util"
|
||||
"github.com/chrislusf/seaweedfs/weed/wdclient/net2"
|
||||
"io"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
// VolumeUdpClient put/get/delete file chunks directly on volume servers without replication
|
||||
type VolumeUdpClient struct {
|
||||
cp net2.ConnectionPool
|
||||
}
|
||||
|
||||
type VolumeUdpConn struct {
|
||||
|
@ -23,41 +20,7 @@ type VolumeUdpConn struct {
|
|||
}
|
||||
|
||||
func NewVolumeUdpClient() *VolumeUdpClient {
|
||||
MaxIdleTime := 10 * time.Second
|
||||
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) {
|
||||
|
@ -77,6 +40,7 @@ func (c *VolumeUdpClient) PutFileChunk(volumeServerAddress string, fileId string
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer listener.Close()
|
||||
|
||||
conn, err := listener.Dial(udpAddress)
|
||||
if err != nil {
|
||||
|
@ -100,7 +64,6 @@ func (c *VolumeUdpClient) PutFileChunk(volumeServerAddress string, fileId string
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
bufWriter.Write([]byte("!\n"))
|
||||
bufWriter.Flush()
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue