Fix #187, use \n instead of std::endl

This little PR fixes #187, while also replacing std::endl with '\n' in
the examples, since most of the time you don't want to flush the output
when outputting a newline.
parent c6569c13
...@@ -17,9 +17,8 @@ ...@@ -17,9 +17,8 @@
#endif #endif
using namespace Pistache; using namespace Pistache;
using namespace Pistache::Http;
class XProtocolVersion : public Header::Header { class XProtocolVersion : public Http::Header::Header {
public: public:
NAME("X-Protocol-Version"); NAME("X-Protocol-Version");
...@@ -68,5 +67,5 @@ private: ...@@ -68,5 +67,5 @@ private:
}; };
int main() { int main() {
Header::Registry::instance().registerHeader<XProtocolVersion>(); Http::Header::Registry::instance().registerHeader<XProtocolVersion>();
} }
...@@ -11,11 +11,10 @@ ...@@ -11,11 +11,10 @@
#include <pistache/net.h> #include <pistache/net.h>
using namespace Pistache; using namespace Pistache;
using namespace Pistache::Http;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
if (argc < 2) { if (argc < 2) {
std::cerr << "Usage: http_client page [count]" << std::endl; std::cerr << "Usage: http_client page [count]" << '\n';
return 1; return 1;
} }
...@@ -42,10 +41,10 @@ int main(int argc, char *argv[]) { ...@@ -42,10 +41,10 @@ int main(int argc, char *argv[]) {
resp.then( resp.then(
[&](Http::Response response) { [&](Http::Response response) {
++completedRequests; ++completedRequests;
std::cout << "Response code = " << response.code() << std::endl; std::cout << "Response code = " << response.code() << '\n';
auto body = response.body(); auto body = response.body();
if (!body.empty()) if (!body.empty())
std::cout << "Response body = " << body << std::endl; std::cout << "Response body = " << body << '\n';
}, },
[&](std::exception_ptr exc) { [&](std::exception_ptr exc) {
++failedRequests; ++failedRequests;
...@@ -60,17 +59,17 @@ int main(int argc, char *argv[]) { ...@@ -60,17 +59,17 @@ int main(int argc, char *argv[]) {
barrier.wait_for(std::chrono::seconds(5)); barrier.wait_for(std::chrono::seconds(5));
auto end = std::chrono::system_clock::now(); auto end = std::chrono::system_clock::now();
std::cout << "Summary of execution" << std::endl std::cout << "Summary of execution\n"
<< "Total number of requests sent : " << count << std::endl << "Total number of requests sent : " << count << '\n'
<< "Total number of responses received: " << "Total number of responses received: "
<< completedRequests.load() << std::endl << completedRequests.load() << '\n'
<< "Total number of requests failed : " << failedRequests.load() << "Total number of requests failed : " << failedRequests.load()
<< std::endl << '\n'
<< "Total time of execution : " << "Total time of execution : "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end - << std::chrono::duration_cast<std::chrono::milliseconds>(end -
start) start)
.count() .count()
<< "ms" << std::endl; << "ms\n";
client.shutdown(); client.shutdown();
} }
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include <pistache/endpoint.h> #include <pistache/endpoint.h>
#include <pistache/common.h> #include <pistache/common.h>
using namespace std;
using namespace Pistache; using namespace Pistache;
struct LoadMonitor { struct LoadMonitor {
...@@ -58,9 +57,9 @@ private: ...@@ -58,9 +57,9 @@ private:
if (global > 100) global = 100; if (global > 100) global = 100;
if (global > 1) if (global > 1)
std::cout << "Global load is " << global << "%" << std::endl; std::cout << "Global load is " << global << "%\n";
else else
std::cout << "Global load is 0%" << std::endl; std::cout << "Global load is 0%\n";
}, },
Async::NoExcept); Async::NoExcept);
...@@ -85,7 +84,7 @@ class MyHandler : public Http::Handler { ...@@ -85,7 +84,7 @@ class MyHandler : public Http::Handler {
auto query = req.query(); auto query = req.query();
if (query.has("chunked")) { if (query.has("chunked")) {
std::cout << "Using chunked encoding" << std::endl; std::cout << "Using chunked encoding\n";
response.headers() response.headers()
.add<Header::Server>("pistache/0.1") .add<Header::Server>("pistache/0.1")
...@@ -131,7 +130,7 @@ class MyHandler : public Http::Handler { ...@@ -131,7 +130,7 @@ class MyHandler : public Http::Handler {
else if (req.resource() == "/static") { else if (req.resource() == "/static") {
if (req.method() == Http::Method::Get) { if (req.method() == Http::Method::Get) {
Http::serveFile(response, "README.md").then([](ssize_t bytes) { Http::serveFile(response, "README.md").then([](ssize_t bytes) {
std::cout << "Sent " << bytes << " bytes" << std::endl; std::cout << "Sent " << bytes << " bytes\n";
}, Async::NoExcept); }, Async::NoExcept);
} }
} else { } else {
...@@ -165,8 +164,8 @@ int main(int argc, char *argv[]) { ...@@ -165,8 +164,8 @@ int main(int argc, char *argv[]) {
Address addr(Ipv4::any(), port); Address addr(Ipv4::any(), port);
cout << "Cores = " << hardware_concurrency() << endl; std::cout << "Cores = " << hardware_concurrency() << '\n';
cout << "Using " << thr << " threads" << endl; std::cout << "Using " << thr << " threads\n";
auto server = std::make_shared<Http::Endpoint>(addr); auto server = std::make_shared<Http::Endpoint>(addr);
......
...@@ -8,7 +8,7 @@ public: ...@@ -8,7 +8,7 @@ public:
HTTP_PROTOTYPE(HelloHandler) HTTP_PROTOTYPE(HelloHandler)
void onRequest(const Http::Request& request, Http::ResponseWriter response) override{ void onRequest(const Http::Request& request, Http::ResponseWriter response) override {
UNUSED(request); UNUSED(request);
response.send(Pistache::Http::Code::Ok, "Hello World\n"); response.send(Pistache::Http::Code::Ok, "Hello World\n");
} }
...@@ -38,11 +38,11 @@ int main() { ...@@ -38,11 +38,11 @@ int main() {
int status = sigwait(&signals, &signal); int status = sigwait(&signals, &signal);
if (status == 0) if (status == 0)
{ {
std::cout << "received signal " << signal << std::endl; std::cout << "received signal " << signal << '\n';
} }
else else
{ {
std::cerr << "sigwait returns " << status << std::endl; std::cerr << "sigwait returns " << status << '\n';
} }
server.shutdown(); server.shutdown();
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include <pistache/thirdparty/serializer/rapidjson.h> #include <pistache/thirdparty/serializer/rapidjson.h>
using namespace std;
using namespace Pistache; using namespace Pistache;
namespace Generic { namespace Generic {
...@@ -145,8 +144,8 @@ int main(int argc, char *argv[]) { ...@@ -145,8 +144,8 @@ int main(int argc, char *argv[]) {
Address addr(Ipv4::any(), port); Address addr(Ipv4::any(), port);
cout << "Cores = " << hardware_concurrency() << endl; std::cout << "Cores = " << hardware_concurrency() << '\n';
cout << "Using " << thr << " threads" << endl; std::cout << "Using " << thr << " threads" << '\n';
BankerService banker(addr); BankerService banker(addr);
......
...@@ -10,17 +10,16 @@ ...@@ -10,17 +10,16 @@
#include <pistache/router.h> #include <pistache/router.h>
#include <pistache/endpoint.h> #include <pistache/endpoint.h>
using namespace std;
using namespace Pistache; using namespace Pistache;
void printCookies(const Http::Request& req) { void printCookies(const Http::Request& req) {
auto cookies = req.cookies(); auto cookies = req.cookies();
std::cout << "Cookies: [" << std::endl; std::cout << "Cookies: [\n";
const std::string indent(4, ' '); const std::string indent(4, ' ');
for (const auto& c: cookies) { for (const auto& c: cookies) {
std::cout << indent << c.name << " = " << c.value << std::endl; std::cout << indent << c.name << " = " << c.value << '\n';
} }
std::cout << "]" << std::endl; std::cout << "]\n";
} }
namespace Generic { namespace Generic {
...@@ -158,8 +157,8 @@ int main(int argc, char *argv[]) { ...@@ -158,8 +157,8 @@ int main(int argc, char *argv[]) {
Address addr(Ipv4::any(), port); Address addr(Ipv4::any(), port);
cout << "Cores = " << hardware_concurrency() << endl; std::cout << "Cores = " << hardware_concurrency() << '\n';
cout << "Using " << thr << " threads" << endl; std::cout << "Using " << thr << " threads" << '\n';
StatsEndpoint stats(addr); StatsEndpoint stats(addr);
......
...@@ -32,8 +32,8 @@ fetchOp ...@@ -32,8 +32,8 @@ fetchOp
[](const User& user) { return fetchUserInfo(user); }, [](const User& user) { return fetchUserInfo(user); },
Async::Throw) Async::Throw)
.then( .then(
[](const UserInfo& info) { std::cout << "User name = " << info.name << std::endl; }, [](const UserInfo& info) { std::cout << "User name = " << info.name << '\n'; },
[](exception_ptr ptr) { std::cout << "An exception occured during user retrieval" << std::endl;} [](exception_ptr ptr) { std::cerr << "An exception occured during user retrieval\n";}
); );
``` ```
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment