-
Notifications
You must be signed in to change notification settings - Fork 5
/
limits_net.go
93 lines (73 loc) · 2.61 KB
/
limits_net.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// +build windows
package winjob
import (
"github.com/kolesnikovae/go-winjob/jobapi"
)
// WithOutgoingBandwidthLimit sets the maximum bandwidth for outgoing
// network traffic for the job, in bytes.
func WithOutgoingBandwidthLimit(b uint64) Limit {
return LimitOutgoingBandwidth.WithValue(b)
}
// WithDSCPTag sets the value to use for the Differentiated Service code
// point (DSCP) field to turn on network quality of service (QoS) for all
// outgoing network traffic generated by the processes of the job object.
// The valid range is from 0x00 through 0x3F.
func WithDSCPTag(t byte) Limit {
return LimitDSCPTag.WithValue(t)
}
var LimitOutgoingBandwidth netBandwidthLimit
var LimitDSCPTag netDSCPTagLimit
type netBandwidthLimit struct {
maxBandwidth uint64
}
func (l netBandwidthLimit) WithValue(x uint64) netBandwidthLimit {
l.maxBandwidth = x
return l
}
func (l netBandwidthLimit) LimitValue(job *JobObject) uint64 {
return job.NetRateControl.MaxBandwidth
}
func (l netBandwidthLimit) set(job *JobObject) {
job.NetRateControl.MaxBandwidth = l.maxBandwidth
f := jobapi.JOB_OBJECT_NET_RATE_CONTROL_ENABLE | jobapi.JOB_OBJECT_NET_RATE_CONTROL_MAX_BANDWIDTH
job.NetRateControl.ControlFlags |= f
}
func (l netBandwidthLimit) reset(job *JobObject) {
job.NetRateControl.ControlFlags &^= jobapi.JOB_OBJECT_NET_RATE_CONTROL_MAX_BANDWIDTH
if job.NetRateControl.ControlFlags == jobapi.JOB_OBJECT_NET_RATE_CONTROL_ENABLE {
job.NetRateControl.ControlFlags = 0
}
}
func (l netBandwidthLimit) IsSet(job *JobObject) bool {
return job.NetRateControl.ControlFlags&jobapi.JOB_OBJECT_NET_RATE_CONTROL_MAX_BANDWIDTH > 0
}
func (l netBandwidthLimit) Value(job *JobObject) interface{} {
return l.LimitValue(job)
}
type netDSCPTagLimit struct {
dscpTag byte
}
func (l netDSCPTagLimit) WithValue(t byte) netDSCPTagLimit {
l.dscpTag = t
return l
}
func (l netDSCPTagLimit) LimitValue(job *JobObject) byte {
return job.NetRateControl.DscpTag
}
func (l netDSCPTagLimit) set(job *JobObject) {
job.NetRateControl.DscpTag = l.dscpTag
f := jobapi.JOB_OBJECT_NET_RATE_CONTROL_ENABLE | jobapi.JOB_OBJECT_NET_RATE_CONTROL_DSCP_TAG
job.NetRateControl.ControlFlags |= f
}
func (l netDSCPTagLimit) reset(job *JobObject) {
job.NetRateControl.ControlFlags &^= jobapi.JOB_OBJECT_NET_RATE_CONTROL_DSCP_TAG
if job.NetRateControl.ControlFlags == jobapi.JOB_OBJECT_NET_RATE_CONTROL_ENABLE {
job.NetRateControl.ControlFlags = 0
}
}
func (l netDSCPTagLimit) IsSet(job *JobObject) bool {
return job.NetRateControl.ControlFlags&jobapi.JOB_OBJECT_NET_RATE_CONTROL_DSCP_TAG > 0
}
func (l netDSCPTagLimit) Value(job *JobObject) interface{} {
return l.LimitValue(job)
}