ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/loop.C
(Generate patch)

Comparing deliantra/server/socket/loop.C (file contents):
Revision 1.60 by root, Thu Jul 12 19:36:58 2007 UTC vs.
Revision 1.64 by root, Sat Jul 28 00:45:05 2007 UTC

156 draw_client_map (pl); 156 draw_client_map (pl);
157 157
158 if (update_look) 158 if (update_look)
159 esrv_draw_look (pl); 159 esrv_draw_look (pl);
160 160
161 bool overload = false;
162
163#if HAVE_TCP_INFO
164 // do bandwidth checking
165 if (tcpi.tcpi_unacked + 1 > max (4, tcpi.tcpi_snd_cwnd))
166 {
167 overload = true;
168 if (next_rate_adjust <= NOW)
169 {
170 next_rate_adjust = NOW + 2;
171 max_rate = max (max_rate >> 1, int (5000 * TICK));
172 LOG (llevDebug, "tcp %s overloaded (%d + 1 > 4 | %d), rate now %d\n",
173 host, (int)tcpi.tcpi_unacked, (int)tcpi.tcpi_snd_cwnd, int (max_rate / TICK));//D
174 send_packet_printf ("drawinfo %d Due to possible network congestion, your output-rate has been reduced to %dbps.",
175 NDI_RED, int (max_rate / TICK));
176 }
177 }
178#endif
179
180 if (!overload)
181 {
161 if (ixface.empty ()) 182 if (ixface.empty ())
162 { 183 {
163 // regularly send a new face when queue is empty 184 // regularly send a new face when queue is empty
164 if (bg_scrub && !--bg_scrub && enable_bg_scrub) 185 if (bg_scrub && !--bg_scrub && enable_bg_scrub)
165 while (scrub_idx < faces.size () - 1) 186 while (scrub_idx < faces.size () - 1)
166 {
167 ++scrub_idx;
168
169 if (!faces_sent [scrub_idx])
170 { 187 {
188 ++scrub_idx;
189
190 if (!faces_sent [scrub_idx])
191 if (faceinfo *f = face_info (scrub_idx))
192 if (f->type == FT_FACE) // only scrub faces for now
193 {
171 send_face (scrub_idx); 194 send_face (scrub_idx, -120);
172 flush_fx (); 195 flush_fx ();
173 196
174 bg_scrub = 1; // send up to one face per tick, unless an image was requested 197 bg_scrub = 1; // send up to one face per tick, unless an image was requested
175 break; 198 break;
199 }
176 } 200 }
177 }
178 201
179 rate_avail = max_rate - outputbuffer_len (); 202 rate_avail = max_rate - outputbuffer_len ();
180 } 203 }
181 else if (!outq) // only send when bandwidht allows it 204 else
182 { 205 {
183 int ol = outputbuffer_len (); 206 int ol = outputbuffer_len ();
184 207
185 rate_avail = min (max_rate, rate_avail + max_rate); 208 rate_avail = min (max_rate, rate_avail + max_rate);
186 rate_avail -= ol; 209 rate_avail -= ol;
187 210
188 int avail = rate_avail; 211 int avail = rate_avail;
189 212
190 // if we can split images, transfer up to mss-sized packets if possible 213 // if we can split images, transfer up to mss-sized packets if possible
191 // but never 768 bytes more. 214 // but never 768 bytes more.
192 if (fxix) avail += min (768, mss - (ol % mss)); 215 if (fxix) avail += min (768, mss - (ol % mss));
193 216
194 bg_scrub = BG_SCRUB_RATE; 217 bg_scrub = BG_SCRUB_RATE;
195 218
196 while (avail > 0) 219 while (avail > 0)
197 {
198 ixsend &ix = ixface.back ();
199
200 if (facedata *d = face_data (ix.idx, faceset))
201 { 220 {
202 if (fxix) 221 ixsend &ix = ixface.back ();
222
223 if (facedata *d = face_data (ix.idx, faceset))
203 { 224 {
225 if (fxix)
226 {
204 // only transfer something if the amount of data transferred 227 // only transfer something if the amount of data transferred
205 // has a healthy relation to the header overhead 228 // has a healthy relation to the header overhead
206 if (avail <= 40) 229 if (avail <= 40)
207 break; 230 break;
208 231
209 // 9 bytes is enough for fx_FFFOOO 232 // 9 bytes is enough for fx_FFFOOO
210 int chunk = min (min (avail, MAXSOCKBUF - 9), (int)ix.ofs); 233 int chunk = min (min (avail, MAXSOCKBUF - 9), (int)ix.ofs);
211 234
212 if (chunk <= 0) 235 if (chunk <= 0)
213 break; 236 break;
214 237
215 ix.ofs -= chunk; 238 ix.ofs -= chunk;
216 239
217 //fprintf (stderr, "i%dx %6d: %5d+%4d (%4d)\n", fxix, ix.idx,ix.ofs,chunk, ixface.size());//D 240 //fprintf (stderr, "i%dx %6d: %5d+%4d (%4d)\n", fxix, ix.idx,ix.ofs,chunk, ixface.size());//D
218 241
219 packet sl ("ix"); 242 packet sl ("ix");
220 243
221 sl << ber32 (ix.idx) 244 sl << ber32 (ix.idx)
222 << ber32 (ix.ofs) 245 << ber32 (ix.ofs)
223 << data (d->data.data () + ix.ofs, chunk); 246 << data (d->data.data () + ix.ofs, chunk);
224 247
225 send_packet (sl); 248 send_packet (sl);
249 }
250 else
251 {
252 send_image (ix.idx);
253 ix.ofs = 0;
254 }
226 } 255 }
227 else 256 else
257 ix.ofs = 0;
258
259 int consumed = outputbuffer_len () - ol;
260
261 avail -= consumed;
262 rate_avail -= consumed;
263
264 ol = outputbuffer_len ();
265
266 if (!ix.ofs)
228 { 267 {
229 send_image (ix.idx); 268 ixface.pop_back ();
230 ix.ofs = 0; 269
270 if (ixface.empty ())
271 break;
231 } 272 }
232 } 273 }
233 else
234 ix.ofs = 0;
235
236 int consumed = outputbuffer_len () - ol;
237
238 avail -= consumed;
239 rate_avail -= consumed;
240
241 ol = outputbuffer_len ();
242
243 if (!ix.ofs)
244 {
245 ixface.pop_back ();
246
247 if (ixface.empty ())
248 break;
249 } 274 }
250 }
251 } 275 }
252} 276}
253 277

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines