コード例 #1
0
        private unsafe void QueueSend(IByteBuffer buffer,
                                      IPEndPoint remoteEndPoint,
                                      Action <Udp, Exception> completion)
        {
            if (buffer is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.buffer);
            }
            if (remoteEndPoint is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.remoteEndPoint);
            }

            WriteRequest request = Loop.SendRequestPool.Take();

            try
            {
                request.Prepare(buffer,
                                (sendRequest, exception) => completion?.Invoke(this, exception));

                NativeMethods.UdpSend(
                    request.InternalHandle,
                    InternalHandle,
                    remoteEndPoint,
                    request.Bufs,
                    ref request.Size);
            }
            catch (Exception exception)
            {
                request.Release();
                Log.Handle_faulted(HandleType, exception);
                throw;
            }
        }
コード例 #2
0
ファイル: TcpChannel.cs プロジェクト: zmk523/DotNetty
        void Write(ChannelOutboundBuffer input)
        {
            while (true)
            {
                int size = input.Count;
                if (size == 0)
                {
                    break;
                }

                List <ArraySegment <byte> > nioBuffers = input.GetSharedBufferList();
                int  nioBufferCnt         = nioBuffers.Count;
                long expectedWrittenBytes = input.NioBufferSize;
                if (nioBufferCnt == 0)
                {
                    this.WriteByteBuffers(input);
                    return;
                }
                else
                {
                    WriteRequest writeRequest = Recycler.Take();
                    writeRequest.Prepare((TcpChannelUnsafe)this.Unsafe, nioBuffers);
                    this.tcp.Write(writeRequest);
                    input.RemoveBytes(expectedWrittenBytes);
                }
            }
        }
コード例 #3
0
        internal void QueueWrite(BufferRef 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;
            }
        }
コード例 #4
0
ファイル: Pipeline.cs プロジェクト: yyjdelete/SpanNetty
        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;
            }
        }
コード例 #5
0
ファイル: TcpChannel.cs プロジェクト: zmk523/DotNetty
        void WriteByteBuffers(ChannelOutboundBuffer input)
        {
            while (true)
            {
                object msg = input.Current;
                if (msg == null)
                {
                    // Wrote all messages.
                    break;
                }

                if (msg is IByteBuffer buf)
                {
                    int readableBytes = buf.ReadableBytes;
                    if (readableBytes == 0)
                    {
                        input.Remove();
                        continue;
                    }

                    var nioBuffers = new List <ArraySegment <byte> >();
                    ArraySegment <byte> nioBuffer = buf.GetIoBuffer();
                    nioBuffers.Add(nioBuffer);
                    WriteRequest writeRequest = Recycler.Take();
                    writeRequest.Prepare((TcpChannelUnsafe)this.Unsafe, nioBuffers);
                    this.tcp.Write(writeRequest);

                    input.Remove();
                }
                else
                {
                    // Should not reach here.
                    throw new InvalidOperationException();
                }
            }
        }