Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
buffer writes
Browse files Browse the repository at this point in the history
Let's not split every wantlist into a length and a wantlist...
  • Loading branch information
Stebalien committed Oct 17, 2018
1 parent e12de92 commit fc1278e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions network/ipfs_impl.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package network

import (
"bufio"
"context"
"fmt"
"io"
Expand Down Expand Up @@ -70,26 +71,32 @@ func msgToStream(ctx context.Context, s inet.Stream, msg bsmsg.BitSwapMessage) e
if dl, ok := ctx.Deadline(); ok {
deadline = dl
}

if err := s.SetWriteDeadline(deadline); err != nil {
log.Warningf("error setting deadline: %s", err)
}

w := bufio.NewWriter(s)

switch s.Protocol() {
case ProtocolBitswap:
if err := msg.ToNetV1(s); err != nil {
if err := msg.ToNetV1(w); err != nil {
log.Debugf("error: %s", err)
return err
}
case ProtocolBitswapOne, ProtocolBitswapNoVers:
if err := msg.ToNetV0(s); err != nil {
if err := msg.ToNetV0(w); err != nil {
log.Debugf("error: %s", err)
return err
}
default:
return fmt.Errorf("unrecognized protocol on remote: %s", s.Protocol())
}

if err := w.Flush(); err != nil {
log.Debugf("error: %s", err)
return err
}

if err := s.SetWriteDeadline(time.Time{}); err != nil {
log.Warningf("error resetting deadline: %s", err)
}
Expand Down

0 comments on commit fc1278e

Please sign in to comment.