From 33c01a5e3c518650fb0c1190ffdcb276b348975d Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 4 Apr 2018 23:21:40 +0900 Subject: [PATCH] ing --- client-readwriter.go | 12 ++++++------ net/client.go | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/client-readwriter.go b/client-readwriter.go index d5daa72..60c7328 100644 --- a/client-readwriter.go +++ b/client-readwriter.go @@ -29,16 +29,11 @@ func (crw *ClientReadWriter) HandleConnection(conn *Conn) { logging.Logger().Infof("connected") - stopChan := make(chan struct{}) - - readerDoneChan := make(chan error) - writerDoneChan := make(chan error) - var err error for { if nil != err { - if io.EOF == err || io.ErrUnexpectedEOF == err { + if IsUnexpectedCloseError(err) || io.EOF == err || io.ErrUnexpectedEOF == err { crw.DisconnectedChan <- struct{}{} newConn := <-crw.ReconnectedChan if nil == newConn { @@ -50,6 +45,11 @@ func (crw *ClientReadWriter) HandleConnection(conn *Conn) { } } + stopChan := make(chan struct{}) + + readerDoneChan := make(chan error) + writerDoneChan := make(chan error) + go connReadHandler(crw.ReadwriteHandler, conn, stopChan, readerDoneChan, crw.ReadChan) go connWriteHandler(crw.ReadwriteHandler, conn, stopChan, writerDoneChan, crw.WriteChan) diff --git a/net/client.go b/net/client.go index a75e287..12e3c8c 100644 --- a/net/client.go +++ b/net/client.go @@ -107,14 +107,20 @@ RC_LOOP: continue RC_LOOP } + logging.Logger().Debugf("connection lost") + for indexI := 0; indexI < c.ReconnectTryTime; indexI++ { + logging.Logger().Debugf("trying reconnect[%d]", indexI) + conn, err := c.connect() if nil == err { + logging.Logger().Debugf("reconnected") c.reconnectedChan <- conn continue RC_LOOP } time.Sleep(c.ReconnectInterval) } + logging.Logger().Debugf("reconnecting has been failed") } }