Skip to content
Snippets Groups Projects
Unverified Commit 835db83c authored by fireice-uk's avatar fireice-uk Committed by GitHub
Browse files

Merge pull request #1672 from aledomu/dev

Buffer output in each line
parents 35f58231 1d0ee719
No related branches found
No related tags found
No related merge requests found
...@@ -113,14 +113,6 @@ R"===( ...@@ -113,14 +113,6 @@ R"===(
*/ */
"daemon_mode" : false, "daemon_mode" : false,
/*
* Buffered output control.
* When running the miner through a pipe, standard output is buffered. This means that the pipe won't read
* each output line immediately. This can cause delays when running in background.
* Set this option to true to flush stdout after each line, so it can be read immediately.
*/
"flush_stdout" : false,
/* /*
* Output file * Output file
* *
......
...@@ -52,7 +52,7 @@ using namespace rapidjson; ...@@ -52,7 +52,7 @@ using namespace rapidjson;
*/ */
enum configEnum { enum configEnum {
aPoolList, sCurrency, bTlsSecureAlgo, iCallTimeout, iNetRetry, iGiveUpLimit, iVerboseLevel, bPrintMotd, iAutohashTime, aPoolList, sCurrency, bTlsSecureAlgo, iCallTimeout, iNetRetry, iGiveUpLimit, iVerboseLevel, bPrintMotd, iAutohashTime,
bFlushStdout, bDaemonMode, sOutputFile, iHttpdPort, sHttpLogin, sHttpPass, bPreferIpv4, bAesOverride, sUseSlowMem bDaemonMode, sOutputFile, iHttpdPort, sHttpLogin, sHttpPass, bPreferIpv4, bAesOverride, sUseSlowMem
}; };
struct configVal { struct configVal {
...@@ -73,7 +73,6 @@ configVal oConfigValues[] = { ...@@ -73,7 +73,6 @@ configVal oConfigValues[] = {
{ iVerboseLevel, "verbose_level", kNumberType }, { iVerboseLevel, "verbose_level", kNumberType },
{ bPrintMotd, "print_motd", kTrueType }, { bPrintMotd, "print_motd", kTrueType },
{ iAutohashTime, "h_print_time", kNumberType }, { iAutohashTime, "h_print_time", kNumberType },
{ bFlushStdout, "flush_stdout", kTrueType},
{ bDaemonMode, "daemon_mode", kTrueType }, { bDaemonMode, "daemon_mode", kTrueType },
{ sOutputFile, "output_file", kStringType }, { sOutputFile, "output_file", kStringType },
{ iHttpdPort, "httpd_port", kNumberType }, { iHttpdPort, "httpd_port", kNumberType },
...@@ -603,16 +602,6 @@ bool jconf::parse_config(const char* sFilename, const char* sFilenamePools) ...@@ -603,16 +602,6 @@ bool jconf::parse_config(const char* sFilename, const char* sFilenamePools)
} }
#endif // _WIN32 #endif // _WIN32
if (prv->configValues[bFlushStdout]->IsBool())
{
bool bflush = prv->configValues[bFlushStdout]->GetBool();
printer::inst()->set_flush_stdout(bflush);
if (bflush)
{
printer::inst()->print_msg(L0, "Flush stdout forced.");
}
}
std::string ctmp = GetMiningCoin(); std::string ctmp = GetMiningCoin();
std::transform(ctmp.begin(), ctmp.end(), ctmp.begin(), ::tolower); std::transform(ctmp.begin(), ctmp.end(), ctmp.begin(), ::tolower);
......
...@@ -156,7 +156,8 @@ printer::printer() ...@@ -156,7 +156,8 @@ printer::printer()
{ {
verbose_level = LINF; verbose_level = LINF;
logfile = nullptr; logfile = nullptr;
b_flush_stdout = false; // Windows doesn't do line buffering, so it needs to enable full buffering and manually flush the buffer
setvbuf(stdout, NULL, _IOFBF, BUFSIZ);
} }
bool printer::open_logfile(const char* file) bool printer::open_logfile(const char* file)
...@@ -191,30 +192,14 @@ void printer::print_msg(verbosity verbose, const char* fmt, ...) ...@@ -191,30 +192,14 @@ void printer::print_msg(verbosity verbose, const char* fmt, ...)
buf[bpos] = '\n'; buf[bpos] = '\n';
buf[bpos+1] = '\0'; buf[bpos+1] = '\0';
std::unique_lock<std::mutex> lck(print_mutex); print_str(buf);
fputs(buf, stdout);
if (b_flush_stdout)
{
fflush(stdout);
}
if(logfile != nullptr)
{
fputs(buf, logfile);
fflush(logfile);
}
} }
void printer::print_str(const char* str) void printer::print_str(const char* str)
{ {
std::unique_lock<std::mutex> lck(print_mutex); std::unique_lock<std::mutex> lck(print_mutex);
fputs(str, stdout); fputs(str, stdout);
fflush(stdout);
if (b_flush_stdout)
{
fflush(stdout);
}
if(logfile != nullptr) if(logfile != nullptr)
{ {
...@@ -223,7 +208,7 @@ void printer::print_str(const char* str) ...@@ -223,7 +208,7 @@ void printer::print_str(const char* str)
} }
} }
//Do a press any key for the windows folk. *insert any key joke here* // Do a press any key for the windows folk. *insert any key joke here*
#ifdef _WIN32 #ifdef _WIN32
void win_exit(int code) void win_exit(int code)
{ {
......
...@@ -35,7 +35,6 @@ public: ...@@ -35,7 +35,6 @@ public:
}; };
inline void set_verbose_level(size_t level) { verbose_level = (verbosity)level; } inline void set_verbose_level(size_t level) { verbose_level = (verbosity)level; }
inline void set_flush_stdout(bool status) { b_flush_stdout = status; }
void print_msg(verbosity verbose, const char* fmt, ...); void print_msg(verbosity verbose, const char* fmt, ...);
void print_str(const char* str); void print_str(const char* str);
bool open_logfile(const char* file); bool open_logfile(const char* file);
...@@ -45,7 +44,6 @@ private: ...@@ -45,7 +44,6 @@ private:
std::mutex print_mutex; std::mutex print_mutex;
verbosity verbose_level; verbosity verbose_level;
bool b_flush_stdout;
FILE* logfile; FILE* logfile;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment