This commit is contained in:
crusader 2018-04-04 23:21:40 +09:00
parent 63fd249b1b
commit 33c01a5e3c
2 changed files with 12 additions and 6 deletions

View File

@ -29,16 +29,11 @@ func (crw *ClientReadWriter) HandleConnection(conn *Conn) {
logging.Logger().Infof("connected") logging.Logger().Infof("connected")
stopChan := make(chan struct{})
readerDoneChan := make(chan error)
writerDoneChan := make(chan error)
var err error var err error
for { for {
if nil != err { if nil != err {
if io.EOF == err || io.ErrUnexpectedEOF == err { if IsUnexpectedCloseError(err) || io.EOF == err || io.ErrUnexpectedEOF == err {
crw.DisconnectedChan <- struct{}{} crw.DisconnectedChan <- struct{}{}
newConn := <-crw.ReconnectedChan newConn := <-crw.ReconnectedChan
if nil == newConn { 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 connReadHandler(crw.ReadwriteHandler, conn, stopChan, readerDoneChan, crw.ReadChan)
go connWriteHandler(crw.ReadwriteHandler, conn, stopChan, writerDoneChan, crw.WriteChan) go connWriteHandler(crw.ReadwriteHandler, conn, stopChan, writerDoneChan, crw.WriteChan)

View File

@ -107,14 +107,20 @@ RC_LOOP:
continue RC_LOOP continue RC_LOOP
} }
logging.Logger().Debugf("connection lost")
for indexI := 0; indexI < c.ReconnectTryTime; indexI++ { for indexI := 0; indexI < c.ReconnectTryTime; indexI++ {
logging.Logger().Debugf("trying reconnect[%d]", indexI)
conn, err := c.connect() conn, err := c.connect()
if nil == err { if nil == err {
logging.Logger().Debugf("reconnected")
c.reconnectedChan <- conn c.reconnectedChan <- conn
continue RC_LOOP continue RC_LOOP
} }
time.Sleep(c.ReconnectInterval) time.Sleep(c.ReconnectInterval)
} }
logging.Logger().Debugf("reconnecting has been failed")
} }
} }