mirror of
https://github.com/ehang-io/nps.git
synced 2025-09-02 11:56:53 +00:00
Code optimization
This commit is contained in:
@@ -2,22 +2,20 @@ package conn
|
||||
|
||||
import (
|
||||
"github.com/cnlh/nps/lib/pool"
|
||||
"github.com/cnlh/nps/lib/rate"
|
||||
"github.com/cnlh/nps/vender/github.com/golang/snappy"
|
||||
"github.com/fatedier/frp/utils/net"
|
||||
"io"
|
||||
)
|
||||
|
||||
type SnappyConn struct {
|
||||
w *snappy.Writer
|
||||
r *snappy.Reader
|
||||
rate *rate.Rate
|
||||
w *snappy.Writer
|
||||
r *snappy.Reader
|
||||
}
|
||||
|
||||
func NewSnappyConn(conn io.ReadWriteCloser, crypt bool, rate *rate.Rate) *SnappyConn {
|
||||
func NewSnappyConn(conn io.ReadWriteCloser) net.Conn {
|
||||
c := new(SnappyConn)
|
||||
c.w = snappy.NewBufferedWriter(conn)
|
||||
c.r = snappy.NewReader(conn)
|
||||
c.rate = rate
|
||||
return c
|
||||
}
|
||||
|
||||
@@ -29,9 +27,6 @@ func (s *SnappyConn) Write(b []byte) (n int, err error) {
|
||||
if err = s.w.Flush(); err != nil {
|
||||
return
|
||||
}
|
||||
if s.rate != nil {
|
||||
s.rate.Get(int64(n))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -43,9 +38,6 @@ func (s *SnappyConn) Read(b []byte) (n int, err error) {
|
||||
return
|
||||
}
|
||||
copy(b, buf[:n])
|
||||
if s.rate != nil {
|
||||
s.rate.Get(int64(n))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user