--- a/xmpp/xmpp.go Wed Nov 06 20:38:03 2013 -0700
+++ b/xmpp/xmpp.go Wed Nov 06 20:39:36 2013 -0700
@@ -13,6 +13,7 @@
"io"
"net"
"reflect"
+ "sync"
)
const (
@@ -66,7 +67,8 @@
// set up the XMPP stream will not appear here.
Recv <-chan Stanza
// Outgoing XMPP stanzas to the server should be sent to this
- // channel.
+ // channel. The application should not close this channel;
+ // rather, call Close().
Send chan<- Stanza
sendRaw chan<- interface{}
statmgr *statmgr
@@ -80,6 +82,7 @@
tlsConfig tls.Config
layer1 *layer1
error chan error
+ shutdownOnce sync.Once
}
// Creates an XMPP client identified by the given JID, authenticating
@@ -256,8 +259,9 @@
func (cl *Client) Close() {
// Shuts down the receivers:
cl.setStatus(StatusShutdown)
+
// Shuts down the senders:
- close(cl.Send)
+ cl.shutdownOnce.Do(func() { close(cl.Send) })
}
// If there's a buffered error in the channel, return it. Otherwise,