예제 #1
0
        private PDU WaitPDU()
        {
            PDUHeader header = null;
            PDU       pdu    = null;

            byte[] bodyBytes   = null;
            byte[] headerBytes = null;
            //--
            try { headerBytes = ReadHeaderBytes(); }
            catch (TcpIpException tcpIp_ex_1)
            {
                _Log.ErrorFormat("200010:TCP/IP Exception encountered while reading pdu header bytes: {0}", tcpIp_ex_1, tcpIp_ex_1.Message);
                if (vTraceSwitch.TraceInfo)
                {
                    Trace.WriteLine(string.Format(
                                        "200010:TCP/IP Exception encountered while reading pdu header bytes:{0};",
                                        tcpIp_ex_1.Message));
                }
                HandleException(tcpIp_ex_1); throw;
            }
            //--
            header = PDUHeader.Parse(new ByteBuffer(headerBytes), vSmppEncodingService);
            _Log.TraceFormat("PDU header: {0}", Logging.LoggingExtensions.DumpString(header, vSmppEncodingService));

            try { pdu = PDU.CreatePDU(header, vSmppEncodingService); }
            catch (InvalidPDUCommandException inv_ex)
            {
                ByteBuffer iBuffer = new ByteBuffer((int)header.CommandLength);
                iBuffer.Append(header.GetBytes(vSmppEncodingService));
                if (header.CommandLength > 16)
                {
                    try { iBuffer.Append(ReadBodyBytes((int)header.CommandLength - 16)); }
                    catch (TcpIpException tcpIp_ex_3) { HandleException(tcpIp_ex_3); }
                }
                _Log.WarnFormat("200011:Invalid PDU command type:{0};", iBuffer.DumpString());
                if (vTraceSwitch.TraceWarning)
                {
                    Trace.WriteLine(string.Format(
                                        "200011:Invalid PDU command type:{0};", iBuffer.DumpString()));
                }
                RaisePduErrorEvent(inv_ex, iBuffer.ToBytes(), header, null);
                throw;
            }
            //--
            try { bodyBytes = ReadBodyBytes((int)header.CommandLength - 16); }
            catch (TcpIpException tpcIp_ex_2)
            {
                _Log.ErrorFormat("200012:TCP/IP Exception encountered while reading pdu body bytes: {0}", tpcIp_ex_2, tpcIp_ex_2.Message);
                if (vTraceSwitch.TraceInfo)
                {
                    Trace.WriteLine(string.Format(
                                        "200012:TCP/IP Exception encountered while reading pdu body bytes:{0};",
                                        tpcIp_ex_2.Message));
                }
                HandleException(tpcIp_ex_2); throw;
            }
            //--
            try { pdu.SetBodyData(new ByteBuffer(bodyBytes)); }
            catch (PDUException pdu_ex)
            {
                ByteBuffer pBuffer = new ByteBuffer((int)header.CommandLength);
                pBuffer.Append(headerBytes);
                pBuffer.Append(bodyBytes);
                RaisePduErrorEvent(pdu_ex, pBuffer.ToBytes(), header, pdu);
                _Log.WarnFormat("200013:Malformed PDU body received:{0}", pdu_ex, pBuffer.DumpString());
                if (vTraceSwitch.TraceWarning)
                {
                    Trace.WriteLine(string.Format(
                                        "200013:Malformed PDU body received:{0} {1};", pBuffer.DumpString(), pdu_ex.Message));
                }
                throw;
            }
            return(pdu);
        }