xmpp/xmpp.go
changeset 176 52c100897e9d
parent 175 fc8702a8572e
parent 170 d496de556c9a
child 178 ccfebbd9f49b
equal deleted inserted replaced
175:fc8702a8572e 176:52c100897e9d
    11 	"encoding/xml"
    11 	"encoding/xml"
    12 	"fmt"
    12 	"fmt"
    13 	"io"
    13 	"io"
    14 	"net"
    14 	"net"
    15 	"reflect"
    15 	"reflect"
       
    16 	"sync"
    16 )
    17 )
    17 
    18 
    18 const (
    19 const (
    19 	// Version of RFC 3920 that we implement.
    20 	// Version of RFC 3920 that we implement.
    20 	XMPPVersion = "1.0"
    21 	XMPPVersion = "1.0"
    64 	// Incoming XMPP stanzas from the remote will be published on
    65 	// Incoming XMPP stanzas from the remote will be published on
    65 	// this channel. Information which is used by this library to
    66 	// this channel. Information which is used by this library to
    66 	// set up the XMPP stream will not appear here.
    67 	// set up the XMPP stream will not appear here.
    67 	Recv <-chan Stanza
    68 	Recv <-chan Stanza
    68 	// Outgoing XMPP stanzas to the server should be sent to this
    69 	// Outgoing XMPP stanzas to the server should be sent to this
    69 	// channel.
    70 	// channel. The application should not close this channel;
       
    71 	// rather, call Close().
    70 	Send    chan<- Stanza
    72 	Send    chan<- Stanza
    71 	sendRaw chan<- interface{}
    73 	sendRaw chan<- interface{}
    72 	statmgr *statmgr
    74 	statmgr *statmgr
    73 	// The client's roster is also known as the buddy list. It's
    75 	// The client's roster is also known as the buddy list. It's
    74 	// the set of contacts which are known to this JID, or which
    76 	// the set of contacts which are known to this JID, or which
    78 	Features                     *Features
    80 	Features                     *Features
    79 	sendFilterAdd, recvFilterAdd chan Filter
    81 	sendFilterAdd, recvFilterAdd chan Filter
    80 	tlsConfig                    tls.Config
    82 	tlsConfig                    tls.Config
    81 	layer1                       *layer1
    83 	layer1                       *layer1
    82 	error                        chan error
    84 	error                        chan error
       
    85 	shutdownOnce                 sync.Once
    83 }
    86 }
    84 
    87 
    85 // Creates an XMPP client identified by the given JID, authenticating
    88 // Creates an XMPP client identified by the given JID, authenticating
    86 // with the provided password and TLS config. Zero or more extensions
    89 // with the provided password and TLS config. Zero or more extensions
    87 // may be specified. The initial presence will be broadcast. If status
    90 // may be specified. The initial presence will be broadcast. If status
   254 }
   257 }
   255 
   258 
   256 func (cl *Client) Close() {
   259 func (cl *Client) Close() {
   257 	// Shuts down the receivers:
   260 	// Shuts down the receivers:
   258 	cl.setStatus(StatusShutdown)
   261 	cl.setStatus(StatusShutdown)
       
   262 
   259 	// Shuts down the senders:
   263 	// Shuts down the senders:
   260 	close(cl.Send)
   264 	cl.shutdownOnce.Do(func() { close(cl.Send) })
   261 }
   265 }
   262 
   266 
   263 // If there's a buffered error in the channel, return it. Otherwise,
   267 // If there's a buffered error in the channel, return it. Otherwise,
   264 // return what was passed to us. The idea is that the error in the
   268 // return what was passed to us. The idea is that the error in the
   265 // channel probably preceded (and caused) the one that's passed as an
   269 // channel probably preceded (and caused) the one that's passed as an