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

View File

@ -22,8 +22,6 @@ type Connectors struct {
Address string `json:"address,omitempty"` Address string `json:"address,omitempty"`
LocalAddress net.Addr `json:"-"` LocalAddress net.Addr `json:"-"`
OnDisconnected func(connector client.Connector) `json:"-"`
stopChan chan struct{} stopChan chan struct{}
stopWg sync.WaitGroup 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. // If Proxy is nil or returns a nil *URL, no proxy is used.
Proxy func(*http.Request) (*url.URL, error) `json:"-"` Proxy func(*http.Request) (*url.URL, error) `json:"-"`
OnDisconnected func(connector client.Connector) `json:"-"`
serverURL *url.URL serverURL *url.URL
stopChan chan struct{} stopChan chan struct{}