Show last IRC connection error in status tab, log IRC connection errors
This commit is contained in:
parent
786d8013b9
commit
18aff3ded6
19 changed files with 294 additions and 189 deletions
|
@ -20,7 +20,7 @@ type Client struct {
|
|||
Username string
|
||||
Realname string
|
||||
Messages chan *Message
|
||||
ConnectionChanged chan bool
|
||||
ConnectionChanged chan ConnectionState
|
||||
HandleNickInUse func(string) string
|
||||
|
||||
nick string
|
||||
|
@ -47,7 +47,7 @@ func NewClient(nick, username string) *Client {
|
|||
Username: username,
|
||||
Realname: nick,
|
||||
Messages: make(chan *Message, 32),
|
||||
ConnectionChanged: make(chan bool, 16),
|
||||
ConnectionChanged: make(chan ConnectionState, 16),
|
||||
out: make(chan string, 32),
|
||||
quit: make(chan struct{}),
|
||||
reconnect: make(chan struct{}),
|
||||
|
|
23
irc/conn.go
23
irc/conn.go
|
@ -10,8 +10,6 @@ import (
|
|||
)
|
||||
|
||||
func (c *Client) Connect(address string) {
|
||||
c.ConnectionChanged <- false
|
||||
|
||||
if idx := strings.Index(address, ":"); idx < 0 {
|
||||
c.Host = address
|
||||
|
||||
|
@ -26,6 +24,7 @@ func (c *Client) Connect(address string) {
|
|||
c.Server = address
|
||||
c.dialer = &net.Dialer{Timeout: 10 * time.Second}
|
||||
|
||||
c.connChange(false, nil)
|
||||
go c.run()
|
||||
}
|
||||
|
||||
|
@ -71,8 +70,20 @@ func (c *Client) run() {
|
|||
}
|
||||
}
|
||||
|
||||
type ConnectionState struct {
|
||||
Connected bool
|
||||
Error error
|
||||
}
|
||||
|
||||
func (c *Client) connChange(connected bool, err error) {
|
||||
c.ConnectionChanged <- ConnectionState{
|
||||
Connected: connected,
|
||||
Error: err,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) disconnect() {
|
||||
c.ConnectionChanged <- false
|
||||
c.connChange(false, nil)
|
||||
c.lock.Lock()
|
||||
c.connected = false
|
||||
c.lock.Unlock()
|
||||
|
@ -91,7 +102,9 @@ func (c *Client) tryConnect() {
|
|||
}
|
||||
|
||||
err := c.connect()
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
c.connChange(false, err)
|
||||
} else {
|
||||
c.backoff.Reset()
|
||||
|
||||
c.flushChannels()
|
||||
|
@ -123,7 +136,7 @@ func (c *Client) connect() error {
|
|||
}
|
||||
|
||||
c.connected = true
|
||||
c.ConnectionChanged <- true
|
||||
c.connChange(true, nil)
|
||||
c.reader = bufio.NewReader(c.conn)
|
||||
|
||||
c.register()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue