Exemplo n.º 1
0
        void QueueSend(WriteBufferRef bufferRef,
                       IPEndPoint remoteEndPoint,
                       Action <Udp, Exception> completion)
        {
            Contract.Requires(remoteEndPoint != null);
            Contract.Requires(bufferRef != null);

            try
            {
                SendRequest request = Recycler.Take();
                Debug.Assert(request != null);
                request.Prepare(bufferRef,
                                (sendRequest, exception) => completion?.Invoke(this, exception));

                NativeMethods.UdpSend(
                    request.InternalHandle,
                    this.InternalHandle,
                    remoteEndPoint,
                    ref request.Bufs,
                    ref request.Size);
            }
            catch (Exception exception)
            {
                Log.Error($"{this.HandleType} faulted.", exception);
                throw;
            }
        }
Exemplo n.º 2
0
        protected WriteBufferRequest(uv_req_type requestType)
            : base(requestType)
        {
            Contract.Requires(
                requestType == uv_req_type.UV_WRITE ||
                requestType == uv_req_type.UV_UDP_SEND);

            this.handle    = new RequestContext(requestType, 0, this);
            this.bufferRef = null;
        }
Exemplo n.º 3
0
        public void QueueWriteStream(byte[] array, int offset, int count,
                                     Action <StreamHandle, Exception> completion)
        {
            Contract.Requires(array != null && array.Length > 0);
            Contract.Requires(offset >= 0 && count > 0);
            Contract.Requires((offset + count) <= array.Length);

            IByteBuffer buffer    = Unpooled.WrappedBuffer(array, offset, count);
            var         bufferRef = new WriteBufferRef(buffer);

            this.pipeline.QueueWrite(bufferRef, completion);
        }
Exemplo n.º 4
0
        public void QueueSend(byte[] array, int offset, int count,
                              IPEndPoint remoteEndPoint,
                              Action <Udp, Exception> completion = null)
        {
            Contract.Requires(array != null);
            Contract.Requires(remoteEndPoint != null);

            IByteBuffer buffer    = Unpooled.WrappedBuffer(array, offset, count);
            var         bufferRef = new WriteBufferRef(buffer);

            this.QueueSend(bufferRef, remoteEndPoint, completion);
        }
Exemplo n.º 5
0
        public void QueueWriteStream(WritableBuffer writableBuffer,
                                     Action <StreamHandle, Exception> completion)
        {
            Contract.Requires(completion != null);

            IByteBuffer buffer = writableBuffer.GetBuffer();

            if (buffer == null || !buffer.IsReadable())
            {
                return;
            }

            var bufferRef = new WriteBufferRef(buffer);

            this.pipeline.QueueWrite(bufferRef, completion);
        }
Exemplo n.º 6
0
        public void QueueSend(WritableBuffer writableBuffer,
                              IPEndPoint remoteEndPoint,
                              Action <Udp, Exception> completion = null)
        {
            Contract.Requires(remoteEndPoint != null);

            IByteBuffer buffer = writableBuffer.GetBuffer();

            if (buffer == null || !buffer.IsReadable())
            {
                return;
            }

            var bufferRef = new WriteBufferRef(buffer);

            this.QueueSend(bufferRef, remoteEndPoint, completion);
        }
Exemplo n.º 7
0
        internal void QueueWrite(WriteBufferRef bufferRef, Action <StreamHandle, Exception> completion)
        {
            Contract.Requires(bufferRef != null);

            try
            {
                WriteRequest request = Recycler.Take();
                request.Prepare(bufferRef,
                                (writeRequest, exception) => completion?.Invoke(this.streamHandle, exception));

                this.streamHandle.WriteStream(request);
            }
            catch (Exception exception)
            {
                Log.Error($"{nameof(Pipeline)} {this.streamHandle.HandleType} faulted.", exception);
                throw;
            }
        }