forked from mirror/redcon
init wr zero
This commit is contained in:
parent
639a7aff4b
commit
9b05e8accd
26
redcon.go
26
redcon.go
|
@ -50,8 +50,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultBufLen = 2 * 1024
|
defaultBufLen = 4 * 1024
|
||||||
defaultPoolSize = 3
|
defaultPoolSize = 64
|
||||||
)
|
)
|
||||||
|
|
||||||
type errProtocol struct {
|
type errProtocol struct {
|
||||||
|
@ -75,6 +75,7 @@ type Server struct {
|
||||||
conns map[*conn]bool
|
conns map[*conn]bool
|
||||||
rdpool [][]byte
|
rdpool [][]byte
|
||||||
wrpool [][]byte
|
wrpool [][]byte
|
||||||
|
initbuf []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer returns a new server
|
// NewServer returns a new server
|
||||||
|
@ -88,6 +89,7 @@ func NewServer(
|
||||||
accept: accept,
|
accept: accept,
|
||||||
closed: closed,
|
closed: closed,
|
||||||
conns: make(map[*conn]bool),
|
conns: make(map[*conn]bool),
|
||||||
|
initbuf: make([]byte, defaultPoolSize*defaultBufLen),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,13 +99,9 @@ func NewServerBytes(
|
||||||
addr string, handler func(conn Conn, cmds [][][]byte),
|
addr string, handler func(conn Conn, cmds [][][]byte),
|
||||||
accept func(conn Conn) bool, closed func(conn Conn, err error),
|
accept func(conn Conn) bool, closed func(conn Conn, err error),
|
||||||
) *Server {
|
) *Server {
|
||||||
return &Server{
|
s := NewServer(addr, nil, accept, closed)
|
||||||
addr: addr,
|
s.bhandler = handler
|
||||||
bhandler: handler,
|
return s
|
||||||
accept: accept,
|
|
||||||
closed: closed,
|
|
||||||
conns: make(map[*conn]bool),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close stops listening on the TCP address.
|
// Close stops listening on the TCP address.
|
||||||
|
@ -182,6 +180,7 @@ func (s *Server) ListenServeAndSignal(signal chan error) error {
|
||||||
if len(s.wrpool) > 0 {
|
if len(s.wrpool) > 0 {
|
||||||
c.wr.b = s.wrpool[len(s.wrpool)-1]
|
c.wr.b = s.wrpool[len(s.wrpool)-1]
|
||||||
s.wrpool = s.wrpool[:len(s.wrpool)-1]
|
s.wrpool = s.wrpool[:len(s.wrpool)-1]
|
||||||
|
c.wr.b = c.wr.b[:0]
|
||||||
}
|
}
|
||||||
s.conns[c] = true
|
s.conns[c] = true
|
||||||
s.mu.Unlock()
|
s.mu.Unlock()
|
||||||
|
@ -238,10 +237,10 @@ func handle(
|
||||||
}
|
}
|
||||||
closed(c, err)
|
closed(c, err)
|
||||||
}
|
}
|
||||||
if len(s.rdpool) < defaultPoolSize {
|
if len(s.rdpool) < defaultPoolSize && len(c.rd.buf) < defaultBufLen {
|
||||||
s.rdpool = append(s.rdpool, c.rd.buf)
|
s.rdpool = append(s.rdpool, c.rd.buf)
|
||||||
}
|
}
|
||||||
if len(s.wrpool) < defaultPoolSize {
|
if len(s.wrpool) < defaultPoolSize && len(c.wr.b) < defaultBufLen {
|
||||||
s.wrpool = append(s.wrpool, c.wr.b)
|
s.wrpool = append(s.wrpool, c.wr.b)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -358,11 +357,6 @@ func newReader(r io.Reader) *reader {
|
||||||
buflen: defaultBufLen,
|
buflen: defaultBufLen,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (rd *reader) reassign(r io.Reader) {
|
|
||||||
rd.r = r
|
|
||||||
rd.start = 0
|
|
||||||
rd.end = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReadCommands reads one or more commands from the reader.
|
// ReadCommands reads one or more commands from the reader.
|
||||||
func (r *reader) ReadCommands() ([][][]byte, error) {
|
func (r *reader) ReadCommands() ([][][]byte, error) {
|
||||||
|
|
Loading…
Reference in New Issue