internal void EnableMars() { if (_fMARS) { // Cache physical stateObj and connection. _pMarsPhysicalConObj = _physicalStateObj; UInt32 error = 0; // Add SMUX (MARS) SNI provider. UInt32 info = 0; error = SNINativeMethodWrapper.SNIAddProvider(_pMarsPhysicalConObj.Handle, SNINativeMethodWrapper.ProviderEnum.SMUX_PROV, ref info); if (error != TdsEnums.SNI_SUCCESS) { _physicalStateObj.AddError(ProcessSNIError(_physicalStateObj)); ThrowExceptionAndWarning(_physicalStateObj); } // HACK HACK HACK - for Async only // Have to post read to intialize MARS - will get callback on this when connection goes // down or is closed. IntPtr temp = IntPtr.Zero; try { } finally { _pMarsPhysicalConObj.IncrementPendingCallbacks(); error = SNINativeMethodWrapper.SNIReadAsync(_pMarsPhysicalConObj.Handle, ref temp); if (temp != IntPtr.Zero) { // Be sure to release packet, otherwise it will be leaked by native. SNINativeMethodWrapper.SNIPacketRelease(temp); } } Debug.Assert(IntPtr.Zero == temp, "unexpected syncReadPacket without corresponding SNIPacketRelease"); if (TdsEnums.SNI_SUCCESS_IO_PENDING != error) { Debug.Assert(TdsEnums.SNI_SUCCESS != error, "Unexpected successfull read async on physical connection before enabling MARS!"); _physicalStateObj.AddError(ProcessSNIError(_physicalStateObj)); ThrowExceptionAndWarning(_physicalStateObj); } _physicalStateObj = CreateSession(); // Create and open default MARS stateObj and connection. } }
internal void ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj) { if ((this._parser.State != TdsParserState.Broken) && (this._parser.State != TdsParserState.Closed)) { IntPtr zero = IntPtr.Zero; RuntimeHelpers.PrepareConstrainedRegions(); try { uint num; if (!this._parser.AsyncOn) { num = SNINativeMethodWrapper.SNIReadSync(stateObj.Handle, ref zero, TdsParserStaticMethods.GetTimeoutMilliseconds(stateObj.TimeoutTime)); if (num == 0) { stateObj.ProcessSniPacket(zero, 0); } else { this.ReadSniError(stateObj, num); } } else { stateObj._asyncResult = asyncResult; RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { stateObj.IncrementPendingCallbacks(); num = SNINativeMethodWrapper.SNIReadAsync(stateObj.Handle, ref zero); if ((num != 0) && (0x3e5 != num)) { stateObj.DecrementPendingCallbacks(false); } } if (num == 0) { stateObj._asyncResult.SetCompletedSynchronously(); stateObj.ReadAsyncCallback(ADP.PtrZero, zero, 0); } else if (0x3e5 != num) { this.ReadSniError(stateObj, num); } } } finally { if (zero != IntPtr.Zero) { SNINativeMethodWrapper.SNIPacketRelease(zero); } } } }