/// <summary> /// Receive a packet asynchronously /// </summary> /// <param name="packet">SNI packet</param> /// <returns>SNI error code</returns> public override uint ReceiveAsync(ref SNIPacket packet, bool isMars = false) { lock (this) { packet = new SNIPacket(null); packet.Allocate(_bufferSize); try { packet.ReadFromStreamAsync(_stream, _receiveCallback, isMars); return(TdsEnums.SNI_SUCCESS_IO_PENDING); } catch (ObjectDisposedException ode) { return(ReportErrorAndReleasePacket(packet, ode)); } catch (SocketException se) { return(ReportErrorAndReleasePacket(packet, se)); } catch (IOException ioe) { return(ReportErrorAndReleasePacket(packet, ioe)); } } }
/// <summary> /// Receive a packet asynchronously /// </summary> /// <param name="packet">SNI packet</param> /// <returns>SNI error code</returns> public override uint ReceiveAsync(ref SNIPacket packet) { packet = new SNIPacket(_bufferSize); try { packet.ReadFromStreamAsync(_stream, _receiveCallback); return(TdsEnums.SNI_SUCCESS_IO_PENDING); } catch (Exception e) when(e is ObjectDisposedException || e is SocketException || e is IOException) { return(ReportErrorAndReleasePacket(packet, e)); } }
public override uint ReceiveAsync(ref SNIPacket packet) { packet = new SNIPacket(headerSize: 0, dataSize: _bufferSize); try { packet.ReadFromStreamAsync(_stream, _receiveCallback); return(TdsEnums.SNI_SUCCESS_IO_PENDING); } catch (ObjectDisposedException ode) { return(ReportErrorAndReleasePacket(packet, ode)); } catch (IOException ioe) { return(ReportErrorAndReleasePacket(packet, ioe)); } }
/// <summary> /// Receive a packet asynchronously /// </summary> /// <param name="packet">SNI packet</param> /// <returns>SNI error code</returns> public sealed override bool ReceiveAsync(bool forceCallback, ref SNIPacket packet, out SNIError sniError) { packet = packet ?? new SNIPacket(); packet.Allocate(_bufferSize); using (_debugLock.Acquire(this)) { try { packet.ReadFromStreamAsync(_stream, _receiveCallback); sniError = null; return(false); } catch (ObjectDisposedException ode) { sniError = new SNIError(ProviderNumber, 0, ode); } catch (SocketException se) { sniError = new SNIError(ProviderNumber, 0, se); } catch (IOException ioe) { sniError = new SNIError(ProviderNumber, 0, ioe); } // Fallthrough: Something failed Debug.Assert(sniError != null, "Error should be set if we didn't already return"); if (forceCallback) { Task.Factory.StartNew( ReceiveAsyncErrorContinuation, Tuple.Create(packet, sniError), CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default); sniError = null; return(false); } return(true); } }