Skip to content

Commit

Permalink
更新TCP读写超时最小值命名;不再使用范围比较;
Browse files Browse the repository at this point in the history
  • Loading branch information
Changeden committed Aug 24, 2021
1 parent 1af33a4 commit 6c3e38b
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions remoting/getty/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

const (
TCP_READ_WRITE_TIMEOUT_MIN_VALUE = time.Second * 1
TCPReadWriteTimeoutMinValue = time.Second * 1
)

type (
Expand Down Expand Up @@ -166,12 +166,11 @@ func (c *GettySessionParam) CheckValidity() error {
return perrors.WithMessagef(err, "time.ParseDuration(KeepAlivePeriod{%#v})", c.KeepAlivePeriod)
}

var tcpTimeoutMinVal = TCP_READ_WRITE_TIMEOUT_MIN_VALUE
if c.tcpReadTimeout, err = parseTimeDurationByRange(c.TcpReadTimeout, &tcpTimeoutMinVal, nil); err != nil {
if c.tcpReadTimeout, err = parseTcpTimeoutDuration(c.TcpReadTimeout); err != nil {
return perrors.WithMessagef(err, "time.ParseDuration(TcpReadTimeout{%#v})", c.TcpReadTimeout)
}

if c.tcpWriteTimeout, err = parseTimeDurationByRange(c.TcpWriteTimeout, &tcpTimeoutMinVal, nil); err != nil {
if c.tcpWriteTimeout, err = parseTcpTimeoutDuration(c.TcpWriteTimeout); err != nil {
return perrors.WithMessagef(err, "time.ParseDuration(TcpWriteTimeout{%#v})", c.TcpWriteTimeout)
}

Expand All @@ -182,19 +181,13 @@ func (c *GettySessionParam) CheckValidity() error {
return nil
}

func parseTimeDurationByRange(timeStr string, min *time.Duration, max *time.Duration) (time.Duration, error) {
func parseTcpTimeoutDuration(timeStr string) (time.Duration, error) {
result, err := time.ParseDuration(timeStr)
if err != nil {
return *min, err
return 0, err
}
if min != nil && max != nil && *min > *max { // swap
min, max = max, min
}
if min != nil && result < *min {
result = *min
}
if max != nil && result > *max {
result = *max
if result < TCPReadWriteTimeoutMinValue {
return TCPReadWriteTimeoutMinValue, nil
}
return result, nil
}
Expand Down

0 comments on commit 6c3e38b

Please sign in to comment.