Skip to content

Commit 361711b

Browse files
committed
Flush interactive console messages.
1 parent ab1bfa4 commit 361711b

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

src/server.cpp

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -48,41 +48,41 @@
4848
#define BS_INFORMATION_MESSAGE \
4949
"Runs a full bitcoin node in the global peer-to-peer network."
5050
#define BS_UNINITIALIZED_CHAIN \
51-
"The %1% directory is not initialized.\n"
51+
"The %1% directory is not initialized."
5252
#define BS_INITIALIZING_CHAIN \
53-
"Please wait while initializing %1% directory...\n"
53+
"Please wait while initializing %1% directory..."
5454
#define BS_INITCHAIN_DIR_NEW \
55-
"Failed to create directory %1% with error, '%2%'.\n"
55+
"Failed to create directory %1% with error, '%2%'."
5656
#define BS_INITCHAIN_DIR_EXISTS \
57-
"Failed because the directory %1% already exists.\n"
57+
"Failed because the directory %1% already exists."
5858
#define BS_INITCHAIN_DIR_TEST \
59-
"Failed to test directory %1% with error, '%2%'.\n"
59+
"Failed to test directory %1% with error, '%2%'."
6060
#define BS_SERVER_STARTING \
61-
"Press CTRL-C to stop server.\n"
61+
"Press CTRL-C to stop server."
6262
#define BS_SERVER_STARTED \
63-
"Server started.\n"
63+
"Server started."
6464
#define BS_SERVER_STOPPING \
65-
"Please wait while server is stopping...\n"
65+
"Please wait while server is stopping..."
6666
#define BS_SERVER_STOPPED \
67-
"Server stopped cleanly.\n"
67+
"Server stopped cleanly."
6868
#define BS_NODE_START_FAIL \
69-
"Node failed to start.\n"
69+
"Node failed to start."
7070
#define BS_NODE_STOP_FAIL \
71-
"Node failed to stop.\n"
71+
"Node failed to stop."
7272
#define BS_PUBLISHER_START_FAIL \
73-
"Publisher failed to start: %1%\n"
73+
"Publisher failed to start: %1%"
7474
#define BS_PUBLISHER_STOP_FAIL \
75-
"Publisher failed to stop.\n"
75+
"Publisher failed to stop."
7676
#define BS_USING_CONFIG_FILE \
77-
"Using config file: %1%\n"
77+
"Using config file: %1%"
7878
#define BS_INVALID_PARAMETER \
79-
"Error: %1%\n"
79+
"Error: %1%"
8080
#define BS_VERSION_MESSAGE \
8181
"\nVersion Information:\n\n" \
8282
"libbitcoin-server: %1%\n" \
8383
"libbitcoin-node: %2%\n" \
8484
"libbitcoin-blockchain: %3%\n" \
85-
"libbitcoin [%5%]: %4%\n"
85+
"libbitcoin [%5%]: %4%"
8686

