Example #1
0
        private void _initiator_OnDataReceived(object sender, MessageEventArgs args)
        {
            try
            {
                if (logger.IsDebugEnabled)
                {
                    logger.Debug("_initiator_OnDataReceived: [" + System.Text.Encoding.ASCII.GetString(args.Message) + "]");
                }

                //compressedStream.Write(args.Message, 0, Convert.ToInt32(args.MessageLen));

                _pendingBytes = appendBytes(args.Message, 0, Convert.ToInt32(args.MessageLen));

                byte [] buff = new byte[BUFFER_SIZE];

                if (zlib.IsNeedingInput)
                {
                    zlib.SetInput(_inputBuffer, 0, _pendingBytes);
                    _pendingBytes = 0;
                }

                int blidos = zlib.Inflate(buff, 0, BUFFER_SIZE);

                if (blidos > 0)
                {
                    UncompressedPacket pkt = new UncompressedPacket();
                    pkt.Buffer    = new byte[blidos];
                    pkt.BufferLen = blidos;

                    System.Array.Copy(buff, pkt.Buffer, blidos);

                    //compressedStream.Flush();
                    //compressedStream.Position = 0;

                    qUnpack.Enqueue(pkt);

                    if (logger.IsDebugEnabled)
                    {
                        logger.Debug("leu : [" + System.Text.Encoding.ASCII.GetString(buff, 0, blidos) + "]");
                    }

                    if (DateTime.UtcNow.Ticks - lastLogSEC > TimeSpan.TicksPerSecond)
                    {
                        lastLogSEC = DateTime.UtcNow.Ticks;
                        logger.Info("Pacotes descompactados na fila: " + qUnpack.Count);
                    }
                }
                //zlib.BeginRead(unzipped, 0, unzipped.Length, new AsyncCallback(OnReceiveDecompressed), null);
            }
            catch (Exception ex)
            {
                logger.Error("_initiator_OnDataReceived: " + ex.Message, ex);
            }
        }
Example #2
0
        private void OnReceiveDecompressed(IAsyncResult ar)
        {
            try
            {
                if (!_bKeepRunning)
                {
                    return;
                }

                int blidos = 0; // zlib.EndRead(ar);

                if (blidos <= 0)
                {
                    logger.Error("OnReceiveDecompressed Blidos <= 0");
                    return;
                }

                UncompressedPacket pkt = new UncompressedPacket();
                pkt.Buffer    = unzipped;
                pkt.BufferLen = blidos;

                qUnpack.Enqueue(pkt);

                unzipped = new byte[BUFFER_SIZE];


                if (DateTime.UtcNow.Ticks - lastLogSEC > TimeSpan.TicksPerSecond)
                {
                    lastLogSEC = DateTime.UtcNow.Ticks;
                    logger.Info("OnReceiveDecompressed: pacotes na fila: " + qUnpack.Count);
                }

                //Start listening to receive more data from the deflater
                //decompressedStream.BeginRead(unzipped, 0, unzipped.Length, new AsyncCallback(OnReceiveDecompressed), null);
            }
            catch (ObjectDisposedException)
            {
                logger.Error("OnReceiveDecompressed(): deflator finalizado!");
            }
            catch (Exception ex)
            {
                logger.Error("OnReceiveDecompressed(): " + ex.Message, ex);
            }
        }