Unverified Commit 088fd5f7 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #103 from bpot/bp-revert-buffered-write

Reduce memory allocation
parents 98550f76 c9aa3744
package network
import (
"bufio"
"context"
"fmt"
"io"
......@@ -74,20 +73,19 @@ 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(w); err != nil {
if err := msg.ToNetV1(s); err != nil {
log.Debugf("error: %s", err)
return err
}
case ProtocolBitswapOne, ProtocolBitswapNoVers:
if err := msg.ToNetV0(w); err != nil {
if err := msg.ToNetV0(s); err != nil {
log.Debugf("error: %s", err)
return err
}
......@@ -95,11 +93,6 @@ func msgToStream(ctx context.Context, s inet.Stream, msg bsmsg.BitSwapMessage) e
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)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment