This repository has been archived by the owner on May 1, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the background autoconnect feature which automatically maintains the connection and tries to reconnect whenever the connection is lost when autoconnect is enabled.
- Loading branch information
Showing
12 changed files
with
245 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
package client | ||
|
||
import "sync/atomic" | ||
import ( | ||
"sync/atomic" | ||
) | ||
|
||
func (clt *Client) close() { | ||
clt.connLock.Lock() | ||
defer clt.connLock.Unlock() | ||
if atomic.LoadInt32(&clt.isConnected) < 1 { | ||
if atomic.LoadInt32(&clt.status) < StatConnected { | ||
// Either disconnected or disabled | ||
return | ||
} | ||
if err := clt.conn.Close(); err != nil { | ||
clt.errorLog.Printf("Failed closing connection: %s", err) | ||
} | ||
atomic.StoreInt32(&clt.isConnected, 0) | ||
atomic.StoreInt32(&clt.status, StatDisabled) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.