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 @@
#endif
using namespace Pistache;
using namespace Pistache::Http;
class XProtocolVersion : public Header::Header {
class XProtocolVersion : public Http::Header::Header {
public:
NAME("X-Protocol-Version");
......@@ -68,5 +67,5 @@ private:
};
int main() {
Header::Registry::instance().registerHeader<XProtocolVersion>();
Http::Header::Registry::instance().registerHeader<XProtocolVersion>();
}
......@@ -11,11 +11,10 @@
#include <pistache/net.h>
using namespace Pistache;
using namespace Pistache::Http;
int main(int argc, char *argv[]) {
if (argc < 2) {
std::cerr << "Usage: http_client page [count]" << std::endl;
std::cerr << "Usage: http_client page [count]" << '\n';
return 1;
}
......@@ -42,10 +41,10 @@ int main(int argc, char *argv[]) {
resp.then(
[&](Http::Response response) {
++completedRequests;
std::cout << "Response code = " << response.code() << std::endl;
std::cout << "Response code = " << response.code() << '\n';
auto body = response.body();
if (!body.empty())
std::cout << "Response body = " << body << std::endl;
std::cout << "Response body = " << body << '\n';
},
[&](std::exception_ptr exc) {
++failedRequests;
......@@ -60,17 +59,17 @@ int main(int argc, char *argv[]) {
barrier.wait_for(std::chrono::seconds(5));
auto end = std::chrono::system_clock::now();
std::cout << "Summary of execution" << std::endl
<< "Total number of requests sent : " << count << std::endl
std::cout << "Summary of execution\n"
<< "Total number of requests sent : " << count << '\n'
<< "Total number of responses received: "
<< completedRequests.load() << std::endl
<< completedRequests.load() << '\n'
<< "Total number of requests failed : " << failedRequests.load()
<< std::endl
<< '\n'
<< "Total time of execution : "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end -
start)
.count()
<< "ms" << std::endl;
<< "ms\n";
client.shutdown();
}
......@@ -12,7 +12,6 @@
#include <pistache/endpoint.h>
#include <pistache/common.h>
using namespace std;
using namespace Pistache;
struct LoadMonitor {
......@@ -58,9 +57,9 @@ private:
if (global > 100) global = 100;
if (global > 1)
std::cout << "Global load is " << global << "%" << std::endl;
std::cout << "Global load is " << global << "%\n";
else
std::cout << "Global load is 0%" << std::endl;
std::cout << "Global load is 0%\n";
},
Async::NoExcept);
......@@ -85,7 +84,7 @@ class MyHandler : public Http::Handler {
auto query = req.query();
if (query.has("chunked")) {
std::cout << "Using chunked encoding" << std::endl;
std::cout << "Using chunked encoding\n";
response.headers()
.add<Header::Server>("pistache/0.1")
......@@ -131,7 +130,7 @@ class MyHandler : public Http::Handler {
else if (req.resource() == "/static") {
if (req.method() == Http::Method::Get) {
Http::serveFile(response, "README.md").then([](ssize_t bytes) {
std::cout << "Sent " << bytes << " bytes" << std::endl;
std::cout << "Sent " << bytes << " bytes\n";
}, Async::NoExcept);
}
} else {
......@@ -165,8 +164,8 @@ int main(int argc, char *argv[]) {
Address addr(Ipv4::any(), port);
cout << "Cores = " << hardware_concurrency() << endl;
cout << "Using " << thr << " threads" << endl;
std::cout << "Cores = " << hardware_concurrency() << '\n';
std::cout << "Using " << thr << " threads\n";
auto server = std::make_shared<Http::Endpoint>(addr);
......
......@@ -8,7 +8,7 @@ public:
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);
response.send(Pistache::Http::Code::Ok, "Hello World\n");
}
......@@ -38,11 +38,11 @@ int main() {
int status = sigwait(&signals, &signal);
if (status == 0)
{
std::cout << "received signal " << signal << std::endl;
std::cout << "received signal " << signal << '\n';
}
else
{
std::cerr << "sigwait returns " << status << std::endl;
std::cerr << "sigwait returns " << status << '\n';
}
server.shutdown();
......
......@@ -10,7 +10,6 @@
#include <pistache/thirdparty/serializer/rapidjson.h>
using namespace std;
using namespace Pistache;
namespace Generic {
......@@ -145,8 +144,8 @@ int main(int argc, char *argv[]) {
Address addr(Ipv4::any(), port);
cout << "Cores = " << hardware_concurrency() << endl;
cout << "Using " << thr << " threads" << endl;
std::cout << "Cores = " << hardware_concurrency() << '\n';
std::cout << "Using " << thr << " threads" << '\n';
BankerService banker(addr);
......
......@@ -10,17 +10,16 @@
#include <pistache/router.h>
#include <pistache/endpoint.h>
using namespace std;
using namespace Pistache;
void printCookies(const Http::Request& req) {
auto cookies = req.cookies();
std::cout << "Cookies: [" << std::endl;
std::cout << "Cookies: [\n";
const std::string indent(4, ' ');
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 {
......@@ -158,8 +157,8 @@ int main(int argc, char *argv[]) {
Address addr(Ipv4::any(), port);
cout << "Cores = " << hardware_concurrency() << endl;
cout << "Using " << thr << " threads" << endl;
std::cout << "Cores = " << hardware_concurrency() << '\n';
std::cout << "Using " << thr << " threads" << '\n';
StatsEndpoint stats(addr);
......
......@@ -32,8 +32,8 @@ fetchOp
[](const User& user) { return fetchUserInfo(user); },
Async::Throw)
.then(
[](const UserInfo& info) { std::cout << "User name = " << info.name << std::endl; },
[](exception_ptr ptr) { std::cout << "An exception occured during user retrieval" << std::endl;}
[](const UserInfo& info) { std::cout << "User name = " << info.name << '\n'; },
[](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