소스 검색

Merge pull request #21 from longsleep/underlyingConn

Added helper function UnderlyingConn to retrieve net.Conn from Conn objects.
Gary Burd 11 년 전
부모
커밋
4ec58d24a4
2개의 변경된 파일16개의 추가작업 그리고 0개의 파일을 삭제
  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.")
+	}
+}