2 procedure tAggr
.ResetMark
;
6 thr
.MarkData
:=0; thr
.MarkTime
:=0; {prevent timing screwup in thread}
7 repeat thr
.mark
:=Random(255)+1 until (thr
.mark
<>pMark
);
10 procedure tAggr
.CalcRates(rxRate
:Single);
15 EnterCriticalSection(thr
.crit
);
16 if thr
.MarkTime
=0 then thr
.MarkTime
:=1;
19 writeln('RESET INITIAL');
20 txRate
:=rxRate
; thr
.Rate
:=4096;
22 end else txRate
:=thr
.MarkData
/(thr
.MarkTime
/1000);
23 if rxRate
=0 then rxRate
:=1;
24 if txRate
=0 then txRate
:=1;
25 RateFill
:=rxRate
/txRate
;
26 write('speed: ',(rxRate
/1024):8:2,'kB/s (',(RateFill
*100):3:0,'% of ',txRate
/1024:8:2,'), ');
27 if RateFill
<0.90 then begin
29 if RateFill
<0.5 then thr
.size1
:=round(thr
.size1
*0.75);
31 RateIF
:=RateIF
*0.1*RateFill
;
33 if (txRate
/thr
.Rate
)>0.7 then begin
35 thr
.Rate
:=1+txRate
*(RateIF
+1);
36 if thr
.Rate
>limRate
then thr
.Rate
:=limRate
37 else RateIF
:=RateIF
+0.1;
38 if RateIF
>limRateIF
then RateIF
:=LimRateIF
;
39 end else write('3hard');
40 ResetMark
; {TODO: do not do this}
41 if thr
.size1
<120 then thr
.size1
:=128;
42 {no ack to size inc packet, back up}
44 {but at least 1 byte increase}
45 if (thr
.size1
*SizeIF
)<1 then SizeIF
:=1/thr
.Size1
;
47 if (thr
.Size1
/thr
.Rate
)>0.11 then begin thr
.size1
:=100; thr
.rate
:=4096; end;
48 write(', if=',RateIF
:6:4);
49 write(', size=',thr
.size1
:5,'+',SizeIF
:6:4);
50 {request ack, also triggers MTU discovery}
52 thr
.size1
:=thr
.size2
-1; {???}
54 LeaveCriticalSection(thr
.crit
);
57 procedure tAggr
.OnCont(msg
:tSMsg
);
61 op
:=msg
.stream
.readbyte
;
62 assert(op
=opcode
.tccont
);
63 rmark
:=msg
.stream
.readbyte
;
64 if rmark
=thr
.mark
then begin
67 rrate
:=msg
.stream
.readword(4);
72 procedure tAggr
.OnAck(msg
:tSMsg
);
77 op
:=msg
.stream
.readbyte
;
78 assert(op
=opcode
.tceack
);
79 rmark
:=msg
.stream
.readbyte
;
80 rsize
:=msg
.stream
.readword(2);
81 if (rmark
<>thr
.mark
) then exit
;
84 {do nothing if timeout recovery or not increase}
85 if (rsize
<=thr
.size1
)or(timeout
>0) then exit
;
86 EnterCriticalSection(thr
.crit
);
87 {try to maintain frequency}
88 if (rSize
/thr
.Rate
)<0.11
89 then thr
.size1
:=rSize
{use the new size as main size}
91 {increase increase fastor}
92 SizeIF
:=SizeIF
*2; if SizeIF
>limSizeIF
then SizeIF
:=limSizeIF
;
93 assert(thr
.size2
=0); {wtf?}
94 {calc new packet size}
95 thr
.size2
:=round(thr
.Size1
*(1+SizeIF
));
96 {do nothing if they are equal}
97 if thr
.size1
=thr
.size2
then thr
.size2
:=0
98 {else writeln('Set size2: ',thr.size2,' ',thr.size1)};
99 LeaveCriticalSection(thr
.crit
);