equal
deleted
inserted
replaced
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" |
78 Features *Features |
79 Features *Features |
79 sendFilterAdd, recvFilterAdd chan Filter |
80 sendFilterAdd, recvFilterAdd chan Filter |
80 tlsConfig tls.Config |
81 tlsConfig tls.Config |
81 layer1 *layer1 |
82 layer1 *layer1 |
82 error chan error |
83 error chan error |
|
84 shutdownOnce sync.Once |
83 } |
85 } |
84 |
86 |
85 // Creates an XMPP client identified by the given JID, authenticating |
87 // Creates an XMPP client identified by the given JID, authenticating |
86 // with the provided password and TLS config. Zero or more extensions |
88 // with the provided password and TLS config. Zero or more extensions |
87 // may be specified. The initial presence will be broadcast. If status |
89 // may be specified. The initial presence will be broadcast. If status |
247 |
249 |
248 // Register an error that happened in the internals somewhere. If |
250 // Register an error that happened in the internals somewhere. If |
249 // there's already an error in the channel, discard the newer one in |
251 // there's already an error in the channel, discard the newer one in |
250 // favor of the older. |
252 // favor of the older. |
251 func (cl *Client) setError(err error) { |
253 func (cl *Client) setError(err error) { |
252 defer cl.Close() |
254 shutdown := func() { |
253 defer cl.setStatus(StatusError) |
255 cl.setStatus(StatusError) |
|
256 cl.Close() |
|
257 } |
|
258 defer cl.shutdownOnce.Do(shutdown) |
254 |
259 |
255 if len(cl.error) > 0 { |
260 if len(cl.error) > 0 { |
256 return |
261 return |
257 } |
262 } |
258 // If we're in a race between two calls to this function, |
263 // If we're in a race between two calls to this function, |