Use a timer to avoid trying to get an ACL connection too frequetly.

This seems to trigger crash Treo650s far less often than constantly
retrying.
This commit is contained in:
ehouse 2007-05-26 22:51:25 +00:00
parent a2f60cb1f8
commit d58789c493
3 changed files with 37 additions and 8 deletions

View file

@ -31,6 +31,7 @@
#define SOCK_INVAL ((BtLibSocketRef)-1)
// #define DO_SERVICE_RECORD 1
#define ACL_WAIT_INTERVAL 8
typedef enum { PBT_UNINIT = 0, PBT_MASTER, PBT_SLAVE } PBT_PicoRole;
@ -137,6 +138,7 @@ static void pbt_postpone( PalmBTStuff* btStuff, PBT_ACTION act );
static XP_S16 pbt_enque( PBT_queue* queue, const XP_U8* data, XP_S16 len );
static void pbt_processIncoming( PalmBTStuff* btStuff );
static void waitACL( PalmBTStuff* btStuff );
static void pbt_reset( PalmBTStuff* btStuff );
static void pbt_killL2C( PalmBTStuff* btStuff, BtLibSocketRef sock );
static void pbt_checkAddress( PalmBTStuff* btStuff, const CommsAddrRec* addr );
@ -654,7 +656,7 @@ pbt_do_work( PalmBTStuff* btStuff )
SET_STATE( btStuff, PBTST_L2C_CONNECTING );
} else {
SET_STATE( btStuff, PBTST_NONE );
pbt_postpone( btStuff, PBT_ACT_CONNECT_ACL );
waitACL( btStuff );
}
} else {
btStuff->dataSocket = SOCK_INVAL;
@ -756,6 +758,22 @@ pbt_reset( PalmBTStuff* btStuff )
LOG_RETURN_VOID();
}
static void
btTimerProc( void* closure, XWTimerReason why )
{
PalmBTStuff* btStuff;
btStuff = (PalmBTStuff*)closure;
XP_ASSERT( why == TIMER_ACL_BACKOFF );
pbt_postpone( btStuff, PBT_ACT_CONNECT_ACL );
}
static void
waitACL( PalmBTStuff* btStuff )
{
util_setTimer( &btStuff->globals->util, TIMER_ACL_BACKOFF,
ACL_WAIT_INTERVAL, btTimerProc, btStuff );
}
static Err
bpd_discover( PalmBTStuff* btStuff, BtLibDeviceAddressType* addr )
{
@ -959,7 +977,7 @@ l2SocketCallback( BtLibSocketEventType* sEvent, UInt32 refCon )
*/
if ( PBT_SLAVE == btStuff->picoRole ) {
pbt_killL2C( btStuff, sEvent->socket );
pbt_postpone( btStuff, PBT_ACT_CONNECT_ACL );
waitACL( btStuff );
} else if ( PBT_MASTER == btStuff->picoRole ) {
pbt_close_datasocket( btStuff );
SET_STATE( btStuff, PBTST_LISTENING );
@ -1009,7 +1027,7 @@ libMgmtCallback( BtLibManagementEventType* mEvent, UInt32 refCon )
pbt_postpone( btStuff, PBT_ACT_CONNECT_L2C );
} else {
SET_STATE( btStuff, PBTST_NONE );
pbt_postpone( btStuff, PBT_ACT_CONNECT_ACL );
waitACL( btStuff );
}
break;
@ -1039,7 +1057,7 @@ libMgmtCallback( BtLibManagementEventType* mEvent, UInt32 refCon )
SET_STATE( btStuff, PBTST_NONE );
/* See comment at btLibSocketEventDisconnected */
if ( PBT_SLAVE == btStuff->picoRole ) {
pbt_postpone( btStuff, PBT_ACT_CONNECT_ACL );
waitACL( btStuff );
}
}
break;

View file

@ -1558,7 +1558,7 @@ timeForTimer( PalmAppGlobals* globals, XWTimerReason* why, XP_U32* when )
XP_U32 nextWhen = 0xFFFFFFFF;
XP_Bool found;
for ( i = 1; i < NUM_TIMERS_PLUS_ONE; ++i ) {
for ( i = 1; i < NUM_PALM_TIMERS; ++i ) {
if ( (globals->timerProcs[i] != NULL) &&
(globals->timerFireAt[i] < nextWhen) ) {
nextWhy = i;
@ -3782,6 +3782,10 @@ palm_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why,
#ifdef XWFEATURE_RELAY
} else if ( why == TIMER_HEARTBEAT ) {
now += (secsFromNow * SysTicksPerSecond());
#endif
#ifdef XWFEATURE_BLUETOOTH
} else if ( why == TIMER_ACL_BACKOFF ) {
now += (secsFromNow * SysTicksPerSecond());
#endif
} else {
XP_ASSERT( 0 );

View file

@ -231,6 +231,13 @@ typedef enum {
} BtUIState;
#endif
#ifdef XWFEATURE_BLUETOOTH
# define TIMER_ACL_BACKOFF NUM_TIMERS_PLUS_ONE
# define NUM_PALM_TIMERS (NUM_TIMERS_PLUS_ONE + 1)
#else
# define NUM_PALM_TIMERS NUM_TIMERS_PLUS_ONE
#endif
struct PalmAppGlobals {
FormPtr mainForm;
PrefsDlgState* prefsDlgState;
@ -324,9 +331,9 @@ struct PalmAppGlobals {
struct ConnsDlgState* connState;
XWTimerProc timerProcs[NUM_TIMERS_PLUS_ONE];
void* timerClosures[NUM_TIMERS_PLUS_ONE];
XP_U32 timerFireAt[NUM_TIMERS_PLUS_ONE];
XWTimerProc timerProcs[NUM_PALM_TIMERS];
void* timerClosures[NUM_PALM_TIMERS];
XP_U32 timerFireAt[NUM_PALM_TIMERS];
#ifdef XWFEATURE_RELAY
NetLibStuff nlStuff;