Merge pull request #21 from longsleep/underlyingConn

Added helper function UnderlyingConn to retrieve net.Conn from Conn objects.
This commit is contained in:
Gary Burd 2014-03-18 09:27:49 -07:00
commit 4ec58d24a4
2 changed files with 16 additions and 0 deletions

View File

@ -765,6 +765,12 @@ func (c *Conn) SetPongHandler(h func(string) error) {
c.handlePong = h
}
// UnderlyingConn returns the internal net.Conn. This can be used to further
// modifications to connection specific flags.
func (c *Conn) UnderlyingConn() net.Conn {
return c.conn
}
// FormatCloseMessage formats closeCode and text as a WebSocket close message.
func FormatCloseMessage(closeCode int, text string) []byte {
buf := make([]byte, 2+len(text))

View File

@ -140,3 +140,13 @@ func TestReadLimit(t *testing.T) {
t.Fatalf("io.Copy() returned %v", err)
}
}
func TestUnderlyingConn(t *testing.T) {
var b1, b2 bytes.Buffer
fc := fakeNetConn{Reader: &b1, Writer: &b2}
c := newConn(fc, true, 1024, 1024)
ul := c.UnderlyingConn()
if ul != fc {
t.Fatalf("Underlying conn is not what it should be.")
}
}