Skip to content

Commit bc2fd9a

Browse files
committed
Add clone methods
1 parent cc7284a commit bc2fd9a

File tree

7 files changed

+271
-186
lines changed

7 files changed

+271
-186
lines changed

buffers.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,35 @@ import "sync/atomic"
2929
// checkBuf checks current buffer for overflow, and flushes buffer up to lastLen bytes on overflow
3030
//
3131
// overflow part is preserved in flushBuf
32-
func (c *Client) checkBuf(lastLen int) {
33-
if len(c.buf) > c.options.MaxPacketSize {
34-
c.flushBuf(lastLen)
32+
func (t *transport) checkBuf(lastLen int) {
33+
if len(t.buf) > t.maxPacketSize {
34+
t.flushBuf(lastLen)
3535
}
3636
}
3737

3838
// flushBuf sends buffer to the queue and initializes new buffer
39-
func (c *Client) flushBuf(length int) {
40-
sendBuf := c.buf[0:length]
41-
tail := c.buf[length:len(c.buf)]
39+
func (t *transport) flushBuf(length int) {
40+
sendBuf := t.buf[0:length]
41+
tail := t.buf[length:len(t.buf)]
4242

4343
// get new buffer
4444
select {
45-
case c.buf = <-c.bufPool:
46-
c.buf = c.buf[0:0]
45+
case t.buf = <-t.bufPool:
46+
t.buf = t.buf[0:0]
4747
default:
48-
c.buf = make([]byte, 0, c.bufSize)
48+
t.buf = make([]byte, 0, t.bufSize)
4949
}
5050

5151
// copy tail to the new buffer
52-
c.buf = append(c.buf, tail...)
52+
t.buf = append(t.buf, tail...)
5353

5454
// flush current buffer
5555
select {
56-
case c.sendQueue <- sendBuf:
56+
case t.sendQueue <- sendBuf:
5757
default:
5858
// flush failed, we lost some data
59-
atomic.AddInt64(&c.lostPacketsPeriod, 1)
60-
atomic.AddInt64(&c.lostPacketsOverall, 1)
59+
atomic.AddInt64(&t.lostPacketsPeriod, 1)
60+
atomic.AddInt64(&t.lostPacketsOverall, 1)
6161
}
6262

6363
}

0 commit comments

Comments
 (0)