func (a *Conn) readLoop() {
	var (
		carrier net.Conn
		r       *bufio.Reader
		seqno   SeqNo
		err     error
		v       []byte
	)
	defer func() {
		close(a.rch)
		a.cascade.Close()
		a.linker.Kill()
		if carrier != nil {
			carrier.Close()
		}
		if a.scrb != nil {
			a.scrb()
		}
	}()
	// Loop
	for {
		// Check for kill signal
		select {
		case <-a.kch:
			return
		default:
		}
		// Read from connection
		v, err = a.read(r)
		if err == nil {
			a.rch <- v
			continue
		}
		// Link
		if carrier != nil {
			carrier.Close()
			r = nil
		}
		if carrier, r, seqno, err = a.linker.Link(err); err != nil {
			// Permanently cannot reconnect
			return
		}
		a.setKillCarrier(carrier)
		w := &ConnWriter{conn: a, carrier: carrier}
		a.cascade.Transition(w)
		a.rch <- &ErrStitch{SeqNo: seqno, Writer: w}
	}
}
// The dialer endpoint of a connection must be able to detect connection outage in order to redial.
// Canonically, communication errors are detected during Read operations. (This cannot always be done reliably on write.)
// Thus, the dialer connection must spawn a dedicate a read loop, in case the user logic does not use Read.
The dialer endpoint of a connection must be able to detect connection outage in order to redial.
Canonically, communication errors are detected during Read operations. (This cannot always be done reliably on write.)
Thus, the dialer connection must spawn a dedicate a read loop, in case the user logic does not use Read.
// The dialer endpoint of a connection must be able to detect connection outage in order to redial . // Canonically communication errors are detected during Read operations . ( This cannot always be done reliably on write . ) // Thus the dialer connection must spawn a dedicate a read loop in case the user logic does not use Read .
func (a *Conn) readLoop() {
	var (
		carrier net.Conn
		r       *bufio.Reader
		seqno   SeqNo
		err     error
		v       []byte
	)
	defer func() {
		close(a.rch)
		a.cascade.Close()
		a.linker.Kill()
		if carrier != nil {
			carrier.Close()
		}
		if a.scrb != nil {
			a.scrb()
		}
	}()
	for {
		select {
		case <-a.kch:
			return
		default:
		}
		v, err = a.read(r)
		if err == nil {
			a.rch <- v
			continue
		}
		if carrier != nil {
			carrier.Close()
			r = nil
		}
		if carrier, r, seqno, err = a.linker.Link(err); err != nil {
			return
		}
		a.setKillCarrier(carrier)
		w := &ConnWriter{conn: a, carrier: carrier}
		a.cascade.Transition(w)
		a.rch <- &ErrStitch{SeqNo: seqno, Writer: w}
	}
}
func ( a * Conn ) readLoop ( ) { var ( carrier net . Conn r * bufio . Reader seqno SeqNo err error v [ ] byte ) defer func ( ) { close ( a . rch ) a . cascade . Close ( ) a . linker . Kill ( ) if carrier != nil { carrier . Close ( ) } if a . scrb != nil { a . scrb ( ) } } ( ) for { select { case <- a . kch : return default : } v , err = a . read ( r ) if err == nil { a . rch <- v continue } if carrier != nil { carrier . Close ( ) r = nil } if carrier , r , seqno , err = a . linker . Link ( err ) ; err != nil { return } a . setKillCarrier ( carrier ) w := & ConnWriter { conn : a , carrier : carrier } a . cascade . Transition ( w ) a . rch <- & ErrStitch { SeqNo : seqno , Writer : w } } }
The dialer endpoint of a connection must be able to detect connection outage in order to redial.
The dialer endpoint of a connection must be able to detect connection outage in order to redial .
// Loop // Check for kill signal // Read from connection // Link // Permanently cannot reconnect