csma: Reduce nested code by using early return

This commit is contained in:
Eduardo Almeida
2025-03-11 15:52:38 +00:00
parent 159f375152
commit 53aaf514ad

View File

@@ -119,28 +119,25 @@ CsmaChannel::Detach(uint32_t deviceId)
{
NS_LOG_FUNCTION(this << deviceId);
if (deviceId < m_deviceList.size())
{
if (!m_deviceList[deviceId].active)
{
NS_LOG_WARN("CsmaChannel::Detach(): Device is already detached (" << deviceId << ")");
return false;
}
m_deviceList[deviceId].active = false;
if ((m_state == TRANSMITTING) && (m_currentSrc == deviceId))
{
NS_LOG_WARN("CsmaChannel::Detach(): Device is currently transmitting (" << deviceId
<< ")");
}
return true;
}
else
if (deviceId >= m_deviceList.size())
{
return false;
}
if (!m_deviceList[deviceId].active)
{
NS_LOG_WARN("CsmaChannel::Detach(): Device is already detached (" << deviceId << ")");
return false;
}
m_deviceList[deviceId].active = false;
if ((m_state == TRANSMITTING) && (m_currentSrc == deviceId))
{
NS_LOG_WARN("CsmaChannel::Detach(): Device is currently transmitting (" << deviceId << ")");
}
return true;
}
bool