Beispiel #1
0
        public void WriteFrame(OutboundFrame frame)
        {
            var ms  = new MemoryStream();
            var nbw = new NetworkBinaryWriter(ms);

            frame.WriteTo(nbw);
            m_socket.Client.Poll(m_writeableStateTimeoutMicroSeconds, SelectMode.SelectWrite);
            Write(ms.GetBufferSegment());
        }
Beispiel #2
0
        public void WriteFrame(OutboundFrame frame)
        {
            var ms  = new MemoryStream();
            var nbw = new NetworkBinaryWriter(ms);

            frame.WriteTo(nbw);
            m_socket.Client.Poll(m_writeableStateTimeout, SelectMode.SelectWrite);
            Write(ms.ToArray());
        }
Beispiel #3
0
        public Task WriteFrame(OutboundFrame frame)
        {
            using (var ms = new MemoryStream())
            {
                var nbw = new NetworkBinaryWriter(ms);
                frame.WriteTo(nbw);

                return(WriteFrameBuffer(ms.ToArray()));
            }
        }
        public void WriteFrame(OutboundFrame frame, bool flush = true)
        {
            int bufferSize = frame.GetMinimumBufferSize();

            using (IMemoryOwner <byte> memory = MemoryPool <byte> .Shared.Rent(bufferSize))
            {
                Memory <byte> slice = memory.Memory.Slice(0, bufferSize);
                frame.WriteTo(slice);
                _socket.Client.Poll(_writeableStateTimeoutMicroSeconds, SelectMode.SelectWrite);
                if (MemoryMarshal.TryGetArray(slice.Slice(0, frame.ByteCount), out ArraySegment <byte> segment))
                {
                    Write(segment, flush);
                    return;
                }

                throw new InvalidOperationException("Unable to get array segment from memory.");
            }
        }
Beispiel #5
0
        public async Task WriteFrame(OutboundFrame frame)
        {
            await semaphoreSlim.WaitAsync();

            try
            {
                using (var ms = new PooledMemoryStream())
                {
                    var nbw = new NetworkBinaryWriter(ms);
                    frame.WriteTo(nbw);

                    var bufferSegment = ms.ToUnsafeArraySegment();
                    await m_netStream.WriteAsync(bufferSegment.Array, bufferSegment.Offset, bufferSegment.Count);
                }
            }
            finally
            {
                semaphoreSlim.Release();
            }
        }
 public void WriteFrame(OutboundFrame frame)
 {
     _frameChannel.Writer.TryWrite(frame);
 }