public StackPacket GetPacketFromBuffer(bool onlySVCPacket = false)
{
if (unprocessedPacketBuffer.Count > 0)
{
lock (unprocessedPacketBuffer)
{
if (unprocessedPacketBuffer.Count > 0)
{
if (onlySVCPacket)
{
for (int i = 0; i < unprocessedPacketBuffer.Count; i++)
{
if (unprocessedPacketBuffer[i] is Virtual_Channel_RAW_Pdu
|| unprocessedPacketBuffer[i] is ErrorPdu
|| unprocessedPacketBuffer[i] is MCS_Disconnect_Provider_Ultimatum_Pdu)
{
// if the packet is ErrorPdu or MCS_Disconnect_Provider_Ultimatum_Pdu, there's some error in the connection
// should return this two types of PDU, so as to notify the error
StackPacket pdu = unprocessedPacketBuffer[i];
unprocessedPacketBuffer.RemoveAt(i);
return pdu;
}
}
}
else
{
StackPacket pdu = unprocessedPacketBuffer[0];
unprocessedPacketBuffer.RemoveAt(0);
return pdu;
}
}
}
}
return null;
}