github.com/lmb/consul@v1.4.1/lib/eof.go (about)

     1  package lib
     2  
     3  import (
     4  	"io"
     5  	"strings"
     6  
     7  	"github.com/hashicorp/yamux"
     8  )
     9  
    10  var yamuxStreamClosed = yamux.ErrStreamClosed.Error()
    11  var yamuxSessionShutdown = yamux.ErrSessionShutdown.Error()
    12  
    13  // IsErrEOF returns true if we get an EOF error from the socket itself, or
    14  // an EOF equivalent error from yamux.
    15  func IsErrEOF(err error) bool {
    16  	if err == io.EOF {
    17  		return true
    18  	}
    19  
    20  	errStr := err.Error()
    21  	if strings.Contains(errStr, yamuxStreamClosed) ||
    22  		strings.Contains(errStr, yamuxSessionShutdown) {
    23  		return true
    24  	}
    25  
    26  	return false
    27  }