File tree Expand file tree Collapse file tree 1 file changed +4
-1
lines changed
Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,9 @@ var connectionCache map[string]*Connection = make(map[string]*Connection)
2424// Creates a new connection to a RCT device at the given address
2525func NewConnection (host string , cache time.Duration ) (* Connection , error ) {
2626 if conn , ok := connectionCache [host ]; ok {
27- return conn , nil
27+ if conn .conn != nil { // there might be dead connection in the cache, e.g. when connection was disconnected
28+ return conn , nil
29+ }
2830 }
2931
3032 conn := & Connection {
@@ -53,6 +55,7 @@ func (c *Connection) connect() (err error) {
5355func (c * Connection ) Close () {
5456 c .conn .Close ()
5557 c .conn = nil
58+ delete (connectionCache , c .host ) // connection is dead, no need to cache any more
5659}
5760
5861// Sends the given RCT datagram via the connection
You can’t perform that action at this time.
0 commit comments