From 1580a274f2e1e0cc9208c06ec70ab2f9982d1243 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 28 Feb 2015 19:36:01 +0000 Subject: [PATCH] Use array<> for net_udp buffers --- common/main/net_udp.h | 10 +++++----- similar/main/net_udp.cpp | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/common/main/net_udp.h b/common/main/net_udp.h index 2c93223fa..ad16d869a 100644 --- a/common/main/net_udp.h +++ b/common/main/net_udp.h @@ -132,22 +132,22 @@ struct UDP_mdata_info : prohibit_void_ptr { ubyte type; ubyte Player_num; + uint16_t mbuf_size; uint32_t pkt_num; - ushort mbuf_size; - ubyte mbuf[UPID_MDATA_BUF_SIZE]; + array mbuf; }; // structure to store MDATA to maybe resend struct UDP_mdata_store : prohibit_void_ptr { - sbyte used; fix64 pkt_initial_timestamp; // initial timestamp to see if packet is outdated fix64 pkt_timestamp[MAX_PLAYERS]; // Packet timestamp uint32_t pkt_num[MAX_PLAYERS]; // Packet number + sbyte used; 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 data[UPID_MDATA_BUF_SIZE]; // extra data of a packet - contains all multibuf data we don't want to loose - ushort data_size; + array data; // extra data of a packet - contains all multibuf data we don't want to loose }; // 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 diff --git a/similar/main/net_udp.cpp b/similar/main/net_udp.cpp index d742db4e6..4fc1b1c1e 100644 --- a/similar/main/net_udp.cpp +++ b/similar/main/net_udp.cpp @@ -4662,7 +4662,7 @@ void net_udp_noloss_process_queue(fix64 time) buf[len] = UPID_MDATA_PNEEDACK; len++; buf[len] = UDP_mdata_queue[queuec].Player_num; len++; 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; dxx_sendto(Netgame.players[plc].protocol.udp.addr, UDP_Socket[0], buf, len, 0); total_len += len; @@ -4782,7 +4782,8 @@ void net_udp_send_mdata(int needack, fix64 time) len++; buf[len] = Player_num; len++; 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()) { @@ -4806,13 +4807,13 @@ void net_udp_send_mdata(int needack, fix64 time) } 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. UDP_MData.type = 0; UDP_MData.Player_num = 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)