package xmpp import ( "crypto/tls" "encoding/xml" "log" ) type decoder struct { terminator chan bool data chan xml.Token decoder *xml.Decoder } func newDecoder(conn *tls.Conn) decoder { return decoder{ make(chan bool), make(chan xml.Token), xml.NewDecoder(conn), } } func (r *decoder) 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 *decoder) stop() { r.terminator <- true }