예제 #1
0
        public byte [] GetDestination2Transmit(out uint streamLength, out bool isMsg)
        {
            try
            {
                byte[] data;
#if false
                if (Queue.Synchronized(m_destinationTxQueue).Count > 0)
                {
                    data = (byte[])Queue.Synchronized(m_destinationTxQueue).Dequeue();
                    LogUtility.LogUtility.LogFile("Queue is not empty", LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                    streamLength = (uint)data.Length;
                    isMsg        = true;
                    m_IsMsgBeingTransmitted2Destination = true;
                    LogUtility.LogUtility.LogFile("Leaving GetDestination2Transmit", LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                    return(data);
                }
#else
                data = null;
                EnterDestinationMsgTxQueue();
                LinkedListNode <byte[]> lln = m_destinationTxQueue.First;
                if (lln != null)
                {
                    data = lln.Value;
                    m_destinationTxQueue.RemoveFirst();
                }
                LeaveDestinationMsgTxQueue();
                if (data != null)
                {
                    LogUtility.LogUtility.LogFile("Queue is not empty", LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                    streamLength = (uint)data.Length;
                    isMsg        = true;
                    m_IsMsgBeingTransmitted2Destination = true;
                    LogUtility.LogUtility.LogFile("Leaving GetDestination2Transmit", LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                    return(data);
                }
#endif
                LogUtility.LogUtility.LogFile("Queue is empty", LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                EnterDestinationStreamCriticalArea();
                if (m_destinationStream.Length == 0)
                {
                    streamLength = 0;
                    isMsg        = false;
                    LogUtility.LogUtility.LogFile("Stream is empty", LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                    LogUtility.LogUtility.LogFile("Leaving GetClient2Transmit", LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                    LeaveDestinationStreamCriticalArea();
                    return(null);
                }
                LogUtility.LogUtility.LogFile("Stream is not empty", LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                streamLength = (uint)m_destinationStream.Length;
                isMsg        = false;
                m_IsMsgBeingTransmitted2Destination = false;
                byte[] bytes = m_destinationStream.GetBytes();
                LogUtility.LogUtility.LogFile("Leaving GetDestination2Transmit " + Convert.ToString(m_destinationStream.Length), LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                LeaveDestinationStreamCriticalArea();
                return(bytes);
            }
            catch (Exception exc)
            {
                LogUtility.LogUtility.LogFile(Convert.ToString(m_Id) + " EXCEPTION " + exc.Message + " " + exc.StackTrace, LogUtility.LogLevels.LEVEL_LOG_HIGH);
                streamLength = 0;
                isMsg        = false;
                return(null);
            }
        }
예제 #2
0
        public byte [] GetClient2Transmit(out uint streamLength, out bool isMsg)
        {
            LogUtility.LogUtility.LogFile("Entering GetClient2Transmit", LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
            try
            {
                byte [] data;
#if false
                if (Queue.Synchronized(m_clientTxQueue).Count > 0)
                {
                    data = (byte[])Queue.Synchronized(m_clientTxQueue).Dequeue();
                    LogUtility.LogUtility.LogFile("Queue is not empty", LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                    streamLength = (uint)data.Length;
                    isMsg        = true;
                    m_IsMsgBeingTransmitted2Client = true;
                    LogUtility.LogUtility.LogFile("Leaving GetClient2Transmit", LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                    return(data);
                }
#else
                data = null;
                bool isSecondPass = false;
second_pass:
                EnterClientMsgTxQueue();
                LinkedListNode <byte[]> lln = m_clientTxQueue.First;
                if (lln != null)
                {
                    data = lln.Value;
                    m_clientTxQueue.RemoveFirst();
                }
                LeaveClientMsgTxQueue();
                if (data != null)
                {
                    if (!isSecondPass)
                    {
                        uint DataSize;
                        byte DummyFlags;
                        byte MsgKind;
                        int  Offset;
                        PackMsg.PackMsg.DecodeMsg(data, out DataSize, out DummyFlags, out MsgKind, out Offset);
                        if (MsgKind == (byte)PackMsg.PackMsg.MsgKind_e.PACK_DATA_MSG_KIND)
                        {
                            byte [] msg = new byte[DataSize];
                            CopyBytesFromOffset(data, Offset, msg, (int)DataSize);
                            isSecondPass = true;
                            LogUtility.LogUtility.LogFile("Reprocess " + Convert.ToString(DataSize) + " of data", ModuleLogLevel);
                            if (ProcessDownStreamData(msg, true))
                            {
                                LogUtility.LogUtility.LogFile("Data message has been intercepted on tx!!!", ModuleLogLevel);
                                msg = null;
                                goto second_pass;
                            }
                            msg = null;
                            //isSecondPass = true;
                        }
                    }
                    LogUtility.LogUtility.LogFile("Queue is not empty", LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                    streamLength = (uint)data.Length;
                    isMsg        = true;
                    m_IsMsgBeingTransmitted2Client = true;
                    LogUtility.LogUtility.LogFile("Leaving GetClient2Transmit", LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                    return(data);
                }
#endif
                LogUtility.LogUtility.LogFile("Queue is empty", LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                EnterClientStreamCriticalArea();
                if (m_clientStream.Length == 0)
                {
                    streamLength = 0;
                    isMsg        = false;
                    LogUtility.LogUtility.LogFile("Stream is empty", LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                    LogUtility.LogUtility.LogFile("Leaving GetClient2Transmit", LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                    LeaveClientStreamCriticalArea();
                    return(null);
                }
                LogUtility.LogUtility.LogFile("Stream is not empty", LogUtility.LogLevels.LEVEL_LOG_MEDIUM);

                isMsg = false;
                m_IsMsgBeingTransmitted2Client = false;
#if true
                streamLength = (uint)m_clientStream.Length;
                byte [] bytes = m_clientStream.GetBytes();
#else
                byte[] bytes = clientStream.GetBytesLimited(4096);
                streamLength = (uint)bytes.Length;
#endif
                LogUtility.LogUtility.LogFile("Leaving GetClient2Transmit " + Convert.ToString(m_clientStream.Length), LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                LeaveClientStreamCriticalArea();
                return(bytes);
            }
            catch (Exception exc)
            {
                LogUtility.LogUtility.LogFile(Convert.ToString(m_Id) + " EXCEPTION " + exc.Message + " " + exc.StackTrace, LogUtility.LogLevels.LEVEL_LOG_HIGH);
                streamLength = 0;
                isMsg        = false;
                LogUtility.LogUtility.LogFile("Leaving GetClient2Transmit", LogUtility.LogLevels.LEVEL_LOG_MEDIUM);
                return(null);
            }
        }