Skip to content

Commit

Permalink
Merge pull request ethereum#135 from nonsense/p2p-sim-configurable-so…
Browse files Browse the repository at this point in the history
…cket

p2p/sim: configurable unix socket read/write buffer size
  • Loading branch information
nonsense authored Nov 15, 2017
2 parents 4853238 + 3a74282 commit 64ecbcd
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions p2p/simulations/adapters/inproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ import (
"github.com/ethereum/go-ethereum/rpc"
)

const (
socketReadBuffer = 5000 * 1024
socketWriteBuffer = 5000 * 1024
)

// SimAdapter is a NodeAdapter which creates in-memory simulation nodes and
// connects them using net.Pipe or OS socket connections
type SimAdapter struct {
Expand Down Expand Up @@ -364,9 +369,35 @@ func socketPipe() (net.Conn, net.Conn, error) {
if err != nil {
return nil, nil, err
}

err = setSocketBuffer(pipe1)
if err != nil {
return nil, nil, err
}

err = setSocketBuffer(pipe2)
if err != nil {
return nil, nil, err
}

return pipe1, pipe2, nil
}

func setSocketBuffer(conn net.Conn) error {
switch v := conn.(type) {
case *net.UnixConn:
err := v.SetReadBuffer(socketReadBuffer)
if err != nil {
return err
}
err = v.SetWriteBuffer(socketWriteBuffer)
if err != nil {
return err
}
}
return nil
}

// netPipe wraps net.Pipe in a signature returning an error
func netPipe() (net.Conn, net.Conn, error) {
p1, p2 := net.Pipe()
Expand Down

0 comments on commit 64ecbcd

Please sign in to comment.