8
8
// threshold for how many packet to throttle at most
9
9
#define KEEP_AT_MOST 1000
10
10
11
- static Ihandle * inboundCheckbox , * outboundCheckbox , * chanceInput , * frameInput ;
11
+ static Ihandle * inboundCheckbox , * outboundCheckbox , * chanceInput , * frameInput , * dropThrottledCheckbox ;
12
12
13
13
static volatile short throttleEnabled = 0 ,
14
14
throttleInbound = 1 , throttleOutbound = 1 ,
15
15
chance = 1000 , // [0-10000]
16
16
// time frame in ms, when a throttle start the packets within the time
17
17
// will be queued and sent altogether when time is over
18
- throttleFrame = TIME_DEFAULT ;
18
+ throttleFrame = TIME_DEFAULT ,
19
+ dropThrottled = 0 ;
19
20
20
21
static PacketNode throttleHeadNode = {0 }, throttleTailNode = {0 };
21
22
static PacketNode * bufHead = & throttleHeadNode , * bufTail = & throttleTailNode ;
@@ -30,6 +31,7 @@ static INLINE_FUNCTION short isBufEmpty() {
30
31
31
32
static Ihandle * throttleSetupUI () {
32
33
Ihandle * throttleControlsBox = IupHbox (
34
+ dropThrottledCheckbox = IupToggle ("Drop Throttled" , NULL ),
33
35
IupLabel ("Timeframe(ms):" ),
34
36
frameInput = IupText (NULL ),
35
37
inboundCheckbox = IupToggle ("Inbound" , NULL ),
@@ -47,6 +49,9 @@ static Ihandle *throttleSetupUI() {
47
49
IupSetAttribute (inboundCheckbox , SYNCED_VALUE , (char * )& throttleInbound );
48
50
IupSetCallback (outboundCheckbox , "ACTION" , (Icallback )uiSyncToggle );
49
51
IupSetAttribute (outboundCheckbox , SYNCED_VALUE , (char * )& throttleOutbound );
52
+ IupSetCallback (dropThrottledCheckbox , "ACTION" , (Icallback )uiSyncToggle );
53
+ IupSetAttribute (dropThrottledCheckbox , SYNCED_VALUE , (char * )& dropThrottled );
54
+
50
55
// sync throttle packet number
51
56
IupSetAttribute (frameInput , "VISIBLECOLUMNS" , "3" );
52
57
IupSetAttribute (frameInput , "VALUE" , STR (TIME_DEFAULT ));
@@ -91,6 +96,16 @@ static void clearBufPackets(PacketNode *tail) {
91
96
throttleStartTick = 0 ;
92
97
}
93
98
99
+ static void dropBufPackets () {
100
+ LOG ("Throttled end, drop all %d packets. Buffer at max: %s" , bufSize , bufSize == KEEP_AT_MOST ? "YES" : "NO" );
101
+ while (!isBufEmpty ()) {
102
+ freeNode (popNode (bufTail -> prev ));
103
+ -- bufSize ;
104
+ }
105
+ throttleStartTick = 0 ;
106
+ }
107
+
108
+
94
109
static void throttleCloseDown (PacketNode * head , PacketNode * tail ) {
95
110
UNREFERENCED_PARAMETER (tail );
96
111
UNREFERENCED_PARAMETER (head );
@@ -127,7 +142,12 @@ static short throttleProcess(PacketNode *head, PacketNode *tail) {
127
142
128
143
// send all when throttled enough, including in current step
129
144
if (bufSize >= KEEP_AT_MOST || (currentTick - throttleStartTick > (unsigned int )throttleFrame )) {
130
- clearBufPackets (tail );
145
+ // drop throttled if dropThrottled is toggled
146
+ if (dropThrottled ) {
147
+ dropBufPackets ();
148
+ } else {
149
+ clearBufPackets (tail );
150
+ }
131
151
}
132
152
}
133
153
}
0 commit comments