From 4691a6923a7fcd9b5f63ea7cc393aa0201c3842d Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 12 Apr 2018 10:55:29 +0900 Subject: [PATCH] ing --- client/client.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/client/client.go b/client/client.go index 65a3f66..4c7b21d 100644 --- a/client/client.go +++ b/client/client.go @@ -30,7 +30,7 @@ type Client struct { pendingRequests sync.Map } -func (c *Client) Start(readChan <-chan []byte, writeChan chan<- []byte) error { +func (c *Client) Start() error { if c.stopChan != nil { return fmt.Errorf("%s already running. Stop it before starting it again", c.logHeader()) } @@ -47,6 +47,11 @@ func (c *Client) Start(readChan <-chan []byte, writeChan chan<- []byte) error { return fmt.Errorf("%s Codec is not valid", c.logHeader()) } + readChan, writeChan, err := c.Connector.Connect() + if nil != err { + return err + } + c.stopChan = make(chan struct{}) c.stopWg.Add(1) @@ -158,6 +163,12 @@ func (c *Client) internalSend(hasResponse bool, result interface{}, method strin func (c *Client) handleClient(readChan <-chan []byte, writeChan chan<- []byte) { defer func() { + + if err := c.Connector.Disconnect(); nil != err { + logging.Logger().Warn(err) + } + + logging.Logger().Infof("%s Stopped", c.logHeader()) c.stopWg.Done() }() @@ -168,6 +179,8 @@ func (c *Client) handleClient(readChan <-chan []byte, writeChan chan<- []byte) { go c.handleSend(stopChan, sendDoneChan, writeChan) go c.handleReceive(stopChan, receiveDoneChan, readChan) + logging.Logger().Infof("%s Started", c.logHeader()) + select { case <-sendDoneChan: close(stopChan)