Skip to content

Commit e304b88

Browse files
committed
Fix: songs not playing fully/skipping to next before the end
This Fix is to limit the watchdog's actions on remote stream read operations only. The watchdog will no longer stop the worker thread when waiting for LMS to read data. On windows, when streaming remote sources (e.g. spotty), playback buffer (stream controller, player, etc) would fill quickly and not request more data for a duration that caused the socketwrapper's WDT mechanism to trigger. This is a simple fix that introduces a new boolean indicator inside of the stage structure: ` BOOL bIsWriting; Stage threads update the flag during both the read phase (bIsWriting=false) and the writing phase (bIsWriting=true). This allows the main socketwrapper's thread to figure out if a given stage thread is reading from a remote socket, where the wdt applies, or if it is waiting for the stage thread to write back to LMS., where the wdt should not apply. if (info[i].fIsWorkerThread) { if (0 == info[i].WatchDog _**&& !info[i].bIsWriting**_) { stderrMsg("Watchdog expired - Thread for step %i stalled.\n", i); if (bWatchdogEnabled) fDie = true; } info[i].WatchDog = 0; }
1 parent 15724ee commit e304b88

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

socketwrapper/socketwrapper.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@
7979
// Version 1.11
8080
// Fix to stop socketwrapper not shutting down properly when input from stdin and output pipe is closed.
8181
//
82+
// ++++++
83+
// Version 1.12
84+
// Fix to limit the watchdog on remote stream read. The watchdog will no longer stop the worker thread
85+
// when waiting for LMS to read data.
86+
//
8287

8388
#include <process.h>
8489
#include "stdafx.h"
@@ -105,6 +110,7 @@ typedef struct
105110
HANDLE hInput; // input handle for process/thread
106111
HANDLE hOutput; // output handle for process/thread
107112
DWORD WatchDog; // watchdog for worker threads
113+
BOOL bIsWriting; // true when stage thread is writing back to LMS server
108114
DWORD nBlocks; // number of "blocks" read
109115
DWORD nBytes; // number of bytes read
110116
} Stage;
@@ -212,6 +218,7 @@ unsigned __stdcall MoveDataThreadProc(void *pv)
212218
}
213219

214220
// wait for some data from input
221+
pS->bIsWriting = false;
215222
if( !ReadFile(pS->hInput, pS->pBuff, BUFFER_SIZE, &bytesread, NULL) ) {
216223
stderrMsg ( "MoveDataThreadProc for step %i failed reading with error %i.\n", pS->i, GetLastError() );
217224
break;
@@ -236,6 +243,7 @@ unsigned __stdcall MoveDataThreadProc(void *pv)
236243
}
237244

238245
// pass data to output
246+
pS->bIsWriting = true;
239247
if (!pS->fOutputIsSocket){
240248
if( !WriteFile(pS->hOutput, pS->pBuff, bytesread, &byteswritten, NULL) ) {
241249
stderrMsg ( "MoveDataThreadProc for step %i failed WriteFile with error %i.\n", pS->i, GetLastError() );
@@ -261,6 +269,7 @@ unsigned __stdcall MoveDataThreadProc(void *pv)
261269
}
262270

263271

272+
pS->bIsWriting = false;
264273
debugMsg ( "MoveDataThreadProc for step %i ending.\n", pS->i );
265274
if (!pS->fOutputIsSocket) {
266275
if (!FlushFileBuffers(pS->hOutput)) {
@@ -596,7 +605,7 @@ DWORD main(int argc, char **argv)
596605
fDie = true;
597606
}
598607
for( int i=0; i<numSteps; ++i ){
599-
if( info[i].fIsWorkerThread ){
608+
if( info[i].fIsWorkerThread && !info[i].bIsWriting){
600609
if( 0==info[i].WatchDog ) {
601610
stderrMsg( "Watchdog expired - Thread for step %i stalled.\n", i );
602611
if (bWatchdogEnabled) fDie = true;

0 commit comments

Comments
 (0)