Ejemplo n.º 1
0
        void Run()
        {
            byte[] data = new byte[0x1000];
            int    i    = 0;
            int    read;

            while (true)
            {
                try { read = stream.Read(data, i, 0x1000); }
                catch (Exception e) { Log.Error(e.Message); break; }

                if (read == 0)
                {
                    break;
                }

                var packet = new byte[read];
                Array.ConstrainedCopy(data, 0, packet, 0, read);
                i = packets.Queue(packet, this, events);
            }

            cancel.Cancel();

            if (client.Connected)
            {
                events.ClientDisconnected(this, this);
                client.Close();
            }
        }
Ejemplo n.º 2
0
        void Run()
        {
            byte[] data = new byte[0x1000];
            int    i    = 0;
            int    read;

            while (true)
            {
                try
                {
                    read = stream.Read(data, i, 0x1000);
                }
                catch (System.IO.IOException ioe)
                {
                    uint err_code = (uint)ioe.HResult;

                    // if it was thrown due closed stream, it's okay
                    // otherwise, we need to log this exception
                    if (err_code != READ_BLOCKED_CODE)
                    {
                        Log.Error(ioe.Message);
                    }

                    break;
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                    break;
                }

                if (read == 0)
                {
                    break;
                }

                var packet = new byte[read];
                Array.ConstrainedCopy(data, 0, packet, 0, read);
                i = packets.Queue(packet, this, events);
            }

            cancel.Cancel();

            if (client.Connected)
            {
                events.ClientDisconnected(this, this);
                client.Close();
            }
        }