From d2e6df0fbff6baf7e40a457d28a3e4f2495030e3 Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 18 Apr 2018 21:21:05 +0900 Subject: [PATCH] ing --- client/connector.go | 19 +++++++++++++++++-- socket/net/client/connector.go | 2 -- socket/web/client/connector.go | 2 -- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/client/connector.go b/client/connector.go index dd3b252..0a55fef 100644 --- a/client/connector.go +++ b/client/connector.go @@ -1,19 +1,26 @@ 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 } type Connectors struct { - Name string `json:"name,omitempty"` + 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, diff --git a/socket/net/client/connector.go b/socket/net/client/connector.go index cff84b7..055ddb9 100644 --- a/socket/net/client/connector.go +++ b/socket/net/client/connector.go @@ -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 diff --git a/socket/web/client/connector.go b/socket/web/client/connector.go index 0345bae..8854174 100644 --- a/socket/web/client/connector.go +++ b/socket/web/client/connector.go @@ -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{}