public override void ReturnPacket(SNIPacket packet) { #if DEBUG Debug.Assert(packet != null, "releasing null SNIPacket"); Debug.Assert(packet.IsActive, "SNIPacket _refcount must be 1 or a lifetime issue has occurred, trace with the #TRACE_HISTORY define"); Debug.Assert(ReferenceEquals(packet._owner, this), "releasing SNIPacket that belongs to another physical handle"); Debug.Assert(!packet.IsInvalid, "releasing already released SNIPacket"); #endif packet.Release(); #if DEBUG Interlocked.Add(ref packet._refCount, -1); packet._traceTag = null; #if TRACE_HISTORY if (packet._history != null) { packet._history.Add(new SNIPacket.History { Action = SNIPacket.History.Direction.Return, Stack = GetStackParts(), RefCount = packet._refCount }); } #endif GC.SuppressFinalize(packet); #endif _pool.Return(packet); }
private uint ReportErrorAndReleasePacket(SNIPacket packet, uint nativeError, uint sniError, string errorMessage) { if (packet != null) { packet.Release(); } return(ReportTcpSNIError(nativeError, sniError, errorMessage)); }
private uint ReportErrorAndReleasePacket(SNIPacket packet, Exception sniException) { if (packet != null) { packet.Release(); } return(ReportTcpSNIError(sniException)); }
private uint ReportErrorAndReleasePacket(SNIPacket packet, uint nativeError, uint sniError, string errorMessage) { if (packet != null) { packet.Release(); } return(SNICommon.ReportSNIError(SNIProviders.NP_PROV, nativeError, sniError, errorMessage)); }
private uint ReportErrorAndReleasePacket(SNIPacket packet, Exception sniException) { if (packet != null) { packet.Release(); } return(SNICommon.ReportSNIError(SNIProviders.NP_PROV, SNICommon.InternalExceptionError, sniException)); }
/// <summary> /// Process a receive error /// </summary> public void HandleReceiveError(SNIPacket packet) { Debug.Assert(Monitor.IsEntered(this), "HandleReceiveError was called without being locked."); foreach (SNIMarsHandle handle in _sessions.Values) { if (packet.HasCompletionCallback) { handle.HandleReceiveError(packet); } } packet?.Release(); }
/// <summary> /// Receive a packet asynchronously /// </summary> /// <param name="packet">SNI packet</param> /// <returns>SNI error code</returns> public uint ReceiveAsync(ref SNIPacket packet) { if (packet != null) { packet.Release(); packet = null; } lock (this) { return(_lowerHandle.ReceiveAsync(ref packet)); } }
/// <summary> /// Send a packet /// </summary> /// <param name="handle">SNI handle</param> /// <param name="packet">SNI packet</param> /// <param name="sync">true if synchronous, false if asynchronous</param> /// <returns>SNI error status</returns> public uint WritePacket(SNIHandle handle, SNIPacket packet, bool sync) { uint result; if (sync) { result = handle.Send(packet); packet.Release(); } else { result = handle.SendAsync(packet, true); } return(result); }
/// <summary> /// Process a receive error /// </summary> public void HandleReceiveError(SNIPacket packet) { Debug.Assert(Monitor.IsEntered(this), "HandleReceiveError was called without being locked."); if (!Monitor.IsEntered(this)) { SqlClientEventSource.Log.SNITraceEvent("<sc.SNI.SNIMarsConnection.HandleReceiveError |SNI|ERR> HandleReceiveError was called without being locked."); } foreach (SNIMarsHandle handle in _sessions.Values) { if (packet.HasCompletionCallback) { handle.HandleReceiveError(packet); } } packet?.Release(); }
internal void WriteAsyncCallback(SNIPacket packet, uint sniError) { SNIHandle sessionHandle = _sessionHandle; if (sessionHandle != null) { WriteAsyncCallback(IntPtr.Zero, PacketHandle.FromManagedPacket(packet), sniError); sessionHandle?.ReturnPacket(packet); } else { // clear the packet and drop it to GC because we no longer know how to return it to the correct owner // this can only happen if a packet is in-flight when the _sessionHandle is cleared packet.Release(); } }
public override void ReturnPacket(SNIPacket packet) { Debug.Assert(packet != null, "releasing null SNIPacket"); #if DEBUG Debug.Assert(packet.IsActive, "SNIPacket _refcount must be 1 or a lifetime issue has occured, trace with the #TRACE_HISTORY define"); Debug.Assert(ReferenceEquals(packet._owner, this), "releasing SNIPacket that belongs to another physical handle"); #endif Debug.Assert(!packet.IsInvalid, "releasing already released SNIPacket"); packet.Release(); #if DEBUG Interlocked.Add(ref packet._refCount, -1); packet._traceTag = null; packet.AddHistory(false); GC.SuppressFinalize(packet); #endif _pool.Return(packet); }
internal void ReadAsyncCallback(SNIPacket packet, uint error) { SNIHandle sessionHandle = _sessionHandle; if (sessionHandle != null) { ReadAsyncCallback(IntPtr.Zero, PacketHandle.FromManagedPacket(packet), error); SqlClientEventSource.Log.TryTraceEvent("TdsParserStateObjectManaged.ReadAsyncCallback | Info | State Object Id {0}, Session Id {1}, Error code returned {2}", _objectID, _sessionHandle?.ConnectionId, error); #if DEBUG SqlClientEventSource.Log.TryAdvancedTraceEvent("TdsParserStateObjectManaged.ReadAsyncCallback | TRC | State Object Id {0}, Session Id {1}, Packet Id = {2}, Error code returned {3}", _objectID, _sessionHandle?.ConnectionId, packet?._id, error); #endif sessionHandle?.ReturnPacket(packet); } else { // clear the packet and drop it to GC because we no longer know how to return it to the correct owner // this can only happen if a packet is in-flight when the _sessionHandle is cleared packet.Release(); } }
/// <summary> /// Receive a packet asynchronously /// </summary> /// <param name="packet">SNI packet</param> /// <returns>SNI error code</returns> public uint ReceiveAsync(ref SNIPacket packet) { long scopeID = SqlClientEventSource.Log.SNIScopeEnterEvent("<sc.SNI.SNIMarsConnection.SendAsync |SNI|INFO|SCOPE> SendAsync"); try { if (packet != null) { packet.Release(); packet = null; } lock (this) { return(_lowerHandle.ReceiveAsync(ref packet)); } } finally { SqlClientEventSource.Log.SNIScopeLeaveEvent(scopeID); } }
/// <summary> /// Release packet /// </summary> /// <param name="packet">SNI packet</param> public void PacketRelease(SNIPacket packet) { packet.Release(); }