diff options
Diffstat (limited to 'xmpp/xmpp.go')
-rw-r--r-- | xmpp/xmpp.go | 44 |
1 files changed, 4 insertions, 40 deletions
diff --git a/xmpp/xmpp.go b/xmpp/xmpp.go index 64ca494..fa61e0b 100644 --- a/xmpp/xmpp.go +++ b/xmpp/xmpp.go @@ -24,9 +24,9 @@ func Run(rxChan chan Event, txChan chan any, jid string, pwd string) { } defer conn.Close() - receiver := newXmppReceiver(conn) - go receiver.run() - defer receiver.stop() + decoder := newDecoder(conn) + go decoder.run() + defer decoder.stop() enc := xml.NewEncoder(conn) defer enc.Close() @@ -48,7 +48,7 @@ func Run(rxChan chan Event, txChan chan any, jid string, pwd string) { default: log.Printf("Unknown Event '%d'!\n", ev) } - case rx := <-receiver.data: + case rx := <-decoder.data: dbg.Indent("S: ", " ") dbg.EncodeToken(rx) dbg.Flush() @@ -56,42 +56,6 @@ func Run(rxChan chan Event, txChan chan any, jid string, pwd string) { } } -type xmppReceiver struct { - terminator chan bool - data chan xml.Token - decoder *xml.Decoder -} - -func newXmppReceiver(conn *tls.Conn) xmppReceiver { - return xmppReceiver{ - make(chan bool), - make(chan xml.Token), - xml.NewDecoder(conn), - } -} - -func (r *xmppReceiver) run() { - for { - select { - case <-r.terminator: - return - default: - t, err := r.decoder.Token() - if err != nil { - log.Print(err) - } - if t != nil { - c := xml.CopyToken(t) - r.data <- c - } - } - } -} - -func (r *xmppReceiver) stop() { - r.terminator <- true -} - func setupConn(jid string) (*tls.Conn, error) { domain := domainpart(jid) |