Beispiel #1
0
        void BeginReceive()
        {
            Buff buff = Buff.getOrCreate();

            buff.position(ImmutableReader.getLargestUnsplitable());
            Exception ex = null;

            try
            {
                _socket.BeginReceive(buff.getByteBuffer().array(), ImmutableReader.getLargestUnsplitable(), buff.remaining(), SocketFlags.None, EndReceive, buff);
            }
            catch (Exception e)
            {
                ex = e;
            }

            if (ex != null)
            {
                if (Debug.ENABLED)
                {
                    ThreadAssert.suspend(this);
                }

                buff.recycle();
                getClient().onError(this, ex.ToString(), true);
            }
        }
Beispiel #2
0
        void EndReceive(IAsyncResult result)
        {
            int       length = 0;
            Exception ex     = null;
            Buff      buff   = (Buff)result.AsyncState;

            try
            {
                length = _socket.EndReceive(result);
            }
            catch (Exception e)
            {
                ex = e;
            }

            if (ex != null || length == 0) // length == 0 means disconnected (!?)
            {
                if (Debug.ENABLED)
                {
                    ThreadAssert.suspend(this);
                    buff.@lock(buff.limit());
                }

                buff.recycle();
                getClient().onError(this, Strings.DISCONNECTED, true);
            }
            else
            {
                buff.position(ImmutableReader.getLargestUnsplitable());
                buff.limit(ImmutableReader.getLargestUnsplitable() + length);

                read(buff);

                buff.recycle();
                BeginReceive();
            }
        }