Skip to content

Commit 118deb1

Browse files
committed
doc: add a few comments
1 parent 355555e commit 118deb1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

session.go

+9
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ func (s *Session) send() {
362362
}
363363
}
364364

365+
// keep a pool of buffered writers so we don't have to keep them around in
366+
// memory when not using them.
365367
var writeBufferPool = sync.Pool{
366368
New: func() interface{} {
367369
return bufio.NewWriter(nil)
@@ -385,6 +387,9 @@ func returnBuffer(wb *bufio.Writer) {
385387
func (s *Session) sendLoop() error {
386388
defer close(s.sendDoneCh)
387389

390+
// Extend the write deadline if we've passed the halfway point. This can
391+
// be expensive so this ensures we only have to do this once every
392+
// ConnectionWriteTimeout/2 (usually 5s).
388393
var lastWriteDeadline time.Time
389394
extendWriteDeadline := func() error {
390395
now := time.Now()
@@ -413,6 +418,10 @@ func (s *Session) sendLoop() error {
413418
select {
414419
case buf = <-s.sendCh:
415420
default:
421+
422+
// nothing to send, flush the writer, return it, and
423+
// wait for something to send.
424+
416425
if err := writer.Flush(); err != nil {
417426
return err
418427
}

0 commit comments

Comments
 (0)