-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_options.go
47 lines (39 loc) · 1.17 KB
/
send_options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
package coap
import "time"
type SendOptions struct {
MaxRetransmit int `json:"MaxRetransmit"`
ActTimeout time.Duration `json:"ActTimeout"`
RandomFactor float64 `json:"RandomFactor"`
BlockSize int `json:"BlockSize"`
NStart int `json:"NStart"`
}
func (s *Server) NewOptions() *SendOptions {
return &SendOptions{
MaxRetransmit: 3,
ActTimeout: time.Second * 5,
RandomFactor: 1.5,
BlockSize: s.config.BlockDefaultSize,
NStart: s.config.NStart,
}
}
func (so *SendOptions) WithRetry(count int, timeout time.Duration, randomFactor float64) *SendOptions {
so.MaxRetransmit = count
so.ActTimeout = timeout
so.RandomFactor = randomFactor
return so
}
func (so *SendOptions) WithBlockSize(bs int) *SendOptions {
so.BlockSize = bs
return so
}
func (so *SendOptions) WithNStart(ns int) *SendOptions {
so.NStart = ns
return so
}
func (so *SendOptions) NoRetry() *SendOptions {
so.MaxRetransmit = -1
return so
}