Change pool, change mux connection close ,change copy buffer

This commit is contained in:
ffdfgdfg
2019-08-30 20:05:09 +08:00
parent 41c282b38b
commit bb2cffe10a
11 changed files with 257 additions and 123 deletions

View File

@@ -2,7 +2,6 @@ package proxy
import (
"github.com/cnlh/nps/lib/common"
"github.com/cnlh/nps/lib/pool"
"github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
"net"
"strings"
@@ -36,7 +35,7 @@ func (s *P2PServer) Start() error {
return err
}
for {
buf := pool.BufPoolUdp.Get().([]byte)
buf := common.BufPoolUdp.Get().([]byte)
n, addr, err := s.listener.ReadFromUDP(buf)
if err != nil {
if strings.Contains(err.Error(), "use of closed network connection") {

View File

@@ -5,7 +5,6 @@ import (
"github.com/cnlh/nps/lib/common"
"github.com/cnlh/nps/lib/conn"
"github.com/cnlh/nps/lib/file"
"github.com/cnlh/nps/lib/pool"
"github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
"net"
"strings"
@@ -33,7 +32,7 @@ func (s *UdpModeServer) Start() error {
if err != nil {
return err
}
buf := pool.BufPoolUdp.Get().([]byte)
buf := common.BufPoolUdp.Get().([]byte)
for {
n, addr, err := s.listener.ReadFromUDP(buf)
if err != nil {
@@ -59,8 +58,8 @@ func (s *UdpModeServer) process(addr *net.UDPAddr, data []byte) {
return
} else {
s.task.Flow.Add(int64(len(data)), 0)
buf := pool.BufPoolUdp.Get().([]byte)
defer pool.BufPoolUdp.Put(buf)
buf := common.BufPoolUdp.Get().([]byte)
defer common.BufPoolUdp.Put(buf)
target.Write(data)
s.task.Flow.Add(int64(len(data)), 0)
if n, err := target.Read(buf); err != nil {