Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "re-enable write coalescing" #24

Merged
merged 1 commit into from
Apr 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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