Improve listening mode.

v0.10
Martin Dosch 4 weeks ago
parent 93d8bbedaa
commit 9aea1e294a
No known key found for this signature in database
GPG Key ID: 52A57CFCE13D657D

@ -20,7 +20,7 @@ import (
func sendIQ(client *xmpp.Client, iqc chan xmpp.IQ, target string, iQtype string, content string) (xmpp.IQ, error) {
var iq xmpp.IQ
id := getID()
c := make(chan xmpp.IQ)
c := make(chan xmpp.IQ, defaultBufferSize)
go getIQ(id, c, iqc)
_, err := client.RawInformation(client.JID(), target, id,
iQtype, content)
@ -47,11 +47,15 @@ func getIQ(id string, c chan xmpp.IQ, iqc chan xmpp.IQ) {
func rcvStanzas(client *xmpp.Client, ctx context.Context, iqc chan xmpp.IQ, msgc chan xmpp.Chat) {
var received interface{}
var err error
r := make(chan interface{})
e := make(chan error)
r := make(chan interface{}, defaultBufferSize)
e := make(chan error, defaultBufferSize)
go func() {
for {
select {
case <-ctx.Done():
return
default:
}
rcv, err := client.Recv()
if err != nil {
e <- err
@ -64,7 +68,7 @@ func rcvStanzas(client *xmpp.Client, ctx context.Context, iqc chan xmpp.IQ, msgc
select {
case <-ctx.Done():
return
case err = <-e:
case err := <-e:
if err != nil {
if err != io.EOF {
closeAndExit(client, err)
@ -76,13 +80,14 @@ func rcvStanzas(client *xmpp.Client, ctx context.Context, iqc chan xmpp.IQ, msgc
}
switch v := received.(type) {
case xmpp.Chat:
msgc <- v
case xmpp.IQ:
switch v.Type {
case "get":
var xmlns *etree.Attr
iq := etree.NewDocument()
err = iq.ReadFromBytes(v.Query)
err := iq.ReadFromBytes(v.Query)
if err != nil {
log.Println("Couldn't parse IQ:",
string(v.Query), err)

Loading…
Cancel
Save