2 procedure tAggr
.CalcRates(rxRate
:Single);
8 EnterCriticalSection(thr
.crit
);
10 if thr
.MarkTime
=0 then thr
.MarkTime
:=1;
13 writeln('RESET INITIAL');
14 thr
.Mark1
:=random(255)+1; thr
.MarkData
:=0; thr
.MarkTime
:=0; txRate
:=rxRate
; thr
.Rate
:=4096;
15 end else txRate
:=thr
.MarkData
/(thr
.MarkTime
/1000);
16 if rxRate
=0 then rxRate
:=1;
17 if txRate
=0 then txRate
:=1;
18 RateFill
:=rxRate
/txRate
;
19 write('speed: ',(rxRate
/1024):8:2,'kB/s (',(RateFill
*100):3:0,'% of ',txRate
/1024:8:2,'), ');
20 if RateFill
<0.90 then begin
22 if RateFill
<0.5 then thr
.size1
:=round(thr
.size1
*0.75);
24 RateIF
:=RateIF
*0.1*RateFill
;
26 if (txRate
/thr
.Rate
)>0.7 then begin
28 thr
.Rate
:=1+txRate
*(RateIF
+1);
29 if thr
.Rate
>limRate
then thr
.Rate
:=limRate
30 else RateIF
:=RateIF
+0.1;
31 if RateIF
>limRateIF
then RateIF
:=LimRateIF
;
32 end else write('3hard');
33 repeat thr
.mark1
:=Random(255)+1 until (thr
.mark1
<>pMark
);
36 if thr
.size1
<120 then thr
.size1
:=128;
37 {no ack to size inc packet, back up}
39 {but at least 1 byte increase}
40 if (thr
.size1
*SizeIF
)<1 then SizeIF
:=1/thr
.Size1
;
42 if (thr
.Size1
/thr
.Rate
)>0.11 then begin thr
.size1
:=100; thr
.rate
:=4096; end;
43 write(', if=',RateIF
:6:4);
44 write(', size=',thr
.size1
:5,'+',SizeIF
:6:4);
45 {request ack, also triggers MTU discovery}
47 thr
.size1
:=thr
.size2
-1;
50 LeaveCriticalSection(thr
.crit
);
53 procedure tAggr
.OnCont(msg
:tSMsg
);
57 op
:=msg
.stream
.readbyte
;
58 assert(op
=opcode
.tccont
);
59 rmark
:=msg
.stream
.readbyte
;
60 if rmark
=thr
.mark1
then begin
63 rrate
:=msg
.stream
.readword(4);
68 procedure tAggr
.OnAck(msg
:tSMsg
);
73 op
:=msg
.stream
.readbyte
;
74 assert(op
=opcode
.tceack
);
75 rmark
:=msg
.stream
.readbyte
;
76 rsize
:=msg
.stream
.readword(2);
77 if (rmark
<>thr
.mark2
)and(rmark
<>thr
.mark1
) then exit
;
80 {do nothing if timeout recovery or not increase}
81 if (rsize
<=thr
.size1
)or(timeout
>0) then exit
;
82 EnterCriticalSection(thr
.crit
);
83 {try to maintain frequency}
84 if (rSize
/thr
.Rate
)<0.11
85 then thr
.size1
:=rSize
{use the new size as main size}
87 {increase increase fastor}
88 SizeIF
:=SizeIF
*2; if SizeIF
>limSizeIF
then SizeIF
:=limSizeIF
;
90 {calc new packet size}
91 thr
.size2
:=round(thr
.Size1
*(1+SizeIF
));
92 {do nothing if they are equal}
93 if thr
.size1
=thr
.size2
then thr
.size2
:=0
94 {else writeln('Set size2: ',thr.size2,' ',thr.size1)};
96 LeaveCriticalSection(thr
.crit
);