internal void Reset()
 {
     this.status      = 0;
     this.endOfStream = false;
     this.buffer      = Unpooled.Empty;
     this.error       = null;
 }
示例#2
0
 internal void Reset()
 {
     _status      = 0;
     _endOfStream = false;
     _buffer      = Unpooled.Empty;
     _error       = null;
 }
示例#3
0
        internal void Complete(int statusCode, OperationException operationException)
        {
            Release();

            _status      = statusCode;
            _endOfStream = statusCode == NativeMethods.EOF;
            _error       = operationException;
        }
        internal void Complete(int statusCode, OperationException operationException)
        {
            this.Release();

            this.status      = statusCode;
            this.endOfStream = statusCode == NativeMethods.EOF;
            this.error       = operationException;
        }
示例#5
0
        internal void Release()
        {
            this.ReleaseHandles();

            this.nativeUnsafe = null;
            this.Error        = null;
            this.recyclerHandle.Release(this);
        }
示例#6
0
        internal void Complete(int status, OperationException error)
        {
            this.Release();

            this.Status      = status;
            this.EndOfStream = status == (int)uv_err_code.UV_EOF;
            this.Error       = error;
            this.nativeUnsafe.FinishRead(this);
        }
示例#7
0
文件: Pipe.cs 项目: cdy816/mars
            void OnWriteCallback(int status)
            {
                if (status < 0)
                {
                    OperationException error = NativeMethods.CreateError((uv_err_code)status);
                    //Logger.Warn($"{nameof(PipeListener)} failed to write server handle to client", error);
                }

                this.sentHandle.CloseHandle();
                this.Dispose();
            }
示例#8
0
        void OnWriteCallback(int status)
        {
            this.ReleaseHandles();

            if (status < 0)
            {
                this.Error = NativeMethods.CreateError((uv_err_code)status);
            }

            this.nativeUnsafe.FinishWrite(this);
        }
示例#9
0
            void OnWriteCallback(int status)
            {
                if (status < 0)
                {
                    OperationException error = NativeMethods.CreateError((uv_err_code)status);
                    if (Logger.WarnEnabled)
                    {
                        Logger.FailedToWriteServerHandleToClient(error);
                    }
                }

                _sentHandle.CloseHandle();
                Dispose();
            }
示例#10
0
文件: Tcp.cs 项目: wxlonstar/Fenix
        static void OnReadCallback(IntPtr handle, IntPtr nread, ref uv_buf_t buf)
        {
            var tcp    = GetTarget <Tcp>(handle);
            int status = (int)nread.ToInt64();

            OperationException error = null;

            if (status < 0 && status != NativeMethods.EOF)
            {
                error = NativeMethods.CreateError((uv_err_code)status);
            }

            tcp.OnReadCallback(status, error);
        }
        void OnWriteCallback(int status)
        {
            NativeChannel.INativeUnsafe @unsafe = this.nativeUnsafe;
            int bytesWritten = this.size;

            this.Release();

            OperationException error = null;

            if (status < 0)
            {
                error = NativeMethods.CreateError((uv_err_code)status);
            }
            @unsafe.FinishWrite(bytesWritten, error);
        }
示例#12
0
 void OnReadCallback(int statusCode, OperationException error)
 {
     try
     {
         this.pendingRead.Complete(statusCode, error);
         this.nativeUnsafe.FinishRead(this.pendingRead);
     }
     catch (Exception exception)
     {
         //Logger.Warn($"Tcp {this.Handle} read callbcak error.", exception);
     }
     finally
     {
         this.pendingRead.Reset();
     }
 }
示例#13
0
文件: Tcp.cs 项目: wxlonstar/Fenix
 void OnReadCallback(int statusCode, OperationException error)
 {
     try
     {
         _pendingRead.Complete(statusCode, error);
         _nativeUnsafe.FinishRead(_pendingRead);
     }
     catch (Exception exception)
     {
         if (Logger.WarnEnabled)
         {
             Logger.TcpHandleReadCallbcakError(Handle, exception);
         }
     }
     finally
     {
         _pendingRead.Reset();
     }
 }
