add a new api: NewConnNet

This commit is contained in:
fangyuanziti
2015-02-22 20:22:38 +08:00
committed by Přemysl Janouch
parent ef8155bf17
commit a1d1151017
2 changed files with 31 additions and 0 deletions

View File

@@ -98,6 +98,26 @@ func NewConnDisplay(display string) (*Conn, error) {
return nil, err
}
return postNewConn(conn)
}
// NewConnDisplay is just like NewConn, but allows a specific net.Conn
// to be used.
func NewConnNet(netConn net.Conn) (*Conn, error) {
conn := &Conn{}
// First connect. This reads authority, checks DISPLAY environment
// variable, and loads the initial Setup info.
err := conn.connectNet(netConn)
if err != nil {
return nil, err
}
return postNewConn(conn)
}
func postNewConn(conn *Conn) (*Conn, error) {
conn.Extensions = make(map[string]byte)
conn.cookieChan = make(chan *Cookie, cookieBuffer)