コード例 #1
0
        // No array gathering support so one by one
        private void SendOne(org.objectfabric.Queue buffs)
        {
            org.objectfabric.CLRBuff buff = (org.objectfabric.CLRBuff)buffs.poll();

            if (buff == null)
            {
                WriteComplete();
            }
            else
            {
                try
                {
                    ArraySegment <byte> buffer = new ArraySegment <byte>(buff.array(), buff.position(), buff.limit() - buff.position());
                    Task task = _socket.SendAsync(buffer, WebSocketMessageType.Binary, false, CancellationToken.None);

                    task.ContinueWith(_ =>
                    {
                        Recycle(buff);
                        SendOne(buffs);
                    });
                }
                catch (Exception ex)
                {
                    Recycle(buff);
                    OnError(ex);
                }
            }
        }
コード例 #2
0
ファイル: Connection.cs プロジェクト: stoneroses/objectfabric
        async void Receive()
        {
            org.objectfabric.CLRBuff buff = (org.objectfabric.CLRBuff)org.objectfabric.CLRBuff.getOrCreate();
            buff.position(org.objectfabric.Buff.getLargestUnsplitable());

            try
            {
                int length = await ReceiveAsync(new ArraySegment <byte>(buff.array(), buff.position(), buff.remaining()));

                if (length > 0 && resumeRead())
                {
                    buff.limit(buff.position() + length);
                    read(buff);
                    suspendRead();
                }

                Receive();
            }
            catch (Exception ex)
            {
                Location.onError(this, ex.Message, true);
            }
            finally
            {
                if (org.objectfabric.Debug.ENABLED)
                {
                    buff.@lock(buff.limit());
                }

                buff.recycle();
            }
        }