mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
fix panic on single digit throttles values
This commit is contained in:
parent
8ff3fb9b89
commit
d372fa1fa4
1 changed files with 7 additions and 1 deletions
|
@ -178,7 +178,8 @@ func New(ops Options) (c *Client, err error) {
|
||||||
|
|
||||||
c.conn = make([]*comm.Comm, 16)
|
c.conn = make([]*comm.Comm, 16)
|
||||||
|
|
||||||
if len(c.Options.ThrottleUpload) > 0 && c.Options.IsSender {
|
// initialize throttler
|
||||||
|
if len(c.Options.ThrottleUpload) > 1 && c.Options.IsSender {
|
||||||
upload := c.Options.ThrottleUpload[:len(c.Options.ThrottleUpload)-1]
|
upload := c.Options.ThrottleUpload[:len(c.Options.ThrottleUpload)-1]
|
||||||
uploadLimit, err := strconv.ParseInt(upload, 10, 64)
|
uploadLimit, err := strconv.ParseInt(upload, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -193,6 +194,11 @@ func New(ops Options) (c *Client, err error) {
|
||||||
uploadLimit = uploadLimit*1024*1024
|
uploadLimit = uploadLimit*1024*1024
|
||||||
case "k", "K":
|
case "k", "K":
|
||||||
uploadLimit = uploadLimit*1024
|
uploadLimit = uploadLimit*1024
|
||||||
|
default:
|
||||||
|
uploadLimit, err = strconv.ParseInt(c.Options.ThrottleUpload, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
panic("Could not parse given Upload Limit")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Somehow 4* is neccessary
|
// Somehow 4* is neccessary
|
||||||
rt = rate.Every(time.Second / (4*time.Duration(uploadLimit)))
|
rt = rate.Every(time.Second / (4*time.Duration(uploadLimit)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue