diff options
author | Wim <wim@42.be> | 2016-10-29 18:59:12 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2016-10-29 18:59:12 +0200 |
commit | 5249568b8ebe2e27f2c952e019f4bdf7504a92d2 (patch) | |
tree | c5d4b8c3e364abc3aec30fb737a069b905e86a51 | |
parent | 4a336a6bbae78ae47ecea1708b784572b7a10ae5 (diff) | |
download | matterbridge-msglm-5249568b8ebe2e27f2c952e019f4bdf7504a92d2.tar.gz matterbridge-msglm-5249568b8ebe2e27f2c952e019f4bdf7504a92d2.tar.bz2 matterbridge-msglm-5249568b8ebe2e27f2c952e019f4bdf7504a92d2.zip |
Wait until the welcome message before connection is ok (irc). Fixes #62
-rw-r--r-- | bridge/irc/irc.go | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/bridge/irc/irc.go b/bridge/irc/irc.go index ea040af5..e5b6858c 100644 --- a/bridge/irc/irc.go +++ b/bridge/irc/irc.go @@ -2,6 +2,7 @@ package birc import ( "crypto/tls" + "fmt" "github.com/42wim/matterbridge/bridge/config" log "github.com/Sirupsen/logrus" ircm "github.com/sorcix/irc" @@ -14,13 +15,14 @@ import ( ) type Birc struct { - i *irc.Connection - Nick string - names map[string][]string - Config *config.Protocol - origin string - protocol string - Remote chan config.Message + i *irc.Connection + Nick string + names map[string][]string + Config *config.Protocol + origin string + protocol string + Remote chan config.Message + connected chan struct{} } var flog *log.Entry @@ -38,6 +40,7 @@ func New(config config.Protocol, origin string, c chan config.Message) *Birc { b.names = make(map[string][]string) b.origin = origin b.protocol = protocol + b.connected = make(chan struct{}) return b } @@ -70,9 +73,14 @@ func (b *Birc) Connect() error { if err != nil { return err } - flog.Info("Connection succeeded") - i.Debug = false b.i = i + select { + case <-b.connected: + flog.Info("Connection succeeded") + case <-time.After(time.Second * 30): + return fmt.Errorf("connection timed out") + } + i.Debug = false return nil } @@ -143,6 +151,8 @@ func (b *Birc) handleNewConnection(event *irc.Event) { flog.Debugf("PING/PONG") }) i.AddCallback("*", b.handleOther) + // we are now fully connected + b.connected <- struct{}{} } func (b *Birc) handleNotice(event *irc.Event) { |