// Treat local function as a static and pass all params otherwise as async will allocate static async Task ReadFromStreamAsync(SNIPacket packet, SNIAsyncCallback cb, ValueTask <int> valueTask) { bool error = false; try { packet._dataLength = await valueTask.ConfigureAwait(false); if (packet._dataLength == 0) { SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.TCP_PROV, 0, SNICommon.ConnTerminatedError, string.Empty); error = true; } } catch (Exception ex) { SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.TCP_PROV, SNICommon.InternalExceptionError, ex); error = true; } if (error) { packet.Release(); } cb(packet, error ? TdsEnums.SNI_ERROR : TdsEnums.SNI_SUCCESS); }
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)); }
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, string errorMessage) { if (packet != null) { packet.Release(); } return(ReportTcpSNIError(0, 0, errorMessage)); }
/// <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) { 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> /// Release packet /// </summary> /// <param name="packet">SNI packet</param> public void PacketRelease(SNIPacket packet) { packet.Release(); }