Network part requires SharedBuffers to be pass as value
authorLoic Blot <loic.blot@unix-experience.fr>
Sun, 3 Sep 2017 17:01:53 +0000 (19:01 +0200)
committerLoic Blot <loic.blot@unix-experience.fr>
Sun, 3 Sep 2017 17:01:53 +0000 (19:01 +0200)
This can trigger unreproductible crashes due to concurrency problem on SharedBuffers

This fixes #6354

src/network/connection.cpp
src/network/connection.h
src/network/connectionthreads.cpp
src/network/connectionthreads.h

index 01f1a7e6329163db31035c88cdcc08cdc0ff83c4..b2e44390143e01cc0d1e542987383dc66ac74a7e 100644 (file)
@@ -55,7 +55,7 @@ std::mutex log_message_mutex;
 
 #define PING_TIMEOUT 5.0
 
-BufferedPacket makePacket(Address &address, const SharedBuffer<u8> &data,
+BufferedPacket makePacket(Address &address, SharedBuffer<u8> data,
                u32 protocol_id, u16 sender_peer_id, u8 channel)
 {
        u32 packet_size = data.getSize() + BASE_HEADER_SIZE;
@@ -125,7 +125,7 @@ void makeSplitPacket(const SharedBuffer<u8> &data, u32 chunksize_max, u16 seqnum
        }
 }
 
-void makeAutoSplitPacket(const SharedBuffer<u8> &data, u32 chunksize_max,
+void makeAutoSplitPacket(SharedBuffer<u8> data, u32 chunksize_max,
                u16 &split_seqnum, std::list<SharedBuffer<u8>> *list)
 {
        u32 original_header_size = 1;
@@ -139,9 +139,7 @@ void makeAutoSplitPacket(const SharedBuffer<u8> &data, u32 chunksize_max,
        list->push_back(makeOriginalPacket(data));
 }
 
-SharedBuffer<u8> makeReliablePacket(
-               const SharedBuffer<u8> &data,
-               u16 seqnum)
+SharedBuffer<u8> makeReliablePacket(SharedBuffer<u8> data, u16 seqnum)
 {
        u32 header_size = 3;
        u32 packet_size = data.getSize() + header_size;
index c54161cc9267552edb16cf3c665c0b601c6259a9..e1bb613f084d4c5c07cca5546f1fcc9911830db8 100644 (file)
@@ -102,16 +102,16 @@ struct BufferedPacket
 };
 
 // This adds the base headers to the data and makes a packet out of it
-BufferedPacket makePacket(Address &address, const SharedBuffer<u8> &data,
+BufferedPacket makePacket(Address &address, SharedBuffer<u8> data,
                u32 protocol_id, u16 sender_peer_id, u8 channel);
 
 // Depending on size, make a TYPE_ORIGINAL or TYPE_SPLIT packet
 // Increments split_seqnum if a split packet is made
-void makeAutoSplitPacket(const SharedBuffer<u8> &data, u32 chunksize_max,
+void makeAutoSplitPacket(SharedBuffer<u8> data, u32 chunksize_max,
                u16 &split_seqnum, std::list<SharedBuffer<u8>> *list);
 
 // Add the TYPE_RELIABLE header to the data
-SharedBuffer<u8> makeReliablePacket(const SharedBuffer<u8> &data, u16 seqnum);
+SharedBuffer<u8> makeReliablePacket(SharedBuffer<u8> data, u16 seqnum);
 
 struct IncomingSplitPacket
 {
index 63c1855c5036d8b04160ddb9e0bc846edbf4957e..ec09e9d3e506c70bd93fda0e209afb8c26bea31f 100644 (file)
@@ -330,7 +330,7 @@ void ConnectionSendThread::sendAsPacketReliable(BufferedPacket &p, Channel *chan
 }
 
 bool ConnectionSendThread::rawSendAsPacket(u16 peer_id, u8 channelnum,
-       const SharedBuffer<u8> &data, bool reliable)
+       SharedBuffer<u8> data, bool reliable)
 {
        PeerHelper peer = m_connection->getPeerNoEx(peer_id);
        if (!peer) {
index c2314f87fe9b4a82ba7cd456e31b536e50bd3cab..906866468ce1151e9b9b0b01b02859b741420141 100644 (file)
@@ -52,7 +52,7 @@ public:
 private:
        void runTimeouts(float dtime);
        void rawSend(const BufferedPacket &packet);
-       bool rawSendAsPacket(u16 peer_id, u8 channelnum, const SharedBuffer<u8> &data,
+       bool rawSendAsPacket(u16 peer_id, u8 channelnum, SharedBuffer<u8> data,
                        bool reliable);
 
        void processReliableCommand(ConnectionCommand &c);