Skip to content

Commit

Permalink
[core] Changed CUDT::m_pListener to CSharedObjectPtr.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Aug 5, 2024
1 parent 055935c commit 8cd78a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
24 changes: 9 additions & 15 deletions srtcore/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,8 +1129,6 @@ srt::CRcvQueue::CRcvQueue()
, m_iIPversion()
, m_szPayloadSize()
, m_bClosing(false)
, m_LSLock()
, m_pListener(NULL)
, m_pRendezvousQueue(NULL)
, m_vNewEntry()
, m_IDLock()
Expand Down Expand Up @@ -1404,11 +1402,13 @@ srt::EConnectStatus srt::CRcvQueue::worker_ProcessConnectionRequest(CUnit* unit,
int listener_ret = SRT_REJ_UNKNOWN;
bool have_listener = false;
{
ScopedLock cg(m_LSLock);
if (m_pListener)
SharedLock shl(m_pListener);
CUDT* pListener = m_pListener.getPtrNoLock();

if (pListener)
{
LOGC(cnlog.Debug, log << "PASSING request from: " << addr.str() << " to listener:" << m_pListener->socketID());
listener_ret = m_pListener->processConnectRequest(addr, unit->m_Packet);
LOGC(cnlog.Debug, log << "PASSING request from: " << addr.str() << " to listener:" << pListener->socketID());
listener_ret = pListener->processConnectRequest(addr, unit->m_Packet);

// This function does return a code, but it's hard to say as to whether
// anything can be done about it. In case when it's stated possible, the
Expand Down Expand Up @@ -1690,21 +1690,15 @@ int srt::CRcvQueue::recvfrom(int32_t id, CPacket& w_packet)

int srt::CRcvQueue::setListener(CUDT* u)
{
ScopedLock lslock(m_LSLock);

if (NULL != m_pListener)
return -1;
if (!m_pListener.set(u))
return -1;

m_pListener = u;
return 0;
}

void srt::CRcvQueue::removeListener(const CUDT* u)
{
ScopedLock lslock(m_LSLock);

if (u == m_pListener)
m_pListener = NULL;
m_pListener.clearIf(u);
}

void srt::CRcvQueue::registerConnector(const SRTSOCKET& id,
Expand Down
5 changes: 2 additions & 3 deletions srtcore/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,8 @@ class CRcvQueue
void storePktClone(int32_t id, const CPacket& pkt);

private:
sync::Mutex m_LSLock;
CUDT* m_pListener; // pointer to the (unique, if any) listening UDT entity
CRendezvousQueue* m_pRendezvousQueue; // The list of sockets in rendezvous mode
sync::CSharedObjectPtr<CUDT> m_pListener; // pointer to the (unique, if any) listening UDT entity
CRendezvousQueue* m_pRendezvousQueue; // The list of sockets in rendezvous mode

std::vector<CUDT*> m_vNewEntry; // newly added entries, to be inserted
sync::Mutex m_IDLock;
Expand Down

0 comments on commit 8cd78a5

Please sign in to comment.