trpc.group/trpc-go/trpc-go@v1.0.3/pool/connpool/checker_other.go (about)

     1  //
     2  //
     3  // Tencent is pleased to support the open source community by making tRPC available.
     4  //
     5  // Copyright (C) 2023 THL A29 Limited, a Tencent company.
     6  // All rights reserved.
     7  //
     8  // If you have downloaded a copy of the tRPC source code from Tencent,
     9  // please note that tRPC source code is licensed under the  Apache 2.0 License,
    10  // A copy of the Apache 2.0 License is included in this file.
    11  //
    12  //
    13  
    14  //go:build !aix && !darwin && !dragonfly && !freebsd && !netbsd && !openbsd && !solaris && !linux
    15  // +build !aix,!darwin,!dragonfly,!freebsd,!netbsd,!openbsd,!solaris,!linux
    16  
    17  package connpool
    18  
    19  import (
    20  	"errors"
    21  	"net"
    22  	"time"
    23  )
    24  
    25  func checkConnErr(conn net.Conn, buf []byte) error {
    26  	conn.SetReadDeadline(time.Now().Add(time.Millisecond))
    27  	n, err := conn.Read(buf)
    28  	// Idle connections should not read data, it is an unexpected read error.
    29  	if err == nil || n > 0 {
    30  		return errors.New("unexpected read from socket")
    31  	}
    32  	// The idle connection is normal and returns timeout.
    33  	if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
    34  		conn.SetReadDeadline(time.Time{})
    35  		return nil
    36  	}
    37  	// other connection errors, including connection closed.
    38  	return err
    39  }
    40  
    41  func checkConnErrUnblock(conn net.Conn, buf []byte) error {
    42  	// Currently non-blocking mode is not supported.
    43  	return nil
    44  }