MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / nw_ReliableResend

Function nw_ReliableResend

networking/networking.cpp:2530–2668  ·  view source on GitHub ↗

MTS: only used in this file? Resend any unack'd packets and send any buffered packets, heartbeats, etc.

Source from the content-addressed store, hash-verified

2528// MTS: only used in this file?
2529// Resend any unack'd packets and send any buffered packets, heartbeats, etc.
2530void nw_ReliableResend(void) {
2531 int i, j;
2532 int rcode = -1;
2533 int16_t max_len = NETBUFFERSIZE;
2534 static reliable_header rcv_buff;
2535 static SOCKADDR rcv_addr;
2536 int bytesin = 0;
2537 int addrlen = sizeof(SOCKADDR);
2538 reliable_socket *rsocket = NULL;
2539 // Go through each reliable socket that is connected and do any needed work.
2540 for (j = 0; j < MAXRELIABLESOCKETS; j++) {
2541 rsocket = &reliable_sockets[j];
2542
2543 if (serverconn == -1) {
2544 if (rsocket->status == RNF_LIMBO)
2545 if ((timer_GetTime() - rsocket->last_packet_received) > NETTIMEOUT) {
2546 mprintf(0, "Reliable (but in limbo) socket (%d) timed out in nw_WorkReliable().\n", j);
2547 memset(rsocket, 0, sizeof(reliable_socket));
2548 rsocket->status = RNF_UNUSED; // Won't work if this is an outgoing connection.
2549 }
2550 } else {
2551 if ((rsocket->status == RNF_LIMBO) && ((timer_GetTime() - first_sent_iamhere) > NETTIMEOUT)) {
2552 rsocket->status = RNF_BROKEN;
2553 mprintf(0, "Reliable socket (%d) timed out in nw_WorkReliable().\n", j);
2554 }
2555 }
2556
2557 if (rsocket->status == RNF_CONNECTED) {
2558 float retry_packet_time;
2559 if ((rsocket->mean_ping == 0) || (rsocket->mean_ping > (NETRETRYTIME * 4))) {
2560 retry_packet_time = NETRETRYTIME;
2561 } else {
2562 if (rsocket->mean_ping < MIN_NET_RETRYTIME) {
2563 retry_packet_time = (float)MIN_NET_RETRYTIME;
2564 // mprintf(0,"Using retransmission time of %f\n",retry_packet_time);
2565 } else {
2566 retry_packet_time = ((float)(float)rsocket->mean_ping * (float)1.25);
2567 // mprintf(0,"Using retransmission time of %f\n",retry_packet_time);
2568 }
2569 }
2570 // Iterate through send buffers.
2571 for (i = 0; i < MAXNETBUFFERS; i++) {
2572 if (((i == rsocket->waiting_packet_number) &&
2573 ((((timer_GetTime() - rsocket->last_sent) > R_NET_PACKET_QUEUE_TIME)) ||
2574 ((rsocket->mean_ping > 0) && (rsocket->mean_ping < R_NET_PACKET_QUEUE_TIME)) || rsocket->send_urgent)) ||
2575 ((rsocket->sbuffers[i]) && ((timer_GetTime() - rsocket->timesent[i]) >= retry_packet_time))) // Send again
2576 {
2577
2578 if (i == rsocket->waiting_packet_number) {
2579 rsocket->waiting_packet_number = -1;
2580 rsocket->last_sent = timer_GetTime();
2581 // mprintf(0,"Sending delayed packet...\n");
2582 }
2583 reliable_header send_header;
2584 // mprintf(0,"Resending reliable packet in nw_WorkReliable().\n");
2585 send_header.send_time = INTEL_FLOAT(timer_GetTime());
2586 send_header.seq = INTEL_SHORT(rsocket->ssequence[i]);
2587 memcpy(send_header.data, rsocket->sbuffers[i]->buffer, rsocket->send_len[i]);

Callers 2

nw_DoNetworkIdleFunction · 0.85
nw_DoReceiveCallbacksFunction · 0.85

Calls 1

nw_SendWithIDFunction · 0.85

Tested by

no test coverage detected