add keepalive timers

This commit is contained in:
Eric House 2013-08-02 08:01:16 -07:00
parent 1e35d676bf
commit da54b1e5fb
4 changed files with 26 additions and 5 deletions

View file

@ -1801,8 +1801,17 @@ cursesNoticeRcvd( void* closure )
(void)g_idle_add( curses_requestMsgs, globals );
}
static gboolean
keepalive_timer( gpointer data )
{
LOG_FUNC();
curses_requestMsgs( data );
return TRUE;
}
static void
cursesDevIDChanged( void* closure, const XP_UCHAR* devID )
cursesDevIDChanged( void* closure, const XP_UCHAR* devID,
XP_U16 maxInterval )
{
CursesAppGlobals* globals = (CursesAppGlobals*)closure;
CommonGlobals* cGlobals = &globals->cGlobals;
@ -1810,6 +1819,7 @@ cursesDevIDChanged( void* closure, const XP_UCHAR* devID )
if ( !!devID ) {
XP_LOGF( "%s(devID=%s)", __func__, devID );
db_store( pDb, KEY_RDEVID, devID );
(void)g_timeout_add_seconds( maxInterval, keepalive_timer, globals );
} else {
XP_LOGF( "%s: bad relayid", __func__ );
db_remove( pDb, KEY_RDEVID );

View file

@ -505,14 +505,23 @@ gtkNoticeRcvd( void* closure )
(void)g_idle_add( requestMsgs, apg );
}
static gboolean
keepalive_timer( gpointer data )
{
LOG_FUNC();
requestMsgs( data );
return TRUE;
}
static void
gtkDevIDChanged( void* closure, const XP_UCHAR* devID )
gtkDevIDChanged( void* closure, const XP_UCHAR* devID, XP_U16 maxInterval )
{
GtkAppGlobals* apg = (GtkAppGlobals*)closure;
LaunchParams* params = apg->params;
if ( !!devID ) {
XP_LOGF( "%s(devID=%s)", __func__, devID );
db_store( params->pDb, KEY_RDEVID, devID );
(void)g_timeout_add_seconds( maxInterval, keepalive_timer, apg );
} else {
XP_LOGF( "%s: bad relayid", __func__ );
db_remove( params->pDb, KEY_RDEVID );

View file

@ -215,7 +215,8 @@ relaycon_receive( void* closure, int socket )
getNetString( &ptr, len, devID );
XP_U16 maxInterval = getNetShort( &ptr );
XP_LOGF( "%s: maxInterval=%d", __func__, maxInterval );
(*storage->procs.devIDChanged)( storage->procsClosure, devID );
(*storage->procs.devIDChanged)( storage->procsClosure, devID,
maxInterval );
}
break;
case XWPDEV_MSG:
@ -223,7 +224,7 @@ relaycon_receive( void* closure, int socket )
ptr, end - ptr );
break;
case XWPDEV_BADREG:
(*storage->procs.devIDChanged)( storage->procsClosure, NULL );
(*storage->procs.devIDChanged)( storage->procsClosure, NULL, 0 );
break;
case XWPDEV_HAVEMSGS: {
(*storage->procs.msgNoticeReceived)( storage->procsClosure );

View file

@ -25,7 +25,8 @@
typedef struct _Procs {
void (*msgReceived)( void* closure, const XP_U8* buf, XP_U16 len );
void (*msgNoticeReceived)( void* closure );
void (*devIDChanged)( void* closure, const XP_UCHAR* devID );
void (*devIDChanged)( void* closure, const XP_UCHAR* devID,
XP_U16 maxInterval );
void (*msgErrorMsg)( void* closure, const XP_UCHAR* msg );
void (*socketChanged)( void* closure, int newSock, int oldSock,
SockReceiver proc, void* procClosure );