-
Notifications
You must be signed in to change notification settings - Fork 39
Added samples with POCO C++ framework #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sim1angeloni
wants to merge
6
commits into
binaryspaceship:master
Choose a base branch
from
sim1angeloni:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b5b5814
Added samples using POCO C++ library
8483c3f
Minor improvements to the script and changes to compile under Linux
71774bf
Update bootstrap.sh
ea37811
!A benchmarks for POCO implementations
d1e45d4
Update Readme.md
c9fa446
Update Readme.md
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| build-libs/ |
This file contains hidden or 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
This file contains hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| cmake_minimum_required(VERSION 3.5) | ||
| project(main) | ||
|
|
||
| find_package(Poco REQUIRED COMPONENTS Foundation Net JSON Util) | ||
|
|
||
| add_executable(main main.cpp) | ||
| target_link_libraries(main | ||
| Poco::Foundation | ||
| Poco::Net | ||
| Poco::JSON | ||
| Poco::Util | ||
| ) |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| #include <Poco/Net/ServerSocket.h> | ||
| #include <Poco/Net/HTTPServer.h> | ||
| #include <Poco/Net/HTTPRequestHandler.h> | ||
| #include <Poco/Net/HTTPRequestHandlerFactory.h> | ||
| #include <Poco/Net/HTTPResponse.h> | ||
| #include <Poco/Net/HTTPServerRequest.h> | ||
| #include <Poco/Net/HTTPServerResponse.h> | ||
| #include <Poco/JSON/Object.h> | ||
| #include <Poco/JSON/Array.h> | ||
| #include <Poco/Util/ServerApplication.h> | ||
| #include <vector> | ||
| #include <string> | ||
|
|
||
| class HelloRequestHandler : public Poco::Net::HTTPRequestHandler | ||
| { | ||
| public: | ||
| virtual void handleRequest(Poco::Net::HTTPServerRequest &req, Poco::Net::HTTPServerResponse &resp) | ||
| { | ||
| resp.setStatus(Poco::Net::HTTPResponse::HTTP_OK); | ||
|
|
||
| Poco::JSON::Array JSONArray; | ||
|
|
||
| for (int i = 0; i < 10000; ++i) | ||
| { | ||
| Poco::JSON::Object::Ptr JSONObject = new Poco::JSON::Object(true); | ||
|
|
||
| std::string id("item-"); id += std::to_string(i); | ||
| JSONObject->set("id", id); | ||
| JSONObject->set("name", "Hello World"); | ||
| JSONObject->set("type", "application"); | ||
|
|
||
| JSONArray.add(Poco::Dynamic::Var(JSONObject)); | ||
| } | ||
|
|
||
| std::ostream& out = resp.send(); | ||
| JSONArray.stringify(out); | ||
| out.flush(); | ||
| } | ||
| }; | ||
|
|
||
| class HelloRequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory | ||
| { | ||
| public: | ||
| virtual Poco::Net::HTTPRequestHandler* createRequestHandler(const Poco::Net::HTTPServerRequest &) | ||
| { | ||
| return new HelloRequestHandler; | ||
| } | ||
| }; | ||
|
|
||
| class HelloServerApp : public Poco::Util::ServerApplication | ||
| { | ||
| protected: | ||
| int main(const std::vector<std::string> &) | ||
| { | ||
| Poco::Net::ServerSocket socket(Poco::Net::SocketAddress(Poco::Net::AddressFamily::IPv4, 9000)); | ||
| Poco::Net::HTTPServer s(new HelloRequestHandlerFactory, socket, new Poco::Net::HTTPServerParams); | ||
|
|
||
| s.start(); | ||
| waitForTerminationRequest(); | ||
| s.stop(); | ||
|
|
||
| return Application::EXIT_OK; | ||
| } | ||
| }; | ||
|
|
||
| int main(int argc, char** argv) | ||
| { | ||
| HelloServerApp app; | ||
| return app.run(argc, argv); | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| cmake_minimum_required(VERSION 3.5) | ||
| project(main) | ||
|
|
||
| find_package(Poco REQUIRED COMPONENTS Foundation Net JSON Util) | ||
| find_package(RapidJSON REQUIRED) | ||
|
|
||
| add_executable(main main.cpp) | ||
| target_include_directories(main PUBLIC ${RAPIDJSON_INCLUDE_DIRS}) | ||
| target_link_libraries(main | ||
| Poco::Foundation | ||
| Poco::Net | ||
| Poco::JSON | ||
| Poco::Util | ||
| ) |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #include <Poco/Net/ServerSocket.h> | ||
| #include <Poco/Net/HTTPServer.h> | ||
| #include <Poco/Net/HTTPRequestHandler.h> | ||
| #include <Poco/Net/HTTPRequestHandlerFactory.h> | ||
| #include <Poco/Net/HTTPResponse.h> | ||
| #include <Poco/Net/HTTPServerRequest.h> | ||
| #include <Poco/Net/HTTPServerResponse.h> | ||
| #include <Poco/Util/ServerApplication.h> | ||
| #include <vector> | ||
| #include <string> | ||
| #include <rapidjson/writer.h> | ||
| #include <rapidjson/stringbuffer.h> | ||
|
|
||
| class HelloRequestHandler : public Poco::Net::HTTPRequestHandler | ||
| { | ||
| public: | ||
| virtual void handleRequest(Poco::Net::HTTPServerRequest &req, Poco::Net::HTTPServerResponse &resp) | ||
| { | ||
| resp.setStatus(Poco::Net::HTTPResponse::HTTP_OK); | ||
|
|
||
| char _id[20]; | ||
|
|
||
| rapidjson::StringBuffer JSONBuffer; | ||
| rapidjson::Writer<rapidjson::StringBuffer> JSONWriter(JSONBuffer); | ||
| JSONWriter.StartArray(); | ||
|
|
||
| for (int i = 0; i < 10000; ++i) | ||
| { | ||
| JSONWriter.StartObject(); | ||
|
|
||
| snprintf(_id, sizeof(_id), "item-%d", i); | ||
| JSONWriter.Key("id"); JSONWriter.String(_id); | ||
| JSONWriter.Key("name"); JSONWriter.String("Hello World"); | ||
| JSONWriter.Key("type"); JSONWriter.String("application"); | ||
|
|
||
| JSONWriter.EndObject(); | ||
| } | ||
|
|
||
| JSONWriter.EndArray(); | ||
|
|
||
| std::ostream& out = resp.send(); | ||
| out << JSONBuffer.GetString(); | ||
| out.flush(); | ||
| } | ||
| }; | ||
|
|
||
| class HelloRequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory | ||
| { | ||
| public: | ||
| virtual Poco::Net::HTTPRequestHandler* createRequestHandler(const Poco::Net::HTTPServerRequest &) | ||
| { | ||
| return new HelloRequestHandler; | ||
| } | ||
| }; | ||
|
|
||
| class HelloServerApp : public Poco::Util::ServerApplication | ||
| { | ||
| protected: | ||
| int main(const std::vector<std::string> &) | ||
| { | ||
| Poco::Net::ServerSocket socket(Poco::Net::SocketAddress(Poco::Net::AddressFamily::IPv4, 9000)); | ||
| Poco::Net::HTTPServer s(new HelloRequestHandlerFactory, socket, new Poco::Net::HTTPServerParams); | ||
|
|
||
| s.start(); | ||
| waitForTerminationRequest(); | ||
| s.stop(); | ||
|
|
||
| return Application::EXIT_OK; | ||
| } | ||
| }; | ||
|
|
||
| int main(int argc, char** argv) | ||
| { | ||
| HelloServerApp app; | ||
| return app.run(argc, argv); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will ensure parallel compilation, if the systems allows it. It's a considerable speed up.