8787
namespace libbitcoin {
8888
namespace server {
@@ -100,7 +100,7 @@ static void display_invalid_parameter(std::ostream& stream,
100100
// English-only hack to patch missing arg name in boost exception message.
101101
std::string clean_message(message);
102102
boost::replace_all(clean_message, "for option is invalid", "is invalid");
103-
stream << format(BS_INVALID_PARAMETER) % clean_message;
103+
stream << format(BS_INVALID_PARAMETER) % clean_message << std::endl;
104104
}
105105

106106
static void show_help(config_type& metadata, std::ostream& stream)
@@ -130,7 +130,7 @@ static void show_version(std::ostream& stream)
130130

131131
stream << format(BS_VERSION_MESSAGE) % LIBBITCOIN_SERVER_VERSION %
132132
LIBBITCOIN_NODE_VERSION % LIBBITCOIN_BLOCKCHAIN_VERSION %
133-
LIBBITCOIN_VERSION % coinnet;
133+
LIBBITCOIN_VERSION % coinnet << std::endl;
134134
}
135135

136136
static console_result init_chain(path& directory, std::ostream& output,
@@ -143,14 +143,15 @@ static console_result init_chain(path& directory, std::ostream& output,
143143
if (!create_directories(directory, code))
144144
{
145145
if (code.value() == 0)
146-
error << format(BS_INITCHAIN_DIR_EXISTS) % directory;
146+
error << format(BS_INITCHAIN_DIR_EXISTS) % directory << std::endl;
147147
else
148-
error << format(BS_INITCHAIN_DIR_NEW) % directory % code.message();
148+
error << format(BS_INITCHAIN_DIR_NEW) % directory % code.message()
149+
<< std::endl;
149150

150151
return console_result::failure;
151152
}
152153

153-
output << format(BS_INITIALIZING_CHAIN) % directory;
154+
output << format(BS_INITIALIZING_CHAIN) % directory << std::endl;
154155

155156
using namespace bc::chain;
156157
const auto& prefix = directory.generic_string();
@@ -175,10 +176,10 @@ static console_result verify_chain(path& directory, std::ostream& error)
175176
if (!exists(directory, code))
176177
{
177178
if (code.value() == 2)
178-
error << format(BS_UNINITIALIZED_CHAIN) % directory;
179+
error << format(BS_UNINITIALIZED_CHAIN) % directory << std::endl;
179180
else
180181
error << format(BS_INITCHAIN_DIR_TEST) % directory %
181-
code.message();
182+
code.message() << std::endl;
182183

183184
return console_result::failure;
184185
}
@@ -190,7 +191,7 @@ static console_result verify_chain(path& directory, std::ostream& error)
190191
static bool stopped = false;
191192
static void interrupt_handler(int)
192193
{
193-
echo() << BS_SERVER_STOPPING;
194+
std::cout << BS_SERVER_STOPPING << std::endl;
194195
stopped = true;
195196
}
196197

@@ -244,7 +245,7 @@ static console_result run(settings_type& config, std::ostream& output,
244245
if (result != console_result::okay)
245246
return result;
246247

247-
output << BS_SERVER_STARTING;
248+
output << BS_SERVER_STARTING << std::endl;
248249

249250
request_worker worker;
250251
worker.start(config);
@@ -255,7 +256,7 @@ static console_result run(settings_type& config, std::ostream& output,
255256
if (!publish.start(config))
256257
{
257258
error << format(BS_PUBLISHER_START_FAIL) %
258-
zmq_strerror(zmq_errno());
259+
zmq_strerror(zmq_errno()) << std::endl;
259260
return console_result::not_started;
260261
}
261262

@@ -265,11 +266,11 @@ static console_result run(settings_type& config, std::ostream& output,
265266
// Start the node last so subscriptions to new blocks don't miss anything.
266267
if (!full_node.start(config))
267268
{
268-
error << BS_NODE_START_FAIL;
269+
error << BS_NODE_START_FAIL << std::endl;
269270
return console_result::not_started;
270271
}
271272

272-
output << BS_SERVER_STARTED;
273+
output << BS_SERVER_STARTED << std::endl;
273274

274275
// Catch C signals for stopping the program.
275276
signal(SIGABRT, interrupt_handler);
@@ -286,15 +287,15 @@ static console_result run(settings_type& config, std::ostream& output,
286287

287288
if (config.publisher_enabled)
288289
if (!publish.stop())
289-
error << BS_PUBLISHER_STOP_FAIL;
290+
error << BS_PUBLISHER_STOP_FAIL << std::endl;
290291

291292
if (!full_node.stop())
292293
{
293-
error << BS_NODE_STOP_FAIL;
294+
error << BS_NODE_STOP_FAIL << std::endl;
294295
return console_result::failure;
295296
}
296297

297-
output << BS_SERVER_STOPPED;
298+
output << BS_SERVER_STOPPED << std::endl;
298299
return console_result::okay;
299300
}
300301

@@ -312,7 +313,7 @@ console_result dispatch(int argc, const char* argv[], std::istream&,
312313

313314
if (!configuration.settings.configuration.empty())
314315
output << format(BS_USING_CONFIG_FILE) %
315-
configuration.settings.configuration;
316+
configuration.settings.configuration << std::endl;
316317

317318
auto settings = configuration.settings;
318319
if (settings.help)

0 commit comments

Comments
 (0)