File tree 1 file changed +9
-0
lines changed
1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -362,6 +362,8 @@ func (s *Session) send() {
362
362
}
363
363
}
364
364
365
+ // keep a pool of buffered writers so we don't have to keep them around in
366
+ // memory when not using them.
365
367
var writeBufferPool = sync.Pool {
366
368
New : func () interface {} {
367
369
return bufio .NewWriter (nil )
@@ -385,6 +387,9 @@ func returnBuffer(wb *bufio.Writer) {
385
387
func (s * Session ) sendLoop () error {
386
388
defer close (s .sendDoneCh )
387
389
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).
388
393
var lastWriteDeadline time.Time
389
394
extendWriteDeadline := func () error {
390
395
now := time .Now ()
@@ -413,6 +418,10 @@ func (s *Session) sendLoop() error {
413
418
select {
414
419
case buf = <- s .sendCh :
415
420
default :
421
+
422
+ // nothing to send, flush the writer, return it, and
423
+ // wait for something to send.
424
+
416
425
if err := writer .Flush (); err != nil {
417
426
return err
418
427
}
You can’t perform that action at this time.
0 commit comments