Skip to content

Commit

Permalink
fix hb
Browse files Browse the repository at this point in the history
  • Loading branch information
snail007 committed Feb 6, 2025
1 parent 000d0ea commit 36835f9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions util/bytes/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func GetPool(bufSize int) *Pool {
}

func GetPoolCap(bufSize, capSize int) *Pool {
poolLock.Lock()
defer poolLock.Unlock()
poolCapLock.Lock()
defer poolCapLock.Unlock()
k := fmt.Sprintf("%d-%d", bufSize, capSize)
if v, ok := poolCapMap[k]; ok {
return v
Expand Down
2 changes: 1 addition & 1 deletion util/func/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func CheckError3(v1 interface{}, v2 interface{}, err error) (*gvalue.AnyValue, *
}

func Wait(f func()) <-chan error {
ch := make(chan error, 1)
ch := make(chan error)
go func() {
ch <- SafetyCall(f)
}()
Expand Down
10 changes: 4 additions & 6 deletions util/net/heartbeat_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ func (h *heartbeatCodecMsg) Bytes() []byte {
h.msgBuf = msgBufPool.Get().([]byte)
buf = bytes.NewBuffer(h.msgBuf)
}
//buf := bytes.NewBuffer(make([]byte, 0, 32*1024))
//buf := &bytes.Buffer{}
binary.Write(buf, binary.LittleEndian, h.flag)
binary.Write(buf, binary.LittleEndian, uint32(len(h.data)))
if h.len > 0 {
Expand Down Expand Up @@ -161,7 +159,7 @@ func (s *HeartbeatCodec) tempDelay(tempDelay time.Duration) time.Duration {
return tempDelay
}
func (s *HeartbeatCodec) heartbeat() {
done := make(chan error, 1)
done := make(chan error)
tempDelay := time.Duration(0)
p := gpool.New(1)
defer p.Stop()
Expand Down Expand Up @@ -197,7 +195,7 @@ retry:
func (s *HeartbeatCodec) backgroundRead() {
tempDelay := time.Duration(0)
msg := newHeartbeatCodecMsg()
out := make(chan error, 1)
out := make(chan error)
p := gpool.New(1)
defer p.Stop()
retry:
Expand Down Expand Up @@ -237,7 +235,7 @@ func (s *HeartbeatCodec) SetConn(c net.Conn) Codec {
}

func (s *HeartbeatCodec) Read(b []byte) (n int, err error) {
done := make(chan bool, 1)
done := make(chan bool)
s.readPool.Submit(func() {
defer close(done)
n, err = s.bufReader.Read(b)
Expand All @@ -254,7 +252,7 @@ func (s *HeartbeatCodec) Write(b []byte) (n int, err error) {
defer s.Unlock()
msg := newHeartbeatCodecMsg()
msg.SetData(b)
done := make(chan bool, 1)
done := make(chan bool)
p := s.writePool
if len(b) == 0 {
p = s.writeHbPool
Expand Down

0 comments on commit 36835f9

Please sign in to comment.