Exemple #1
0
        internal SocketConnection(URIResolver server, SocketRemote client, Socket socket)
            : base(server, client)
        {
            _socket = socket;

            setActor(new SocketActor(this));

            Buff buff     = Buff.getOrCreate();
            int  position = buff.position();

            startWrite(buff);
            buff.limit(buff.position());
            buff.position(position);

            if (Debug.ENABLED)
            {
                buff.@lock(buff.limit());
            }

            _socket.BeginSend(buff.getByteBuffer().array(), buff.position(), buff.remaining(), SocketFlags.None, Connected, buff);

            BeginReceive();
        }
Exemple #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();
            }
        }