summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-05-11 19:46:13 +0200
committerxengineering <me@xengineering.eu>2023-05-11 19:46:13 +0200
commit6ec791ba0fffb2a0c8e0e603f4f5f0cc2b6f5e18 (patch)
treed070de96a7013bedf839af416f98c61ebf7a7e57
parent2662bcd350c51ee3a0db2a7750fe4551de23fb04 (diff)
downloadlimox-6ec791ba0fffb2a0c8e0e603f4f5f0cc2b6f5e18.tar
limox-6ec791ba0fffb2a0c8e0e603f4f5f0cc2b6f5e18.tar.zst
limox-6ec791ba0fffb2a0c8e0e603f4f5f0cc2b6f5e18.zip
Refactor with new rxRoutine function
-rw-r--r--xmpp.go39
1 files changed, 20 insertions, 19 deletions
diff --git a/xmpp.go b/xmpp.go
index 6540ae5..9e09700 100644
--- a/xmpp.go
+++ b/xmpp.go
@@ -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"},