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")
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)

View File

@ -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")
}
}