This commit is contained in:
crusader 2018-04-18 21:21:05 +09:00
parent 68341e3eb5
commit d2e6df0fbf
3 changed files with 17 additions and 6 deletions

View File

@ -1,12 +1,18 @@
package client
import "sync/atomic"
import (
"sync/atomic"
)
type OnDisconnectedFunc func(connector Connector)
type Connector interface {
Connect() (readChan <-chan []byte, writeChan chan<- []byte, err error)
Disconnect() error
GetName() string
GetOnDisconnected() OnDisconnectedFunc
SetOnDisconnected(fnc OnDisconnectedFunc)
Clone() Connector
Validate() error
@ -14,6 +20,7 @@ type Connector interface {
type Connectors struct {
Name string `json:"name,omitempty"`
OnDisconnected OnDisconnectedFunc `json:"-"`
validated atomic.Value
}
@ -22,6 +29,14 @@ func (c *Connectors) GetName() string {
return c.Name
}
func (c *Connectors) GetOnDisconnected() OnDisconnectedFunc {
return c.OnDisconnected
}
func (c *Connectors) SetOnDisconnected(fnc OnDisconnectedFunc) {
c.OnDisconnected = fnc
}
func (c *Connectors) Clone() *Connectors {
return &Connectors{
Name: c.Name,

View File

@ -22,8 +22,6 @@ type Connectors struct {
Address string `json:"address,omitempty"`
LocalAddress net.Addr `json:"-"`
OnDisconnected func(connector client.Connector) `json:"-"`
stopChan chan struct{}
stopWg sync.WaitGroup

View File

@ -52,8 +52,6 @@ type Connectors struct {
// If Proxy is nil or returns a nil *URL, no proxy is used.
Proxy func(*http.Request) (*url.URL, error) `json:"-"`
OnDisconnected func(connector client.Connector) `json:"-"`
serverURL *url.URL
stopChan chan struct{}