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

buffer writes #15

Merged
merged 1 commit into from
Oct 18, 2018
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
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