Created
November 17, 2016 10:39
-
-
Save michalpelka/d7b5ee940597fe9dc5032abdc979c75c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "pistache/endpoint.h" | |
#include <thread> | |
using namespace Net; | |
class HelloHandler : public Http::Handler { | |
public: | |
HTTP_PROTOTYPE(HelloHandler) | |
void onRequest(const Http::Request& request, Http::ResponseWriter response) { | |
//std::cout << "headers_" << request.headers() << "\n"; | |
std::cout << "method " << request.method() << "\n"; | |
std::cout << "resource " << request.resource() << "\n"; | |
std::cout << "id " << request.query().get("id").getOrElse("-") << "\n"; | |
response.send(Http::Code::Ok, "Hello World"); | |
} | |
}; | |
void th() | |
{ | |
Net::Address addr(Net::Ipv4::any(), Net::Port(9080)); | |
auto opts = Net::Http::Endpoint::options() | |
.threads(1); | |
Http::Endpoint server(addr); | |
server.init(opts); | |
server.setHandler(Http::make_handler<HelloHandler>()); | |
server.serve(); | |
server.shutdown(); | |
} | |
int main() { | |
std::thread t(th); | |
while (1) | |
{ | |
sleep(10); | |
} | |
std::cout << "Even here breakpoint cause crash\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment