From bef91567be528be724e189f71e6049a3433e8895 Mon Sep 17 00:00:00 2001 From: dongjulim Date: Fri, 15 Mar 2024 20:37:32 +0900 Subject: [PATCH] init --- .gitignore | 8 ++++ CMakeLists.txt | 15 ++++++++ filesystem_test.cpp | 58 ++++++++++++++++++++++++++++ http_test1.cpp | 63 ++++++++++++++++++++++++++++++ process_test.cpp | 24 ++++++++++++ thread_test.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 262 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 filesystem_test.cpp create mode 100644 http_test1.cpp create mode 100644 process_test.cpp create mode 100644 thread_test.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..379ce1c --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +/cmake-build-debug +/CMakeFiles +/Testing +.idea +*.cbp +cmake_install.cmake +Makefile +CMakeCache.txt \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..78bb87a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.19) +project(pocoTest) + +find_package(Poco CONFIG REQUIRED Foundation Net Util) + +set(CMAKE_CXX_STANDARD 14) + +add_executable(http_test1 http_test1.cpp) +add_executable(filesystem_test filesystem_test) +add_executable(process_test process_test.cpp) +add_executable(thread_test thread_test.cpp) + +target_link_libraries(http_test1 Poco::Foundation Poco::Net Poco::Util) +target_link_libraries(process_test Poco::Foundation Poco::Net Poco::Util) +target_link_libraries(thread_test Poco::Foundation Poco::Net Poco::Util) \ No newline at end of file diff --git a/filesystem_test.cpp b/filesystem_test.cpp new file mode 100644 index 0000000..cf5d8a6 --- /dev/null +++ b/filesystem_test.cpp @@ -0,0 +1,58 @@ +// +// Created by centos on 24. 3. 15.. +// + +// +// Created by centos on 24. 3. 13.. +// +#include "Poco/Foundation.h" +#include "Poco/TemporaryFile.h" +#include "Poco/Path.h" +#include "Poco/File.h" +#include "Poco/FileStream.h" +#include "Poco/TeeStream.h" +int file_path_test(); +int main() { + file_path_test(); +} + +int file_path_test(){ + Poco::Path path1 = Poco::Path::current(); + std::cout<> hello >> i; + reader.read7BitEncoded(i); + reader >> b; + return 0; +} \ No newline at end of file diff --git a/http_test1.cpp b/http_test1.cpp new file mode 100644 index 0000000..350be12 --- /dev/null +++ b/http_test1.cpp @@ -0,0 +1,63 @@ +#include "Poco/Net/HTTPServer.h" +#include "Poco/Net/HTTPRequestHandler.h" +#include "Poco/Net/HTTPRequestHandlerFactory.h" +#include "Poco/Net/HTTPServerRequest.h" +#include "Poco/Net/HTTPServerResponse.h" +#include "Poco/Net/ServerSocket.h" +#include "Poco/Util/ServerApplication.h" +#include + +using namespace Poco; +using namespace Poco::Net; +using namespace Poco::Util; + +class HelloRequestHandler: public HTTPRequestHandler +{ + void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) + { + Application& app = Application::instance(); + app.logger().information("Request from %s", request.clientAddress().toString()); + + response.setChunkedTransferEncoding(true); + response.setContentType("text/html"); + + response.send() + << "" + << "Hello" + << "

Hello from the POCO Web Server

" + << ""; + } +}; + +class HelloRequestHandlerFactory: public HTTPRequestHandlerFactory +{ + HTTPRequestHandler* createRequestHandler(const HTTPServerRequest&) + { + return new HelloRequestHandler; + } +}; + +class WebServerApp: public ServerApplication +{ + void initialize(Application& self) + { + loadConfiguration(); + ServerApplication::initialize(self); + } + + int main(const std::vector&) + { + UInt16 port = static_cast(config().getUInt("port", 8080)); + + HTTPServer srv(new HelloRequestHandlerFactory, port); + srv.start(); + logger().information("HTTP Server started on port %hu.", port); + waitForTerminationRequest(); + logger().information("Stopping HTTP Server..."); + srv.stop(); + + return Application::EXIT_OK; + } +}; + +POCO_SERVER_MAIN(WebServerApp) \ No newline at end of file diff --git a/process_test.cpp b/process_test.cpp new file mode 100644 index 0000000..a916a21 --- /dev/null +++ b/process_test.cpp @@ -0,0 +1,24 @@ +// +// Created by centos on 24. 3. 15.. +// + +#include "Poco/Process.h" +#include "Poco/PipeStream.h" +#include "Poco/StreamCopier.h" +#include +#include + +int main(int argc, char** argv){ + if(argc!=1){ + std::cout<<"process test ... ok!"< arg; + arg.emplace_back("1"); + Poco::ProcessHandle ph = Poco::Process::launch("./process_test",arg,0,&outPipe,0); + Poco::PipeInputStream istr(outPipe); +// std::cout< +#include +int test1=0; +int test2=0; +bool test3=true; +class ThreadClass: public Poco::Runnable +{ +public: + ThreadClass(const std::string& arg1, int arg2){ + this->arg1=arg1; + this->arg2 = arg2; + } + void greet() + { + std::cout << "Hello, world!" << std::endl; + test1++; + } + void run() + { + for(int i=0;i<3;i++){ + usleep(100000); + std::cout<arg1<<" : "<arg2<arg2==1){ + if(this->arg1!="one"){ + test3=false; + } + } + if(this->arg2==2){ + if(this->arg1!="two"){ + test3=false; + } + } + if(this->arg2==3){ + if(this->arg1!="three"){ + test3=false; + } + } + } +private: + std::string arg1; + int arg2; +}; +int main(int argc, char** argv) +{ + //thread start & join + ThreadClass greeter("",0); + Poco::RunnableAdapter runnable(greeter, &ThreadClass::greet); + Poco::Thread thread[2]; + thread[0].start(runnable); + thread[1].start(runnable); + thread[0].join(); + thread[1].join(); + + //threadpool + ThreadClass run("",0); + for (int i = 0; i < 5; ++i) { + Poco::ThreadPool::defaultPool().start(run); + } + //thread all join + Poco::ThreadPool::defaultPool().joinAll(); + + + //argument passing ( 클래스의 인자로 전달하는 방식 ) + ThreadClass arg_test1("one",1); + ThreadClass arg_test2("two",2); + ThreadClass arg_test3("three",3); + Poco::RunnableAdapter argtst1(arg_test1, &ThreadClass::say_args); + Poco::RunnableAdapter argtst2(arg_test2, &ThreadClass::say_args); + Poco::RunnableAdapter argtst3(arg_test3, &ThreadClass::say_args); + Poco::Thread arg_thread[3]; + arg_thread[0].start(argtst1); + arg_thread[1].start(argtst2); + arg_thread[2].start(argtst3); + arg_thread[0].join(); + arg_thread[1].join(); + arg_thread[2].join(); + + + std::cout<