From ccad3db0071a48330ba01807bca7a34bbdf3911b Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Tue, 18 Mar 2014 15:26:10 +0100 Subject: [PATCH] Added helper function UnderlyingConn to retrieve net.Conn from Conn objects. --- conn.go | 6 ++++++ conn_test.go | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/conn.go b/conn.go index 050d8bc..2580f9e 100644 --- a/conn.go +++ b/conn.go @@ -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)) diff --git a/conn_test.go b/conn_test.go index bd588e3..2e7477e 100644 --- a/conn_test.go +++ b/conn_test.go @@ -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.") + } +}