@ -48,10 +48,18 @@ import (
//
//
// A received StatusNormalClosure or StatusGoingAway close frame will be translated to
// A received StatusNormalClosure or StatusGoingAway close frame will be translated to
// io.EOF when reading.
// io.EOF when reading.
func NetConn ( ctx context . Context , c * websocket . Conn , msgType websocket . MessageType ) net . Conn {
//
// The given remoteAddr will be the value of the returned conn's
// RemoteAddr().String(). For best compatibility with consumers of
// conns, the string should be an ip:port if available, but in the
// absence of that it can be any string that describes the remote
// endpoint, or the empty string to makes RemoteAddr() return a place
// holder value.
func NetConn ( ctx context . Context , c * websocket . Conn , msgType websocket . MessageType , remoteAddr string ) net . Conn {
nc := & netConn {
nc := & netConn {
c : c ,
c : c ,
msgType : msgType ,
msgType : msgType ,
remoteAddr : remoteAddr ,
}
}
var writeCancel context . CancelFunc
var writeCancel context . CancelFunc
@ -84,6 +92,7 @@ func NetConn(ctx context.Context, c *websocket.Conn, msgType websocket.MessageTy
type netConn struct {
type netConn struct {
c * websocket . Conn
c * websocket . Conn
msgType websocket . MessageType
msgType websocket . MessageType
remoteAddr string
writeTimer * time . Timer
writeTimer * time . Timer
writeContext context . Context
writeContext context . Context
@ -167,6 +176,7 @@ func (c *netConn) Read(p []byte) (int, error) {
}
}
type websocketAddr struct {
type websocketAddr struct {
addr string
}
}
func ( a websocketAddr ) Network ( ) string {
func ( a websocketAddr ) Network ( ) string {
@ -174,15 +184,18 @@ func (a websocketAddr) Network() string {
}
}
func ( a websocketAddr ) String ( ) string {
func ( a websocketAddr ) String ( ) string {
if a . addr != "" {
return a . addr
}
return "websocket/unknown-addr"
return "websocket/unknown-addr"
}
}
func ( c * netConn ) RemoteAddr ( ) net . Addr {
func ( c * netConn ) RemoteAddr ( ) net . Addr {
return websocketAddr { }
return websocketAddr { c . remoteAddr }
}
}
func ( c * netConn ) LocalAddr ( ) net . Addr {
func ( c * netConn ) LocalAddr ( ) net . Addr {
return websocketAddr { }
return websocketAddr { "" }
}
}
func ( c * netConn ) SetDeadline ( t time . Time ) error {
func ( c * netConn ) SetDeadline ( t time . Time ) error {