From 603ce10fae8855ee2343f79cd3ba6f3e06aa5cca Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Thu, 15 Jun 2006 04:26:01 +0000 Subject: [PATCH] Attempt to fix #147 - long song lists hang soundbridge... need grommet to test --- src/plugins/rsp.c | 10 +++++++--- src/plugins/xml-rpc.c | 18 +++++++++++++----- src/plugins/xml-rpc.h | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/plugins/rsp.c b/src/plugins/rsp.c index e7792063..99d910ca 100644 --- a/src/plugins/rsp.c +++ b/src/plugins/rsp.c @@ -364,6 +364,7 @@ void rsp_playlist(WS_CONNINFO *pwsc, PRIVINFO *ppi) { int type; int transcode; unsigned int samplerate; + int done = 0; ppi->dq.filter = _ppi->ws_getvar(pwsc,"query"); ppi->dq.filter_type = FILTER_TYPE_FIREFLY; @@ -418,7 +419,8 @@ void rsp_playlist(WS_CONNINFO *pwsc, PRIVINFO *ppi) { xml_push(pxml,"items"); - while((_ppi->db_enum_fetch_row(NULL,&row,&ppi->dq) == 0) && (row)) { + while((!done) && (_ppi->db_enum_fetch_row(NULL,&row,&ppi->dq) == 0) && + (row)) { xml_push(pxml,"item"); rowindex=0; transcode = 0; @@ -459,8 +461,10 @@ void rsp_playlist(WS_CONNINFO *pwsc, PRIVINFO *ppi) { break; } } else { - xml_output(pxml,rsp_fields[rowindex].name,"%s", - row[rowindex]); + /* check for pushing against closed socket */ + if(xml_output(pxml,rsp_fields[rowindex].name,"%s", + row[rowindex]) == -1) + done=1; } } diff --git a/src/plugins/xml-rpc.c b/src/plugins/xml-rpc.c index 8f8d6b58..2dbb1442 100644 --- a/src/plugins/xml-rpc.c +++ b/src/plugins/xml-rpc.c @@ -53,19 +53,24 @@ XML_STREAMBUFFER *xml_stream_open(void); int xml_stream_write(XMLSTRUCT *pxml, char *out); int xml_stream_close(XMLSTRUCT *pxml); -void xml_write(XMLSTRUCT *pxml, char *fmt, ...) { +int xml_write(XMLSTRUCT *pxml, char *fmt, ...) { char buffer[1024]; va_list ap; + int result=0; va_start(ap, fmt); vsnprintf(buffer, 1024, fmt, ap); va_end(ap); if(pxml->psb) { - xml_stream_write(pxml, buffer); + result=xml_stream_write(pxml, buffer); + if(!result) + result = -1; } else { - _ppi->ws_writefd(pxml->pwsc,"%s",buffer); + result=_ppi->ws_writefd(pxml->pwsc,"%s",buffer); } + + return result; } void xml_return_error(WS_CONNINFO *pwsc, int errno, char *errstr) { @@ -283,10 +288,11 @@ void xml_pop(XMLSTRUCT *pxml) { /** * output a string */ -void xml_output(XMLSTRUCT *pxml, char *section, char *fmt, ...) { +int xml_output(XMLSTRUCT *pxml, char *section, char *fmt, ...) { va_list ap; char buf[256]; char *output; + int result=0; va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); @@ -297,11 +303,13 @@ void xml_output(XMLSTRUCT *pxml, char *section, char *fmt, ...) { xml_push(pxml,section); } - xml_write(pxml,"%s",output); + result = xml_write(pxml,"%s",output); free(output); if(section) { xml_pop(pxml); } + + return result; } /** diff --git a/src/plugins/xml-rpc.h b/src/plugins/xml-rpc.h index e8bc9b57..ea4d8114 100644 --- a/src/plugins/xml-rpc.h +++ b/src/plugins/xml-rpc.h @@ -14,7 +14,7 @@ typedef struct tag_ws_conninfo WS_CONNINFO; extern XMLSTRUCT *xml_init(WS_CONNINFO *pwsc, int emit_header); extern void xml_push(XMLSTRUCT *pxml, char *term); extern void xml_pop(XMLSTRUCT *pxml); -extern void xml_output(XMLSTRUCT *pxml, char *section, char *fmt, ...); +extern int xml_output(XMLSTRUCT *pxml, char *section, char *fmt, ...); extern void xml_deinit(XMLSTRUCT *pxml);