Check if we have a connection open before trying to close it

Fixes #22
This commit is contained in:
Mickael Remond 2019-09-06 10:28:49 +02:00
parent 7e596fc33c
commit 8794ea6ed8
No known key found for this signature in database
GPG Key ID: E6F6045D79965AA3
2 changed files with 8 additions and 2 deletions

View File

@ -189,7 +189,10 @@ func (c *Client) Resume(state SMState) error {
func (c *Client) Disconnect() {
_ = c.SendRaw("</stream:stream>")
// TODO: Add a way to wait for stream close acknowledgement from the server for clean disconnect
_ = c.conn.Close()
conn := c.conn
if conn != nil {
_ = conn.Close()
}
}
func (c *Client) SetHandler(handler EventHandler) {

View File

@ -123,7 +123,10 @@ func (c *Component) Resume(sm SMState) error {
func (c *Component) Disconnect() {
_ = c.SendRaw("</stream:stream>")
// TODO: Add a way to wait for stream close acknowledgement from the server for clean disconnect
_ = c.conn.Close()
conn := c.conn
if conn != nil {
_ = conn.Close()
}
}
func (c *Component) SetHandler(handler EventHandler) {