32 static DWORD multi_msg_sequence = 1;
37 : addr(a), netid(id), sequence(0), pps(0), bps(0), max_qsize(0),
38 status(OK), hist_indx(0), send_size(0), recv_size(0),
41 ZeroMemory(hist_time,
sizeof(hist_time));
42 ZeroMemory(hist_size,
sizeof(hist_size));
62 if (max_qsize > 0 && msg->
Length() + send_size > max_qsize) {
69 if (msg->
Length() <= (int) chunk_size) {
75 send_size += msg->
Length();
83 list = &multi_send_list;
85 DWORD nparts = msg->
Length() / chunk_size;
86 DWORD extra = msg->
Length() % chunk_size;
88 if (extra > 0) nparts++;
91 multi_part_buffer.
msgid = multi_msg_sequence++;
92 multi_part_buffer.
nparts = nparts;
94 DWORD header_size = (DWORD) (&multi_part_buffer.
payload) -
95 (DWORD) (&multi_part_buffer);
97 const BYTE* p = msg->
Data();
99 for (DWORD i = 0; i < nparts; i++) {
100 multi_part_buffer.
partno = i;
102 DWORD part_size = chunk_size;
104 if (i == nparts-1 && extra > 0)
107 CopyMemory(multi_part_buffer.
payload, p, part_size);
111 header_size + part_size,
116 send_size += part->
Length();
132 if (recv_list.
size() > 0) {
134 recv_size -= msg->
Length();
148 if ((send_list.
size() || multi_send_list.
size()) && OKtoSend()) {
151 int xmit_size = send_size;
152 int nmsg = send_list.
size();
154 bool reliable =
false;
155 bool is_multi =
false;
160 if (xmit_size > limit) {
164 if (send_list.
size() > 0) {
168 if (multi_send_list.
size()) {
176 for (
int i = 0; i < send_list.
size(); i++) {
177 NetMsg* msg = send_list[i];
179 if (xmit_size + msg->
Length() < limit) {
180 xmit_size += msg->
Length();
191 list = &multi_send_list;
195 for (
int i = 0; i < multi_send_list.
size(); i++) {
196 NetMsg* msg = multi_send_list[i];
198 if (xmit_size + msg->
Length() < limit) {
199 xmit_size += msg->
Length();
209 if (xmit_size > 0 && nmsg > 0) {
210 BYTE* buffer =
new(__FILE__,__LINE__) BYTE[xmit_size];
215 CopyMemory(p, multi_msg->
Data(), multi_msg->
Length());
216 p[1] = multi_msg->
Length();
222 while (nmsg-- && p < buffer + xmit_size) {
237 Text user_data((
const char*) buffer, xmit_size);
246 send_size -= xmit_size;
252 if (hist_indx >= HIST_SIZE)
255 g =
new(__FILE__,__LINE__)
NetGram(addr, user_data, retries);
277 if (max_qsize > 0 && recv_size + g->
Size() > max_qsize) {
289 while (p < g->Data() + g->
Size()) {
290 BYTE block_type = p[0];
291 BYTE block_size = p[1];
293 if (!block_type || !block_size)
296 NetMsg* msg =
new(__FILE__,__LINE__)
NetMsg(netid, p, block_size);
331 NetPeer::OKtoSend()
const
334 DWORD hist_total = 0;
335 DWORD hist_count = 0;
337 DWORD hist_oldest = now;
338 DWORD hist_newest = 0;
340 for (
int i = 0; i < HIST_SIZE; i++) {
341 if (hist_size[i] > 0) {
342 hist_total += hist_size[i];
346 if (hist_time[i] > 0) {
347 if (hist_time[i] < hist_oldest)
348 hist_oldest = hist_time[i];
350 if (hist_time[i] > hist_newest)
351 hist_newest = hist_time[i];
355 if (now - hist_newest < (DWORD) pps)
358 DWORD delta = now - hist_oldest;
359 DWORD avg_bps = hist_total / delta;
361 if (bps > 0 && avg_bps > (DWORD) bps)
381 const int MAX_SIMULTANEOUS_MULTI_SEQUENCES = 8;
384 ZeroMemory(assy,
sizeof(assy));
386 DWORD header_size = (DWORD) (&multi_part_buffer.
payload) -
387 (DWORD) (&multi_part_buffer);
390 for (
int i = 0; i < multi_recv_list.
size(); i++) {
391 NetMsg* msg = multi_recv_list[i];
394 for (
int n = 0; n < MAX_SIMULTANEOUS_MULTI_SEQUENCES; n++) {
408 for (
int n = 0; n < MAX_SIMULTANEOUS_MULTI_SEQUENCES; n++) {
413 BYTE* buffer =
new BYTE[a->
nbytes];
419 netid = iter->
NetID();
425 CopyMemory(p, m->
payload, m->
len - header_size);
426 p += m->
len - header_size;