diff options
Diffstat (limited to 'xmpp.go')
-rw-r--r-- | xmpp.go | 39 |
1 files changed, 20 insertions, 19 deletions
@@ -37,25 +37,7 @@ func (l *Limox) xmpp(jid string, pwd string) { receiver := make(chan xml.Token) termination := make(chan bool) - go func() { - quit := false - dec := xml.NewDecoder(conn) - for { - select { - case <-termination: - quit = true - default: - t, _ := dec.Token() - if t != nil { - receiver <- t - } - } - if quit { - break - } - } - log.Println("Done!") - }() + go rxRoutine(conn, receiver, termination) dbg := xml.NewEncoder(os.Stdout) @@ -89,6 +71,25 @@ func (l *Limox) xmpp(jid string, pwd string) { l.XmppEvents <- XmppDisconnect } +func rxRoutine(conn *tls.Conn, tokens chan xml.Token, terminator chan bool) { + quit := false + dec := xml.NewDecoder(conn) + for { + select { + case <-terminator: + quit = true + default: + t, _ := dec.Token() + if t != nil { + tokens <- t + } + } + if quit { + break + } + } +} + func sendStreamStart(enc *xml.Encoder, jid string) (xml.EndElement) { start := xml.StartElement{ xml.Name{"jabber:client", "stream:stream"}, |