Skip to content

Commit

Permalink
Expose Conn.Set{Read,Write}Buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-mo committed Apr 4, 2020
1 parent ec28a8e commit c17f61d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ func (c *Conn) SetOption(option netlink.ConnOption, enable bool) error {
return c.conn.SetOption(option, enable)
}

// SetReadBuffer sets the size of the operating system's receive buffer associated with the Conn.
func (c *Conn) SetReadBuffer(bytes int) error {
return c.conn.SetReadBuffer(bytes)
}

// SetWriteBuffer sets the size of the operating system's transmit buffer associated with the Conn.
func (c *Conn) SetWriteBuffer(bytes int) error {
return c.conn.SetWriteBuffer(bytes)
}

// Listen joins the Netfilter connection to a multicast group and starts a given
// amount of Flow decoders from the Conn to the Flow channel. Returns an error channel
// the workers will return any errors on. Any error during Flow decoding is fatal and
Expand Down
13 changes: 13 additions & 0 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

"github.com/mdlayher/netlink"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ti-mo/conntrack"
"github.com/ti-mo/netfilter"
)
Expand All @@ -20,6 +22,17 @@ func TestConnDialError(t *testing.T) {
assert.EqualError(t, err, "setns: bad file descriptor")
}

func TestConnBufferSizes(t *testing.T) {

c, err := conntrack.Dial(nil)
require.NoError(t, err, "dialing conn")

assert.NoError(t, c.SetReadBuffer(256))
assert.NoError(t, c.SetWriteBuffer(256))

require.NoError(t, c.Close(), "closing conn")
}

func ExampleConn_createUpdateFlow() {
// Open a Conntrack connection.
c, err := conntrack.Dial(nil)
Expand Down

0 comments on commit c17f61d

Please sign in to comment.