Skip to content

Commit

Permalink
export flush timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
256dpi committed Aug 7, 2018
1 parent 3d4d8ae commit de856f0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 4 additions & 1 deletion transport/base_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"github.com/256dpi/gomqtt/packet"
)

// FlushTimeout is the time after any async writes are flushed asynchronously.
const FlushTimeout = time.Millisecond

// A Carrier is a generalized stream that can be used with BaseConn.
type Carrier interface {
io.ReadWriteCloser
Expand Down Expand Up @@ -88,7 +91,7 @@ func (c *BaseConn) Send(pkt packet.Generic, async bool) error {

// setup the timer if missing
if c.flushTimer == nil {
c.flushTimer = time.AfterFunc(flushTimeout, c.asyncFlush)
c.flushTimer = time.AfterFunc(FlushTimeout, c.asyncFlush)
}

return nil
Expand Down
2 changes: 0 additions & 2 deletions transport/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"github.com/256dpi/gomqtt/packet"
)

var flushTimeout = time.Millisecond

// A Conn is a connection between a client and a broker. It abstracts an
// existing underlying stream connection.
type Conn interface {
Expand Down
2 changes: 1 addition & 1 deletion transport/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func abstractConnAsyncSendAfterCloseTest(t *testing.T, protocol string) {
err = conn2.Send(packet.NewConnect(), true)
assert.NoError(t, err)

<-time.After(2 * flushTimeout)
<-time.After(2 * FlushTimeout)

err = conn2.Send(packet.NewConnect(), true)
assert.Error(t, err)
Expand Down

0 comments on commit de856f0

Please sign in to comment.