Use array<> for net_udp buffers

This commit is contained in:
Kp 2015-02-28 19:36:01 +00:00
parent e440bc1b17
commit 1580a274f2
2 changed files with 10 additions and 9 deletions

View file

@ -132,22 +132,22 @@ struct UDP_mdata_info : prohibit_void_ptr<UDP_mdata_info>
{ {
ubyte type; ubyte type;
ubyte Player_num; ubyte Player_num;
uint16_t mbuf_size;
uint32_t pkt_num; uint32_t pkt_num;
ushort mbuf_size; array<uint8_t, UPID_MDATA_BUF_SIZE> mbuf;
ubyte mbuf[UPID_MDATA_BUF_SIZE];
}; };
// structure to store MDATA to maybe resend // structure to store MDATA to maybe resend
struct UDP_mdata_store : prohibit_void_ptr<UDP_mdata_store> struct UDP_mdata_store : prohibit_void_ptr<UDP_mdata_store>
{ {
sbyte used;
fix64 pkt_initial_timestamp; // initial timestamp to see if packet is outdated fix64 pkt_initial_timestamp; // initial timestamp to see if packet is outdated
fix64 pkt_timestamp[MAX_PLAYERS]; // Packet timestamp fix64 pkt_timestamp[MAX_PLAYERS]; // Packet timestamp
uint32_t pkt_num[MAX_PLAYERS]; // Packet number uint32_t pkt_num[MAX_PLAYERS]; // Packet number
sbyte used;
ubyte Player_num; // sender of this packet ubyte Player_num; // sender of this packet
uint16_t data_size;
ubyte player_ack[MAX_PLAYERS]; // 0 if player has not ACK'd this packet, 1 if ACK'd or not connected ubyte player_ack[MAX_PLAYERS]; // 0 if player has not ACK'd this packet, 1 if ACK'd or not connected
ubyte data[UPID_MDATA_BUF_SIZE]; // extra data of a packet - contains all multibuf data we don't want to loose array<uint8_t, UPID_MDATA_BUF_SIZE> data; // extra data of a packet - contains all multibuf data we don't want to loose
ushort data_size;
}; };
// structure to keep track of MDATA packets we already got, which we expect from another player and the pkt_num for the next packet we want to send to another player // structure to keep track of MDATA packets we already got, which we expect from another player and the pkt_num for the next packet we want to send to another player

View file

@ -4662,7 +4662,7 @@ void net_udp_noloss_process_queue(fix64 time)
buf[len] = UPID_MDATA_PNEEDACK; len++; buf[len] = UPID_MDATA_PNEEDACK; len++;
buf[len] = UDP_mdata_queue[queuec].Player_num; len++; buf[len] = UDP_mdata_queue[queuec].Player_num; len++;
PUT_INTEL_INT(buf + len, UDP_mdata_queue[queuec].pkt_num[plc]); len += 4; PUT_INTEL_INT(buf + len, UDP_mdata_queue[queuec].pkt_num[plc]); len += 4;
memcpy(&buf[len], UDP_mdata_queue[queuec].data, sizeof(char)*UDP_mdata_queue[queuec].data_size); memcpy(&buf[len], UDP_mdata_queue[queuec].data.data(), sizeof(char)*UDP_mdata_queue[queuec].data_size);
len += UDP_mdata_queue[queuec].data_size; len += UDP_mdata_queue[queuec].data_size;
dxx_sendto(Netgame.players[plc].protocol.udp.addr, UDP_Socket[0], buf, len, 0); dxx_sendto(Netgame.players[plc].protocol.udp.addr, UDP_Socket[0], buf, len, 0);
total_len += len; total_len += len;
@ -4782,7 +4782,8 @@ void net_udp_send_mdata(int needack, fix64 time)
len++; len++;
buf[len] = Player_num; len++; buf[len] = Player_num; len++;
if (needack) len += 4; // we place the pkt_num later since it changes per player if (needack) len += 4; // we place the pkt_num later since it changes per player
memcpy(&buf[len], UDP_MData.mbuf, sizeof(char)*UDP_MData.mbuf_size); len += UDP_MData.mbuf_size; memcpy(&buf[len], UDP_MData.mbuf.data(), sizeof(char)*UDP_MData.mbuf_size);
len += UDP_MData.mbuf_size;
if (multi_i_am_master()) if (multi_i_am_master())
{ {
@ -4806,13 +4807,13 @@ void net_udp_send_mdata(int needack, fix64 time)
} }
if (needack) if (needack)
net_udp_noloss_add_queue_pkt(time, UDP_MData.mbuf, UDP_MData.mbuf_size, Player_num, pack); net_udp_noloss_add_queue_pkt(time, UDP_MData.mbuf.data(), UDP_MData.mbuf_size, Player_num, pack);
// Clear UDP_MData except pkt_num. That one must not be deleted so we can clearly keep track of important packets. // Clear UDP_MData except pkt_num. That one must not be deleted so we can clearly keep track of important packets.
UDP_MData.type = 0; UDP_MData.type = 0;
UDP_MData.Player_num = 0; UDP_MData.Player_num = 0;
UDP_MData.mbuf_size = 0; UDP_MData.mbuf_size = 0;
memset(&UDP_MData.mbuf, 0, sizeof(ubyte)*UPID_MDATA_BUF_SIZE); UDP_MData.mbuf = {};
} }
void net_udp_process_mdata(uint8_t *data, uint_fast32_t data_len, const _sockaddr &sender_addr, int needack) void net_udp_process_mdata(uint8_t *data, uint_fast32_t data_len, const _sockaddr &sender_addr, int needack)