Make connected externally accessible, per issues/8.

This commit is contained in:
Alex Bramley 2011-08-22 17:09:48 +01:00
parent fb91caeccf
commit f3a2cf6fa6
1 changed files with 6 additions and 6 deletions

View File

@ -41,7 +41,7 @@ type Conn struct {
io *bufio.ReadWriter io *bufio.ReadWriter
in chan *Line in chan *Line
out chan string out chan string
connected bool Connected bool
// Control channels to goroutines // Control channels to goroutines
cSend, cLoop chan bool cSend, cLoop chan bool
@ -118,7 +118,7 @@ func (conn *Conn) initialise() {
// Connect(). The port will default to 6697 if ssl is enabled, and 6667 // Connect(). The port will default to 6697 if ssl is enabled, and 6667
// otherwise. You can also provide an optional connect password. // otherwise. You can also provide an optional connect password.
func (conn *Conn) Connect(host string, pass ...string) os.Error { func (conn *Conn) Connect(host string, pass ...string) os.Error {
if conn.connected { if conn.Connected {
return os.NewError(fmt.Sprintf( return os.NewError(fmt.Sprintf(
"irc.Connect(): already connected to %s, cannot connect to %s", "irc.Connect(): already connected to %s, cannot connect to %s",
conn.Host, host)) conn.Host, host))
@ -144,7 +144,7 @@ func (conn *Conn) Connect(host string, pass ...string) os.Error {
} }
} }
conn.Host = host conn.Host = host
conn.connected = true conn.Connected = true
conn.postConnect() conn.postConnect()
if len(pass) > 0 { if len(pass) > 0 {
@ -264,8 +264,8 @@ func (conn *Conn) rateLimit(chars int64) {
func (conn *Conn) shutdown() { func (conn *Conn) shutdown() {
// Guard against double-call of shutdown() if we get an error in send() // Guard against double-call of shutdown() if we get an error in send()
// as calling sock.Close() will cause recv() to recieve EOF in readstring() // as calling sock.Close() will cause recv() to recieve EOF in readstring()
if conn.connected { if conn.Connected {
conn.connected = false conn.Connected = false
conn.sock.Close() conn.sock.Close()
conn.cSend <- true conn.cSend <- true
conn.cLoop <- true conn.cLoop <- true
@ -281,7 +281,7 @@ func (conn *Conn) shutdown() {
func (conn *Conn) String() string { func (conn *Conn) String() string {
str := "GoIRC Connection\n" str := "GoIRC Connection\n"
str += "----------------\n\n" str += "----------------\n\n"
if conn.connected { if conn.Connected {
str += "Connected to " + conn.Host + "\n\n" str += "Connected to " + conn.Host + "\n\n"
} else { } else {
str += "Not currently connected!\n\n" str += "Not currently connected!\n\n"