(b []byte)
| 91 | } |
| 92 | |
| 93 | func (this *ClientConn) Read(b []byte) (n int, err error) { |
| 94 | if this.isDebugging { |
| 95 | this.lastReadAt = fasttime.Now().Unix() |
| 96 | |
| 97 | defer func() { |
| 98 | if err != nil { |
| 99 | this.lastErr = fmt.Errorf("read error: %w", err) |
| 100 | } else { |
| 101 | this.lastErr = nil |
| 102 | } |
| 103 | }() |
| 104 | } |
| 105 | |
| 106 | // 环路直接读取 |
| 107 | if this.isLO { |
| 108 | n, err = this.rawConn.Read(b) |
| 109 | if n > 0 { |
| 110 | atomic.AddUint64(&teaconst.InTrafficBytes, uint64(n)) |
| 111 | } |
| 112 | return |
| 113 | } |
| 114 | |
| 115 | // 设置读超时时间 |
| 116 | if this.isHTTP && !this.isPersistent && !this.isShortReading && this.autoReadTimeout { |
| 117 | this.setHTTPReadTimeout() |
| 118 | } |
| 119 | |
| 120 | // 开始读取 |
| 121 | n, err = this.rawConn.Read(b) |
| 122 | if n > 0 { |
| 123 | atomic.AddUint64(&teaconst.InTrafficBytes, uint64(n)) |
| 124 | this.hasRead = true |
| 125 | } |
| 126 | |
| 127 | // 检测是否为超时错误 |
| 128 | var isTimeout = err != nil && os.IsTimeout(err) |
| 129 | var isHandshakeError = isTimeout && !this.hasRead |
| 130 | |
| 131 | if err != nil { |
| 132 | _ = this.SetLinger(nodeconfigs.DefaultTCPLinger) |
| 133 | } |
| 134 | |
| 135 | // 忽略白名单和局域网 |
| 136 | if !this.isPersistent && this.isHTTP && !this.isInAllowList && !utils.IsLocalIP(this.RawIP()) { |
| 137 | // SYN Flood检测 |
| 138 | if this.serverId == 0 || !this.hasResetSYNFlood { |
| 139 | var synFloodConfig = sharedNodeConfig.SYNFloodConfig() |
| 140 | if synFloodConfig != nil && synFloodConfig.IsOn { |
| 141 | if isHandshakeError { |
| 142 | this.increaseSYNFlood(synFloodConfig) |
| 143 | } else if err == nil && !this.hasResetSYNFlood { |
| 144 | this.hasResetSYNFlood = true |
| 145 | this.resetSYNFlood() |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 |
nothing calls this directly
no test coverage detected