diff options
Diffstat (limited to 'xmpp/decoder.go')
-rw-r--r-- | xmpp/decoder.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/xmpp/decoder.go b/xmpp/decoder.go new file mode 100644 index 0000000..97329c7 --- /dev/null +++ b/xmpp/decoder.go @@ -0,0 +1,43 @@ +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 +} |