This commit is contained in:
crusader 2018-07-02 17:03:45 +09:00
parent 20a63b3de6
commit cbe8e30db4
3 changed files with 32 additions and 37 deletions

View File

@ -9,6 +9,9 @@ import (
type OnDisconnectedFunc func(connector Connector)
type Connector interface {
socket.ClientConnHandler
socket.ReadWriteHandler
Connect() (readChan <-chan socket.SocketMessage, writeChan chan<- socket.SocketMessage, err error)
Disconnect() error
@ -21,6 +24,9 @@ type Connector interface {
}
type Connectors struct {
socket.ClientConnHandlers
socket.ReadWriteHandlers
Name string `json:"name,omitempty"`
OnDisconnected OnDisconnectedFunc `json:"-"`
@ -41,8 +47,10 @@ func (c *Connectors) SetOnDisconnected(fnc OnDisconnectedFunc) {
func (c *Connectors) Clone() *Connectors {
return &Connectors{
Name: c.Name,
validated: c.validated,
Name: c.Name,
ClientConnHandlers: *c.ClientConnHandlers.Clone(),
ReadWriteHandlers: *c.ReadWriteHandlers.Clone(),
validated: c.validated,
}
}
@ -52,6 +60,13 @@ func (c *Connectors) Validate() error {
}
c.validated.Store(true)
if err := c.ClientConnHandlers.Validate(); nil != err {
return err
}
if err := c.ReadWriteHandlers.Validate(); nil != err {
return err
}
if "" == c.Name {
c.Name = "Connector"
}

View File

@ -15,8 +15,6 @@ import (
type Connectors struct {
client.Connectors
socket.ClientConnHandlers
socket.ReadWriteHandlers
Network string `json:"network,omitempty"`
Address string `json:"address,omitempty"`
@ -191,13 +189,11 @@ func (c *Connectors) dial() (net.Conn, error) {
func (c *Connectors) Clone() client.Connector {
return &Connectors{
Connectors: *c.Connectors.Clone(),
ClientConnHandlers: *c.ClientConnHandlers.Clone(),
ReadWriteHandlers: *c.ReadWriteHandlers.Clone(),
Network: c.Network,
Address: c.Address,
LocalAddress: c.LocalAddress,
validated: c.validated,
Connectors: *c.Connectors.Clone(),
Network: c.Network,
Address: c.Address,
LocalAddress: c.LocalAddress,
validated: c.validated,
}
}
@ -210,12 +206,6 @@ func (c *Connectors) Validate() error {
if err := c.Connectors.Validate(); nil != err {
return err
}
if err := c.ClientConnHandlers.Validate(); nil != err {
return err
}
if err := c.ReadWriteHandlers.Validate(); nil != err {
return err
}
if "" == c.Network {
return fmt.Errorf("%s Network is not valid", c.logHeader())

View File

@ -27,8 +27,6 @@ var errMalformedURL = errors.New("malformed ws or wss URL")
type Connectors struct {
client.Connectors
socket.ClientConnHandlers
socket.ReadWriteHandlers
URL string `json:"url,omitempty"`
@ -482,18 +480,16 @@ func cloneTLSConfig(cfg *tls.Config) *tls.Config {
func (c *Connectors) Clone() client.Connector {
return &Connectors{
Connectors: *c.Connectors.Clone(),
ClientConnHandlers: *c.ClientConnHandlers.Clone(),
ReadWriteHandlers: *c.ReadWriteHandlers.Clone(),
URL: c.URL,
RequestHeader: c.RequestHeader,
Subprotocols: c.Subprotocols,
CookieJar: c.CookieJar,
ResponseHandler: c.ResponseHandler,
NetDial: c.NetDial,
Proxy: c.Proxy,
serverURL: c.serverURL,
validated: c.validated,
Connectors: *c.Connectors.Clone(),
URL: c.URL,
RequestHeader: c.RequestHeader,
Subprotocols: c.Subprotocols,
CookieJar: c.CookieJar,
ResponseHandler: c.ResponseHandler,
NetDial: c.NetDial,
Proxy: c.Proxy,
serverURL: c.serverURL,
validated: c.validated,
}
}
@ -506,12 +502,6 @@ func (c *Connectors) Validate() error {
if err := c.Connectors.Validate(); nil != err {
return err
}
if err := c.ClientConnHandlers.Validate(); nil != err {
return err
}
if err := c.ReadWriteHandlers.Validate(); nil != err {
return err
}
if "" == c.URL {
return fmt.Errorf("URL is not valid")