Skip to content

Commit

Permalink
Merge pull request #24 from libp2p/fix/re-disable-write-coalescing
Browse files Browse the repository at this point in the history
Revert "re-enable write coalescing"
  • Loading branch information
willscott authored Apr 2, 2020
2 parents 42b17e9 + c436870 commit 9a36404
Showing 1 changed file with 40 additions and 35 deletions.
75 changes: 40 additions & 35 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,20 +422,25 @@ func (s *Session) sendLoop() error {
return nil
}

writer := pool.Writer{W: s.conn}
writer := s.conn

var writeTimeout *time.Timer
var writeTimeoutCh <-chan time.Time
if s.config.WriteCoalesceDelay > 0 {
writeTimeout = time.NewTimer(s.config.WriteCoalesceDelay)
defer writeTimeout.Stop()
// FIXME: https://github.com/libp2p/go-libp2p/issues/644
// Write coalescing is disabled for now.

writeTimeoutCh = writeTimeout.C
} else {
ch := make(chan time.Time)
close(ch)
writeTimeoutCh = ch
}
//writer := pool.Writer{W: s.conn}

//var writeTimeout *time.Timer
//var writeTimeoutCh <-chan time.Time
//if s.config.WriteCoalesceDelay > 0 {
// writeTimeout = time.NewTimer(s.config.WriteCoalesceDelay)
// defer writeTimeout.Stop()

// writeTimeoutCh = writeTimeout.C
//} else {
// ch := make(chan time.Time)
// close(ch)
// writeTimeoutCh = ch
//}

for {
// yield after processing the last message, if we've shutdown.
Expand All @@ -453,29 +458,29 @@ func (s *Session) sendLoop() error {
case buf = <-s.sendCh:
case <-s.shutdownCh:
return nil
default:
select {
case buf = <-s.sendCh:
case <-s.shutdownCh:
return nil
case <-writeTimeoutCh:
if err := writer.Flush(); err != nil {
if os.IsTimeout(err) {
err = ErrConnectionWriteTimeout
}
return err
}

select {
case buf = <-s.sendCh:
case <-s.shutdownCh:
return nil
}

if writeTimeout != nil {
writeTimeout.Reset(s.config.WriteCoalesceDelay)
}
}
//default:
// select {
// case buf = <-s.sendCh:
// case <-s.shutdownCh:
// return nil
// case <-writeTimeoutCh:
// if err := writer.Flush(); err != nil {
// if os.IsTimeout(err) {
// err = ErrConnectionWriteTimeout
// }
// return err
// }

// select {
// case buf = <-s.sendCh:
// case <-s.shutdownCh:
// return nil
// }

// if writeTimeout != nil {
// writeTimeout.Reset(s.config.WriteCoalesceDelay)
// }
// }
}

if err := extendWriteDeadline(); err != nil {
Expand Down

0 comments on commit 9a36404

Please sign in to comment.