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.55 by root, Sun Jul 1 05:00:20 2007 UTC vs.
Revision 1.63 by root, Sat Jul 28 00:15:03 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines