internal void Reset() { this.status = 0; this.endOfStream = false; this.buffer = Unpooled.Empty; this.error = null; }
internal void Reset() { _status = 0; _endOfStream = false; _buffer = Unpooled.Empty; _error = null; }
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; }
internal void Release() { this.ReleaseHandles(); this.nativeUnsafe = null; this.Error = null; this.recyclerHandle.Release(this); }
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); }
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(); }
void OnWriteCallback(int status) { this.ReleaseHandles(); if (status < 0) { this.Error = NativeMethods.CreateError((uv_err_code)status); } this.nativeUnsafe.FinishWrite(this); }
void OnWriteCallback(int status) { if (status < 0) { OperationException error = NativeMethods.CreateError((uv_err_code)status); if (Logger.WarnEnabled) { Logger.FailedToWriteServerHandleToClient(error); } } _sentHandle.CloseHandle(); Dispose(); }
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); }
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(); } }
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(); } }
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); } }
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); } }
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); } } }
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."); }