Explorar o código

Merge pull request #21 from longsleep/underlyingConn

Added helper function UnderlyingConn to retrieve net.Conn from Conn objects.
Gary Burd %!s(int64=11) %!d(string=hai) anos
pai
achega
4ec58d24a4
Modificáronse 2 ficheiros con 16 adicións e 0 borrados
  1. 6 0
      conn.go
  2. 10 0
      conn_test.go

+ 6 - 0
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))

+ 10 - 0
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.")
+	}
+}