diff -r 14e279d2bbb7 -r 22de2e391156 bluetooth/btstack/l2cap/l2capSigStates.cpp --- a/bluetooth/btstack/l2cap/l2capSigStates.cpp Wed Jul 21 15:42:05 2010 +0300 +++ b/bluetooth/btstack/l2cap/l2capSigStates.cpp Thu Sep 23 17:06:47 2010 +0300 @@ -286,6 +286,8 @@ { LOG_FUNC // The SAP has requested a channel be opened. + // Override all LPMs to try and avoid signalling timeouts + aSignalHandler.OverrideLPM(); TInt err = aSignalHandler.ChannelConfig().UpdateLocalConfigWithEntityCapabilities(); if (err == KErrNone) @@ -298,9 +300,6 @@ // Update local Port. aSignalHandler.SetLocalPort(port); - // Override park to allow the connection to be made. - aSignalHandler.OverrideParkMode(); - // Active connection. Send a Connect Request command. err = aSignalHandler.ConstructConnectionRequest(); if(err == KErrNone) @@ -330,10 +329,8 @@ // Update local Port. aSignalHandler.SetLocalPort(port); - // Override park to allow the connection to be made. - aSignalHandler.OverrideParkMode(); - // Override all LPMs (if timeout not set to zero) - aSignalHandler.OverrideLPMWithTimeout(); + // Override all LPMs to try and avoid signalling timeouts + aSignalHandler.OverrideLPM(); // Send a response with a 'pending' result and start security procedure. err = aSignalHandler.ConstructConnectionResponse(aSignalHandler.GetOutstandingRequestID(), @@ -384,10 +381,16 @@ aSignalHandler.iOpenChannelRequestAwaitingPeerEntityConfig = EFalse; - // If Park mode has been overridden during either channel establishment or - // channel disconnect, remove the override. - // NB It is safe to call this method multiple times. + // Depending where we came from we may have applied either a + // park override or an all LPM override. We remove both these + // overrides because it's safe to remove an override that + // hasn't been applied. + // Note that although park is one of the LPMs the different + // levels of override are managed separately, so an + // UndoOverrideLPM does not remove an explicit park only + // override. aSignalHandler.UndoOverrideParkMode(); + aSignalHandler.UndoOverrideLPM(); // If the signal handler has left the closed state, it will have been added // to the SH list in the Muxer. Now that the closed state is being @@ -898,6 +901,9 @@ void TL2CAPSigStateWaitConfig::Enter(CL2CapSAPSignalHandler& aSignalHandler) const { LOG_FUNC + // Cancel the Config timer if it's running + aSignalHandler.CancelTimer(); + // First start the ConfigReq sending delay timer (see DelayConfigRequest() for why). // It's short lived, we'll start the proper L2CAP config timer when it expires. aSignalHandler.StartConfigRequestDelayTimer(); @@ -1088,8 +1094,16 @@ } else { - // Remove and park override. + // Depending where we came from we may have applied either a + // park override or an all LPM override. We remove both these + // overrides because it's safe to remove an override that + // hasn't been applied. + // Note that although park is one of the LPMs the different + // levels of override are managed separately, so an + // UndoOverrideLPM does not remove an explicit park only + // override. aSignalHandler.UndoOverrideParkMode(); + aSignalHandler.UndoOverrideLPM(); // Cancel the configuration timer. aSignalHandler.CancelTimer(); @@ -1146,7 +1160,23 @@ void TL2CAPSigStateWaitDisconnect::DisconnectResponse(CL2CapSAPSignalHandler& aSignalHandler) const { LOG_FUNC - aSignalHandler.DrainPendingCommands(); + // We've got a disconnect response, we're done. Any remaing stuff on the queue + // is redundant, so ditch it and close synchronously. + aSignalHandler.FlushAllQueues(); + + // If an error condition has been recorded forward the error + // to the SAP. + if(aSignalHandler.SignalHandlerErrorCode() != KErrNone) + { + Error(aSignalHandler, aSignalHandler.SignalHandlerErrorCode(), aSignalHandler.SignalHandlerErrorAction()); + } + else + { + // This will delete the signal handler if the SAP has detached. + aSignalHandler.SetState(iFactory.GetState(CL2CAPSignalStateFactory::EClosed)); + aSignalHandler.SignalHandlerDisconnectedCanClose(); + } + } // "Artificial" state events @@ -1170,7 +1200,9 @@ void TL2CAPSigStateWaitDisconnect::Enter(CL2CapSAPSignalHandler& aSignalHandler) const { LOG_FUNC - // Override park to allow the disconnect to continue. + // Only override park for disconnect. We need to be able + // to send the signalling, but we don't care if it takes + // ages. No point starting a sniff bun-fight. aSignalHandler.OverrideParkMode(); // Cancel the configuration timer.