Skip to content

Commit

Permalink
test set buffers and only support tcp for now
Browse files Browse the repository at this point in the history
  • Loading branch information
256dpi committed Aug 7, 2018
1 parent de856f0 commit 1a47b43
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
18 changes: 18 additions & 0 deletions transport/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,21 @@ func abstractConnBigAsyncSendAfterCloseTest(t *testing.T, protocol string) {

safeReceive(done)
}

func abstractConnSetBuffersTest(t *testing.T, protocol string) {
// TODO: Do some real testing.

conn2, done := connectionPair(protocol, func(conn1 Conn) {
conn1.SetBuffers(128, 128)

err := conn1.Close()
assert.NoError(t, err)
})

conn2.SetBuffers(128, 128)

err := conn2.Close()
assert.NoError(t, err)

safeReceive(done)
}
12 changes: 0 additions & 12 deletions transport/net_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@ func (c *NetConn) SetBuffers(read, write int) {
tcpConn.SetReadBuffer(read)
tcpConn.SetWriteBuffer(write)
}

// set ip conn
if tcpConn, ok := c.conn.(*net.IPConn); ok {
tcpConn.SetReadBuffer(read)
tcpConn.SetWriteBuffer(write)
}

// set unix conn
if tcpConn, ok := c.conn.(*net.UnixConn); ok {
tcpConn.SetReadBuffer(read)
tcpConn.SetWriteBuffer(write)
}
}

// UnderlyingConn returns the underlying net.Conn.
Expand Down
4 changes: 4 additions & 0 deletions transport/net_conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func TestNetConnBigAsyncSendAfterClose(t *testing.T) {
abstractConnBigAsyncSendAfterCloseTest(t, "tcp")
}

func TestNetConnSetBuffers(t *testing.T) {
abstractConnSetBuffersTest(t, "tcp")
}

func TestNetConnCloseWhileReadError(t *testing.T) {
conn2, done := connectionPair("tcp", func(conn1 Conn) {
pkt := packet.NewPublish()
Expand Down
12 changes: 0 additions & 12 deletions transport/websocket_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,6 @@ func (c *WebSocketConn) SetBuffers(read, write int) {
tcpConn.SetReadBuffer(read)
tcpConn.SetWriteBuffer(write)
}

// set ip conn
if tcpConn, ok := c.conn.UnderlyingConn().(*net.IPConn); ok {
tcpConn.SetReadBuffer(read)
tcpConn.SetWriteBuffer(write)
}

// set unix conn
if tcpConn, ok := c.conn.UnderlyingConn().(*net.UnixConn); ok {
tcpConn.SetReadBuffer(read)
tcpConn.SetWriteBuffer(write)
}
}

// UnderlyingConn returns the underlying websocket.Conn.
Expand Down
4 changes: 4 additions & 0 deletions transport/websocket_conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func TestWebSocketConnBigAsyncSendAfterClose(t *testing.T) {
abstractConnBigAsyncSendAfterCloseTest(t, "ws")
}

func TestWebSocketConnSetBuffers(t *testing.T) {
abstractConnSetBuffersTest(t, "ws")
}

func TestWebSocketBadFrameError(t *testing.T) {
conn2, done := connectionPair("ws", func(conn1 Conn) {
buf := []byte{0x07, 0x00, 0x00, 0x00, 0x00} // < bad frame
Expand Down

0 comments on commit 1a47b43

Please sign in to comment.