From e304b887d94a1c7fb9d83e9b21a26b26979ab647 Mon Sep 17 00:00:00 2001 From: sle118 Date: Sun, 27 Oct 2019 16:50:02 -0400 Subject: [PATCH 1/2] 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; } --- socketwrapper/socketwrapper.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/socketwrapper/socketwrapper.cpp b/socketwrapper/socketwrapper.cpp index 58ba340..03e6263 100755 --- a/socketwrapper/socketwrapper.cpp +++ b/socketwrapper/socketwrapper.cpp @@ -79,6 +79,11 @@ // Version 1.11 // Fix to stop socketwrapper not shutting down properly when input from stdin and output pipe is closed. // +// ++++++ +// Version 1.12 +// Fix to limit the watchdog on remote stream read. The watchdog will no longer stop the worker thread +// when waiting for LMS to read data. +// #include #include "stdafx.h" @@ -105,6 +110,7 @@ typedef struct HANDLE hInput; // input handle for process/thread HANDLE hOutput; // output handle for process/thread DWORD WatchDog; // watchdog for worker threads + BOOL bIsWriting; // true when stage thread is writing back to LMS server DWORD nBlocks; // number of "blocks" read DWORD nBytes; // number of bytes read } Stage; @@ -212,6 +218,7 @@ unsigned __stdcall MoveDataThreadProc(void *pv) } // wait for some data from input + pS->bIsWriting = false; if( !ReadFile(pS->hInput, pS->pBuff, BUFFER_SIZE, &bytesread, NULL) ) { stderrMsg ( "MoveDataThreadProc for step %i failed reading with error %i.\n", pS->i, GetLastError() ); break; @@ -236,6 +243,7 @@ unsigned __stdcall MoveDataThreadProc(void *pv) } // pass data to output + pS->bIsWriting = true; if (!pS->fOutputIsSocket){ if( !WriteFile(pS->hOutput, pS->pBuff, bytesread, &byteswritten, NULL) ) { stderrMsg ( "MoveDataThreadProc for step %i failed WriteFile with error %i.\n", pS->i, GetLastError() ); @@ -261,6 +269,7 @@ unsigned __stdcall MoveDataThreadProc(void *pv) } + pS->bIsWriting = false; debugMsg ( "MoveDataThreadProc for step %i ending.\n", pS->i ); if (!pS->fOutputIsSocket) { if (!FlushFileBuffers(pS->hOutput)) { @@ -596,7 +605,7 @@ DWORD main(int argc, char **argv) fDie = true; } for( int i=0; i Date: Wed, 2 Mar 2022 21:44:58 -0500 Subject: [PATCH 2/2] Untangling changes --- socketwrapper/socketwrapper.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/socketwrapper/socketwrapper.cpp b/socketwrapper/socketwrapper.cpp index 03e6263..24e7a47 100755 --- a/socketwrapper/socketwrapper.cpp +++ b/socketwrapper/socketwrapper.cpp @@ -88,8 +88,7 @@ #include #include "stdafx.h" #include "getopt.h" - -#define SW_ID "Socketwrapper 1.11beta\n" +#define SW_ID "Socketwrapper 1.12beta\n" // defines & global vars for extra thread mode #define MAX_STEPS 16 @@ -605,7 +604,7 @@ DWORD main(int argc, char **argv) fDie = true; } for( int i=0; i