mirror of https://github.com/fluffle/goirc
Fix for issues/6 (1/2): Don't close channels when disconnected.
This commit is contained in:
parent
a5a4f989ac
commit
eb51558009
|
@ -69,29 +69,30 @@ type Line struct {
|
||||||
// Creates a new IRC connection object, but doesn't connect to anything so
|
// Creates a new IRC connection object, but doesn't connect to anything so
|
||||||
// that you can add event handlers to it. See AddHandler() for details.
|
// that you can add event handlers to it. See AddHandler() for details.
|
||||||
func New(nick, user, name string) *Conn {
|
func New(nick, user, name string) *Conn {
|
||||||
conn := new(Conn)
|
conn := &Conn{
|
||||||
conn.initialise()
|
in: make(chan *Line, 32),
|
||||||
conn.SSL = false
|
out: make(chan string, 32),
|
||||||
conn.SSLConfig = nil
|
Err: make(chan os.Error, 4),
|
||||||
conn.Timeout = 300
|
SSL: false,
|
||||||
|
SSLConfig: nil,
|
||||||
|
Timeout: 300,
|
||||||
|
Timestamp: time.LocalTime,
|
||||||
|
TSFormat: "15:04:05",
|
||||||
|
}
|
||||||
conn.Me = conn.NewNick(nick, user, name, "")
|
conn.Me = conn.NewNick(nick, user, name, "")
|
||||||
conn.Timestamp = time.LocalTime
|
conn.initialise()
|
||||||
conn.TSFormat = "15:04:05"
|
|
||||||
conn.setupEvents()
|
conn.setupEvents()
|
||||||
return conn
|
return conn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Per-connection state initialisation.
|
||||||
func (conn *Conn) initialise() {
|
func (conn *Conn) initialise() {
|
||||||
// allocate meh some memoraaaahh
|
|
||||||
conn.nicks = make(map[string]*Nick)
|
conn.nicks = make(map[string]*Nick)
|
||||||
conn.chans = make(map[string]*Channel)
|
conn.chans = make(map[string]*Channel)
|
||||||
conn.in = make(chan *Line, 32)
|
|
||||||
conn.out = make(chan string, 32)
|
|
||||||
conn.Err = make(chan os.Error, 4)
|
|
||||||
conn.io = nil
|
conn.io = nil
|
||||||
conn.sock = nil
|
conn.sock = nil
|
||||||
|
|
||||||
// if this is being called because we are reconnecting, conn.Me
|
// If this is being called because we are reconnecting, conn.Me
|
||||||
// will still have all the old channels referenced -- nuke them!
|
// will still have all the old channels referenced -- nuke them!
|
||||||
if conn.Me != nil {
|
if conn.Me != nil {
|
||||||
conn.Me = conn.NewNick(conn.Me.Nick, conn.Me.Ident, conn.Me.Name, "")
|
conn.Me = conn.NewNick(conn.Me.Nick, conn.Me.Ident, conn.Me.Name, "")
|
||||||
|
@ -254,9 +255,6 @@ func (conn *Conn) runLoop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conn *Conn) shutdown() {
|
func (conn *Conn) shutdown() {
|
||||||
close(conn.in)
|
|
||||||
close(conn.out)
|
|
||||||
close(conn.Err)
|
|
||||||
conn.connected = false
|
conn.connected = false
|
||||||
conn.sock.Close()
|
conn.sock.Close()
|
||||||
// reinit datastructures ready for next connection
|
// reinit datastructures ready for next connection
|
||||||
|
|
Loading…
Reference in New Issue