for the purpose of performance handle incoming packets in their own threads (NOTE: this commit is *experimental* and may burn your house down and kick your dog, and it most certainly has a memory leak I'm working on somewhere);

pull/51/head
Bryan Biedenkapp 2 years ago
parent c6c1c72f79
commit e348b15d7f

@ -32,6 +32,7 @@ using namespace network;
/// <param name="debug"></param>
RawFrameQueue::RawFrameQueue(udp::Socket* socket, bool debug) :
m_socket(socket),
m_flushMutex(),
m_buffers(),
m_debug(debug)
{
@ -145,25 +146,32 @@ void RawFrameQueue::enqueueMessage(const uint8_t* message, uint32_t length, sock
/// <returns></returns>
bool RawFrameQueue::flushQueue()
{
if (m_buffers.empty()) {
return false;
}
bool ret = true;
m_flushMutex.lock();
{
if (m_buffers.empty()) {
m_flushMutex.unlock();
return false;
}
// bryanb: this is the same as above -- but for some assinine reason prevents
// weirdness
if (m_buffers.size() == 0U) {
return false;
}
// bryanb: this is the same as above -- but for some assinine reason prevents
// weirdness
if (m_buffers.size() == 0U) {
m_flushMutex.unlock();
return false;
}
// LogDebug(LOG_NET, "m_buffers len = %u", m_buffers.size());
// LogDebug(LOG_NET, "m_buffers len = %u", m_buffers.size());
bool ret = true;
if (!m_socket->write(m_buffers)) {
LogError(LOG_NET, "Failed writing data to the network");
ret = false;
}
ret = true;
if (!m_socket->write(m_buffers)) {
LogError(LOG_NET, "Failed writing data to the network");
ret = false;
}
deleteBuffers();
deleteBuffers();
}
m_flushMutex.unlock();
return ret;
}

@ -17,6 +17,8 @@
#include "common/network/udp/Socket.h"
#include "common/Utils.h"
#include <mutex>
namespace network
{
// ---------------------------------------------------------------------------
@ -57,6 +59,7 @@ namespace network
uint32_t m_addrLen;
udp::Socket* m_socket;
std::mutex m_flushMutex;
udp::BufferVector m_buffers;
bool m_debug;

File diff suppressed because it is too large Load Diff

@ -24,6 +24,7 @@
#include <string>
#include <cstdint>
#include <unordered_map>
#include <mutex>
// ---------------------------------------------------------------------------
// Class Prototypes
@ -155,6 +156,25 @@ namespace network
pthread_t thread;
};
// ---------------------------------------------------------------------------
// Structure Declaration
// Represents the data required for a network packet handler thread.
// ---------------------------------------------------------------------------
struct NetPacketRequest {
FNENetwork* network;
uint32_t peerId;
sockaddr_storage address;
uint32_t addrLen;
frame::RTPHeader rtpHeader;
frame::RTPFNEHeader fneHeader;
int length = 0U;
uint8_t *buffer;
pthread_t thread;
};
// ---------------------------------------------------------------------------
// Class Declaration
// Implements the core FNE networking logic.
@ -189,6 +209,8 @@ namespace network
/// <summary>Process a data frames from the network.</summary>
void processNetwork();
/// <summary>Entry point to process a given network packet.</summary>
static void* threadedNetworkRx(void* arg);
/// <summary>Updates the timer by the passed number of milliseconds.</summary>
void clock(uint32_t ms) override;
@ -227,6 +249,7 @@ namespace network
NET_CONN_STATUS m_status;
std::mutex m_peerMutex;
typedef std::pair<const uint32_t, network::FNEPeerConnection*> PeerMapPair;
std::unordered_map<uint32_t, FNEPeerConnection*> m_peers;
typedef std::pair<const uint32_t, lookups::AffiliationLookup*> PeerAffiliationMapPair;

Loading…
Cancel
Save

Powered by TurnKey Linux.