From e54a8a1d9eb9efd6436e16b2a150798a3f5b285c Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Sat, 29 Jul 2006 00:18:00 +0000 Subject: [PATCH] Defer updates while db is changing --- src/dispatch.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/dispatch.c b/src/dispatch.c index 2b04ee89..b7b5f52b 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -1382,6 +1382,7 @@ void dispatch_update(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) { fd_set rset; struct timeval tv; int result; + int lastver=0; DPRINTF(E_DBG,L_DAAP,"Preparing to send update response\n"); config_set_status(pwsc,pqi->session_id,"Waiting for DB update"); @@ -1390,7 +1391,10 @@ void dispatch_update(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) { clientver=atoi(ws_getvar(pwsc,"revision-number")); } - while(clientver == db_revision()) { + /* wait for db_version to be stable for 30 seconds */ + while((clientver == db_revision()) && (db_revision() == lastver)) { + lastver = db_revision(); + FD_ZERO(&rset); FD_SET(pwsc->fd,&rset); @@ -1400,8 +1404,8 @@ void dispatch_update(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) { result=select(pwsc->fd+1,&rset,NULL,NULL,&tv); if(FD_ISSET(pwsc->fd,&rset)) { /* can't be ready for read, must be error */ - DPRINTF(E_DBG,L_DAAP,"Socket closed?\n"); - + DPRINTF(E_DBG,L_DAAP,"Update session stopped\n"); + pwsc->close=1; return; } }