Beispiel #1
0
        public void EnqueueWriteRequest(UvWriteRequest writeRequest)
        {
            var job = new WriteRequestJob(writeRequest ?? throw new ArgumentNullException(nameof(writeRequest)));

            this.writeRequestQueue.Enqueue(job);
            this.jobNotificationAsync.Send();
        }
Beispiel #2
0
        private void WriteCallback(UvWriteRequest request, Exception error, object stateObject)
        {
            try
            {
                if (stateObject is BufferSegment buffer)
                {
                    buffer.Dispose();
                }

                if (error != null)
                {
                    throw error;
                }
            }
            catch (UvErrorException exception)
            {
                if (exception.ErrorCode == UvErrorCode.ECANCELED)
                {
                    // Ignore
                }
                else if (exception.ErrorCode == UvErrorCode.ECONNRESET)
                {
                    this.Close();
                }
                else
                {
                    this.Close(exception);
                }
            }
            catch (Exception exception)
            {
                this.Close(exception);
            }
        }
Beispiel #3
0
 private void WriteHandleCallback(UvWriteRequest request, Exception error, object stateObject)
 {
     try
     {
         if (error != null)
         {
             throw error;
         }
     }
     catch (Exception exception)
     {
         this.OnConnectionAcceptError(exception);
     }
     finally
     {
         ((UvTcp)stateObject).Close();
     }
 }
Beispiel #4
0
        public override void Send(IPacket packet)
        {
            try
            {
                var buffer = this.BufferPool.Acquire(this.Protocol.CalculatePacketSize(packet));
                var length = this.Protocol.Write(packet, buffer.Buffer, buffer.Offset, buffer.Length);

                var writeRequest = new UvWriteRequest(this.BaseSocket, new ArraySegment <byte>(buffer.Buffer, buffer.Offset, length), this.WriteCallback, buffer);

                if (this.Worker != null && Thread.CurrentThread.ManagedThreadId != this.BaseSocket.ThreadId)
                {
                    this.Worker.EnqueueWriteRequest(writeRequest);
                }
                else
                {
                    writeRequest.Write();
                }
            }
            catch (UvErrorException exception)
            {
                if (exception.ErrorCode == UvErrorCode.ECONNRESET)
                {
                    this.Close();
                }
                else
                {
                    this.Close(exception);
                }
            }
            catch (Exception exception)
            {
                this.Close(exception);
                if (!this.SilentSend)
                {
                    throw;
                }
            }
        }
Beispiel #5
0
 public WriteRequestJob(UvWriteRequest writeRequest)
 {
     this.WriteRequest = writeRequest;
 }
Beispiel #6
0
 public static extern int uv_write2(UvWriteRequest req, UvStream handle, UvBuffer[] bufs, int nbufs, UvStream sendHandle, UvWriteCallback cb);