@@ -90,18 +90,26 @@ private static PacketKind TypeToKind(PacketType type)
90
90
}
91
91
}
92
92
93
- private static long [ ] GetWithin ( Queue < PacketData > queue , TimeSpan time )
93
+ private static void GetWithin ( Queue < PacketData > queue , TimeSpan time , out DataCatergory data )
94
94
{
95
95
var now = Tools . Now ;
96
- var bandwidth = new long [ 3 ] ;
96
+ var nowThresh = now - time ;
97
+ data = new DataCatergory ( ) ;
97
98
foreach ( var pack in queue . Reverse ( ) )
98
- if ( now - pack . SendPoint <= time )
99
- bandwidth [ ( int ) pack . Kind ] += pack . Size ;
100
- else
101
- break ;
102
- for ( int i = 0 ; i < 3 ; i ++ )
103
- bandwidth [ i ] = ( long ) ( bandwidth [ i ] / time . TotalSeconds ) ;
104
- return bandwidth ;
99
+ if ( nowThresh <= pack . SendPoint )
100
+ {
101
+ switch ( pack . Kind )
102
+ {
103
+ case PacketKind . Speech : data . Speech += pack . Size ; break ;
104
+ case PacketKind . Keepalive : data . Keepalive += pack . Size ; break ;
105
+ case PacketKind . Control : data . Control += pack . Size ; break ;
106
+ default : throw Tools . UnhandledDefault ( pack . Kind ) ;
107
+ }
108
+ }
109
+ else { break ; }
110
+ data . Speech = ( long ) ( data . Speech / time . TotalSeconds ) ;
111
+ data . Keepalive = ( long ) ( data . Keepalive / time . TotalSeconds ) ;
112
+ data . Control = ( long ) ( data . Control / time . TotalSeconds ) ;
105
113
}
106
114
107
115
private static void DropOver ( Queue < PacketData > queue , TimeSpan time )
@@ -113,18 +121,18 @@ private static void DropOver(Queue<PacketData> queue, TimeSpan time)
113
121
114
122
public TsCommand GenerateStatusAnswer ( )
115
123
{
116
- long [ ] lastSecondIn ;
117
- long [ ] lastSecondOut ;
118
- long [ ] lastMinuteIn ;
119
- long [ ] lastMinuteOut ;
124
+ DataCatergory lastSecondIn ;
125
+ DataCatergory lastSecondOut ;
126
+ DataCatergory lastMinuteIn ;
127
+ DataCatergory lastMinuteOut ;
120
128
double lastPing ;
121
129
double deviationPing ;
122
130
lock ( queueLock )
123
131
{
124
- lastSecondIn = GetWithin ( inBytesTime , TimeSecond ) ;
125
- lastSecondOut = GetWithin ( outBytesTime , TimeSecond ) ;
126
- lastMinuteIn = GetWithin ( inBytesTime , TimeMinute ) ;
127
- lastMinuteOut = GetWithin ( outBytesTime , TimeMinute ) ;
132
+ GetWithin ( inBytesTime , TimeSecond , out lastSecondIn ) ;
133
+ GetWithin ( outBytesTime , TimeSecond , out lastSecondOut ) ;
134
+ GetWithin ( inBytesTime , TimeMinute , out lastMinuteIn ) ;
135
+ GetWithin ( outBytesTime , TimeMinute , out lastMinuteOut ) ;
128
136
if ( pingTimes . Count > 0 )
129
137
{
130
138
lastPing = pingTimes . Last ( ) . TotalMilliseconds ;
@@ -155,18 +163,18 @@ public TsCommand GenerateStatusAnswer()
155
163
{ "connection_server2client_packetloss_keepalive" , 1.0000f } ,
156
164
{ "connection_server2client_packetloss_control" , 0.5000f } ,
157
165
{ "connection_server2client_packetloss_total" , 0.0000f } ,
158
- { "connection_bandwidth_sent_last_second_speech" , lastSecondOut [ ( int ) PacketKind . Speech ] } ,
159
- { "connection_bandwidth_sent_last_second_keepalive" , lastSecondOut [ ( int ) PacketKind . Keepalive ] } ,
160
- { "connection_bandwidth_sent_last_second_control" , lastSecondOut [ ( int ) PacketKind . Control ] } ,
161
- { "connection_bandwidth_sent_last_minute_speech" , lastMinuteOut [ ( int ) PacketKind . Speech ] } ,
162
- { "connection_bandwidth_sent_last_minute_keepalive" , lastMinuteOut [ ( int ) PacketKind . Keepalive ] } ,
163
- { "connection_bandwidth_sent_last_minute_control" , lastMinuteOut [ ( int ) PacketKind . Control ] } ,
164
- { "connection_bandwidth_received_last_second_speech" , lastSecondIn [ ( int ) PacketKind . Speech ] } ,
165
- { "connection_bandwidth_received_last_second_keepalive" , lastSecondIn [ ( int ) PacketKind . Keepalive ] } ,
166
- { "connection_bandwidth_received_last_second_control" , lastSecondIn [ ( int ) PacketKind . Control ] } ,
167
- { "connection_bandwidth_received_last_minute_speech" , lastMinuteIn [ ( int ) PacketKind . Speech ] } ,
168
- { "connection_bandwidth_received_last_minute_keepalive" , lastMinuteIn [ ( int ) PacketKind . Keepalive ] } ,
169
- { "connection_bandwidth_received_last_minute_control" , lastMinuteIn [ ( int ) PacketKind . Control ] } ,
166
+ { "connection_bandwidth_sent_last_second_speech" , lastSecondOut . Speech } ,
167
+ { "connection_bandwidth_sent_last_second_keepalive" , lastSecondOut . Keepalive } ,
168
+ { "connection_bandwidth_sent_last_second_control" , lastSecondOut . Control } ,
169
+ { "connection_bandwidth_sent_last_minute_speech" , lastMinuteOut . Speech } ,
170
+ { "connection_bandwidth_sent_last_minute_keepalive" , lastMinuteOut . Keepalive } ,
171
+ { "connection_bandwidth_sent_last_minute_control" , lastMinuteOut . Control } ,
172
+ { "connection_bandwidth_received_last_second_speech" , lastSecondIn . Speech } ,
173
+ { "connection_bandwidth_received_last_second_keepalive" , lastSecondIn . Keepalive } ,
174
+ { "connection_bandwidth_received_last_second_control" , lastSecondIn . Control } ,
175
+ { "connection_bandwidth_received_last_minute_speech" , lastMinuteIn . Speech } ,
176
+ { "connection_bandwidth_received_last_minute_keepalive" , lastMinuteIn . Keepalive } ,
177
+ { "connection_bandwidth_received_last_minute_control" , lastMinuteIn . Control } ,
170
178
} ;
171
179
}
172
180
@@ -214,5 +222,12 @@ private readonly struct PacketData
214
222
215
223
public PacketData ( ushort size , DateTime sendPoint , PacketKind kind ) { Size = size ; SendPoint = sendPoint ; Kind = kind ; }
216
224
}
225
+
226
+ struct DataCatergory
227
+ {
228
+ public long Speech { get ; set ; }
229
+ public long Keepalive { get ; set ; }
230
+ public long Control { get ; set ; }
231
+ }
217
232
}
218
233
}
0 commit comments