blob: 97329c7a973acdd65523570481db8bece716bf90 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
}
|