From 045679dd42a76b035032fd903cb99956796f1ac8 Mon Sep 17 00:00:00 2001 From: Alex Bramley Date: Sun, 21 Aug 2011 13:23:42 +0100 Subject: [PATCH] Split Connect() into two pieces for testing purposes. --- client/connection.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/client/connection.go b/client/connection.go index 90b783f..a854389 100644 --- a/client/connection.go +++ b/client/connection.go @@ -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...))