diff options
author | xengineering <me@xengineering.eu> | 2023-05-11 19:46:13 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-05-11 19:46:13 +0200 |
commit | 6ec791ba0fffb2a0c8e0e603f4f5f0cc2b6f5e18 (patch) | |
tree | d070de96a7013bedf839af416f98c61ebf7a7e57 | |
parent | 2662bcd350c51ee3a0db2a7750fe4551de23fb04 (diff) | |
download | limox-6ec791ba0fffb2a0c8e0e603f4f5f0cc2b6f5e18.tar limox-6ec791ba0fffb2a0c8e0e603f4f5f0cc2b6f5e18.tar.zst limox-6ec791ba0fffb2a0c8e0e603f4f5f0cc2b6f5e18.zip |
Refactor with new rxRoutine function
-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"}, |