示例#14
0
        void OnRead(Pipe pipe, int status)
        {
            // The server connection is never meant to read anything back
            // it is only used for passing handles over to different loops
            // Therefore the only message should come back is EOF
            if (status >= 0)
            {
                return;
            }

            this.windowsApi.Dispose();
            this.pipes.Remove(pipe);
            pipe.CloseHandle();

            if (status != NativeMethods.EOF)
            {
                OperationException error = NativeMethods.CreateError((uv_err_code)status);
                //Logger.Warn($"{nameof(PipeListener)} read error", error);
            }
        }
示例#15
0
        static void OnReadCallback(IntPtr handle, IntPtr nread, ref uv_buf_t buf)
        {
            var tcp    = GetTarget <Tcp>(handle);
            int status = (int)nread.ToInt64();

            OperationException error = null;

            if (status < 0 && status != (int)uv_err_code.UV_EOF)
            {
                error = NativeMethods.CreateError((uv_err_code)status);
            }

            ReadOperation operation = tcp.pendingReads.Poll();

            if (operation == null)
            {
                if (error != null)
                {
                    // It is possible if the client connection resets
                    // causing errors where there are no pending read
                    // operations, in this case we just notify the channel
                    // for errors
                    operation = new ReadOperation(tcp.unsafeChannel, Unpooled.Empty);
                }
                else
                {
                    Logger.Warn("Channel read operation completed prematurely.");
                    return;
                }
            }

            try
            {
                operation.Complete(status, error);
            }
            catch (Exception exception)
            {
                Logger.Warn("Channel read callbcak failed.", exception);
            }
        }
示例#16
0
        private void OnRead(Pipe pipe, int status)
        {
            // The server connection is never meant to read anything back
            // it is only used for passing handles over to different loops
            // Therefore the only message should come back is EOF
            if (status >= 0)
            {
                return;
            }

            _windowsApi.Dispose();
            _ = _pipes.Remove(pipe);
            pipe.CloseHandle();

            if (status != NativeMethods.EOF)
            {
                OperationException error = NativeMethods.CreateError((uv_err_code)status);
                if (Logger.WarnEnabled)
                {
                    Logger.ReadError(error);
                }
            }
        }
示例#17
0
        public void Close()
        {
            IntPtr loopHandle = this.Handle;

            if (loopHandle == IntPtr.Zero)
            {
                return;
            }

            // Get gc handle before close loop
            IntPtr pHandle = ((uv_loop_t *)loopHandle)->data;

            // Close loop
            try
            {
                int retry = 0;
                while (retry < 10)
                {
                    // Force close all active handles before close the loop
                    NativeMethods.uv_walk(loopHandle, WalkCallback, loopHandle);
                    Logger.Debug($"Loop {loopHandle} walk all handles completed.");

                    // Loop.Run here actually blocks in some intensive situitions
                    // and it is highly unpredictable. For now, we rely on the users
                    // to do the right things before disposing the loop,
                    // e.g. close all handles before calling this.
                    // NativeMethods.RunLoop(handle, uv_run_mode.UV_RUN_DEFAULT);
                    int result = NativeMethods.uv_loop_close(loopHandle);
                    if (result >= 0)
                    {
                        break;
                    }
                    else
                    {
                        OperationException error = NativeMethods.CreateError((uv_err_code)result);
                        // Only retry if loop close return busy
                        if (error.Name != "EBUSY")
                        {
                            throw error;
                        }
                    }

                    retry++;
                }
            }
            catch (Exception exception)
            {
                Logger.Warn($"Loop {loopHandle} error attempt to run loop once before closing. {exception}");
            }

            Logger.Info($"Loop {loopHandle} closed.");

            // Free GCHandle
            if (pHandle != IntPtr.Zero)
            {
                GCHandle nativeHandle = GCHandle.FromIntPtr(pHandle);
                if (nativeHandle.IsAllocated)
                {
                    nativeHandle.Free();
                    ((uv_loop_t *)loopHandle)->data = IntPtr.Zero;
                    Logger.Info($"Loop {loopHandle} GCHandle released.");
                }
            }

            // Release memory
            Marshal.FreeHGlobal(loopHandle);
            this.Handle = IntPtr.Zero;
            Logger.Info($"Loop {loopHandle} memory released.");
        }