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.54 by root, Sun Jul 1 04:08:14 2007 UTC vs.
Revision 1.65 by root, Sun Jul 29 02:24:34 2007 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (©) 2002-2003,2007 Mark Wedel & The Crossfire Development Team 5 * Copyright (©) 2002-2003,2007 Mark Wedel & The Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT is free software; you can redistribute it and/or modify it 8 * Crossfire TRT is free software: you can redistribute it and/or modify
9 * under the terms of the GNU General Public License as published by the Free 9 * it under the terms of the GNU General Public License as published by
10 * Software Foundation; either version 2 of the License, or (at your option) 10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * (at your option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, but 13 * This program is distributed in the hope that it will be useful,
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License along 18 * You should have received a copy of the GNU General Public License
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * 20 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
23 */ 22 */
24 23
25/** 24/**
47 46
48#include <loader.h> 47#include <loader.h>
49 48
50#define BG_SCRUB_RATE 4 // how often to send a face in the background 49#define BG_SCRUB_RATE 4 // how often to send a face in the background
51 50
52#define MAX_QUEUE_DEPTH 500 51#define MAX_QUEUE_DEPTH 50
53#define MAX_QUEUE_BACKLOG 3. 52#define MAX_QUEUE_BACKLOG 3.
54 53
55void 54void
56client::reset_state () 55client::reset_state ()
57{ 56{
166 while (scrub_idx < faces.size () - 1) 165 while (scrub_idx < faces.size () - 1)
167 { 166 {
168 ++scrub_idx; 167 ++scrub_idx;
169 168
170 if (!faces_sent [scrub_idx]) 169 if (!faces_sent [scrub_idx])
170 if (faceinfo *f = face_info (scrub_idx))
171 if (f->type == FT_FACE) // only scrub faces for now
171 { 172 {
172 send_face (scrub_idx); 173 send_face (scrub_idx, -120);
173 flush_fx (); 174 flush_fx ();
174 175
175 bg_scrub = 1; // send up to one face per tick, unless an image was requested 176 bg_scrub = 1; // send up to one face per tick, unless an image was requested
176 break; 177 break;
177 } 178 }
178 } 179 }
179 180
180 rate_avail = max_rate - outputbuffer_len (); 181 rate_avail = max_rate - outputbuffer_len ();
181 } 182 }
182 else 183 else
183 { 184 {
184 int ol = outputbuffer_len (); 185 int ol = outputbuffer_len ();
185 186
186 rate_avail = min (max_rate, rate_avail + max_rate); 187 rate_avail = min (max_rate + mss, rate_avail + max_rate);
188
189 int avail = rate_avail;
190
191 // if we can split images, round to next-lowest mss
192 if (fxix) avail -= avail % mss;
193
187 rate_avail -= ol; 194 rate_avail -= ol;
195 avail -= ol;
188 196
189 int avail = rate_avail; 197#if HAVE_TCP_INFO
190 198 // further restrict the available bandwidth by the excess bandwidth available
191 // if we can split images, transfer up to mss-sized packets if possible 199 avail = max (0, min (avail, (tcpi.tcpi_snd_cwnd - tcpi.tcpi_unacked + tcpi.tcpi_sacked) * mss));
192 // but never 768 bytes more. 200#endif
193 if (fxix) avail += min (768, mss - (ol % mss));
194 201
195 bg_scrub = BG_SCRUB_RATE; 202 bg_scrub = BG_SCRUB_RATE;
196 203
197 while (avail > 0) 204 while (avail > 0)
198 { 205 {
200 207
201 if (facedata *d = face_data (ix.idx, faceset)) 208 if (facedata *d = face_data (ix.idx, faceset))
202 { 209 {
203 if (fxix) 210 if (fxix)
204 { 211 {
205 // 9 bytes is enough for fx_FFFOOO, 40 leaves some room for image data 212 // estimate the packet header overhead "ix " + idx + (new)ofs
213 int pktlen = 3 + ber32::encoded_size (ix.idx) + ber32::encoded_size (ix.ofs);
206 int chunk = min (min (avail - 40, MAXSOCKBUF - 9), ix.ofs); 214 int chunk = min (avail - packet::hdrlen, MAXSOCKBUF) - pktlen;
207 215
216 // only transfer something if the amount of data transferred
217 // has a healthy relation to the header overhead
208 if (chunk <= 0) 218 if (chunk < 64)
209 break; 219 break;
210 220
221 chunk = min (chunk, (int)ix.ofs);
222
211 ix.ofs -= chunk; 223 ix.ofs -= chunk;
224
225 //fprintf (stderr, "i%dx %6d: %5d+%4d (%4d)\n", fxix, ix.idx,ix.ofs,chunk, ixface.size());//D
212 226
213 packet sl ("ix"); 227 packet sl ("ix");
214 228
215 sl << ber32 (ix.idx) 229 sl << ber32 (ix.idx)
216 << ber32 (ix.ofs) 230 << ber32 (ix.ofs)
225 } 239 }
226 } 240 }
227 else 241 else
228 ix.ofs = 0; 242 ix.ofs = 0;
229 243
230 int consumed = ol - outputbuffer_len (); 244 int consumed = outputbuffer_len () - ol;
231 245
232 avail -= consumed; 246 avail -= consumed;
233 rate_avail -= consumed; 247 rate_avail -= consumed;
234 248
235 ol = outputbuffer_len (); 249 ol = outputbuffer_len ();
236 250
237 if (!ix.ofs) 251 if (!ix.ofs)
238 { 252 {
239 ixface.pop_back (); 253 ixface.pop_back ();
254
240 if (ixface.empty ()) 255 if (ixface.empty ())
241 break; 256 break;
242 } 257 }
243 } 258 }
244 } 259 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines