Split Connect() into two pieces for testing purposes.

This commit is contained in:
Alex Bramley 2011-08-21 13:23:42 +01:00
parent a95da1cb2c
commit 045679dd42
1 changed files with 12 additions and 9 deletions

View File

@ -143,26 +143,29 @@ func (conn *Conn) Connect(host string, pass ...string) os.Error {
return err
}
}
conn.Host = host
conn.io = bufio.NewReadWriter(
bufio.NewReader(conn.sock),
bufio.NewWriter(conn.sock))
conn.sock.SetTimeout(conn.Timeout * second)
conn.connected = true
go conn.send()
go conn.recv()
conn.postConnect()
if len(pass) > 0 {
conn.Pass(pass[0])
}
conn.Nick(conn.Me.Nick)
conn.User(conn.Me.Ident, conn.Me.Name)
go conn.runLoop()
return nil
}
// Post-connection setup (for ease of testing)
func (conn *Conn) postConnect() {
conn.io = bufio.NewReadWriter(
bufio.NewReader(conn.sock),
bufio.NewWriter(conn.sock))
conn.sock.SetTimeout(conn.Timeout * second)
go conn.send()
go conn.recv()
go conn.runLoop()
}
// dispatch a nicely formatted os.Error to the error channel
func (conn *Conn) error(s string, a ...interface{}) {
conn.Err <- os.NewError(fmt.Sprintf(s, a...))