Exemplo n.º 1
0
        public unsafe StreamHandle CreatePendingType()
        {
            Validate();

            StreamHandle handle = null;
            int          count  = PendingCount();

            if (count > 0)
            {
                IntPtr         loopHandle = ((uv_stream_t *)InternalHandle)->loop;
                var            loop       = HandleContext.GetTarget <LoopContext>(loopHandle);
                uv_handle_type handleType = NativeMethods.PipePendingType(InternalHandle);

                switch (handleType)
                {
                case uv_handle_type.UV_TCP:
                    handle = new Tcp(loop);
                    break;

                case uv_handle_type.UV_NAMED_PIPE:
                    handle = new Pipe(loop);
                    break;

                default:
                    throw ThrowHelper.GetInvalidOperationException_uv_handle_type_not_supported_or_IPC_over_Pipe_is_disabled(handleType);
                }

                NativeMethods.StreamAccept(InternalHandle, handle.InternalHandle);
                handle.ReadStart();
            }

            return(handle);
        }
Exemplo n.º 2
0
        private static void OnConnectionCallback(IntPtr handle, int status)
        {
            var server = HandleContext.GetTarget <ServerStream>(handle);

            if (server is null)
            {
                return;
            }

            StreamHandle client = null;
            Exception    error  = null;

            try
            {
                if ((uint)status > SharedConstants.TooBigOrNegative) // < 0
                {
                    error = NativeMethods.CreateError((uv_err_code)status);
                }
                else
                {
                    client = server.NewStream();
                }

                server._connectionHandler(client, error);
            }
            catch
            {
                client?.Dispose();
                throw;
            }
        }
Exemplo n.º 3
0
        internal Pipeline(StreamHandle streamHandle, PooledByteBufferAllocator allocator)
        {
            Debug.Assert(streamHandle is object);
            Debug.Assert(allocator is object);

            _streamHandle = streamHandle;
            _allocator    = allocator;
            _receiveBufferSizeEstimate = new ReceiveBufferSizeEstimate();
            _pendingRead = new PendingRead();
        }
Exemplo n.º 4
0
        public void QueueWriteStream(byte[] array, StreamHandle sendHandle,
                                     Action <StreamHandle, Exception> completion)
        {
            if (array is null)
            {
                return;
            }

            QueueWriteStream(array, 0, array.Length, sendHandle, completion);
        }
Exemplo n.º 5
0
        internal void QueueWrite(IByteBuffer bufferRef, StreamHandle sendHandle, Action <StreamHandle, Exception> completion)
        {
            Debug.Assert(bufferRef is object && sendHandle is object);

            WriteRequest request = Loop.WriteRequestPool.Take();

            try
            {
                request.Prepare(bufferRef,
                                (writeRequest, exception) => completion?.Invoke(_streamHandle, exception));

                _streamHandle.WriteStream(request, sendHandle);
            }
            catch (Exception exception)
            {
                Log.Pipeline_Handle_faulted(_streamHandle.HandleType, exception);
                request.Release();
                throw;
            }
        }
Exemplo n.º 6
0
        internal unsafe void WriteStream(WriteRequest request, StreamHandle sendHandle)
        {
            Debug.Assert(request is object);
            Debug.Assert(sendHandle is object);

            Validate();
            try
            {
                NativeMethods.WriteStream(
                    request.InternalHandle,
                    InternalHandle,
                    request.Bufs,
                    ref request.Size,
                    sendHandle.InternalHandle);
            }
            catch (Exception exception)
            {
                Log.Failed_to_write_data(HandleType, request, exception);
                throw;
            }
        }
Exemplo n.º 7
0
        public void QueueWriteStream(byte[] array, int offset, int count,
                                     StreamHandle sendHandle,
                                     Action <StreamHandle, Exception> completion)
        {
            if (array is null || 0u >= (uint)array.Length)
            {
                return;
            }
            if ((uint)count > SharedConstants.TooBigOrNegative)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count);
            }
            if ((uint)(offset + count) > (uint)array.Length)
            {
                ThrowHelper.ThrowArgumentException_InvalidOffLen();
            }

            IByteBuffer buffer = Unpooled.WrappedBuffer(array, offset, count);

            _pipeline.QueueWrite(buffer, sendHandle, completion);
        }
Exemplo n.º 8
0
        public void QueueWriteStream(WritableBuffer writableBuffer, StreamHandle sendHandle,
                                     Action <StreamHandle, Exception> completion)
        {
            if (completion is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.completion);
            }
            if (sendHandle is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.sendHandle);
            }

            IByteBuffer buffer = writableBuffer.GetBuffer();

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

            _pipeline.QueueWrite(buffer, sendHandle, completion);
        }
Exemplo n.º 9
0
 internal Pipeline(StreamHandle streamHandle)
     : this(streamHandle, PooledByteBufferAllocator.Default)
 {
 }