diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..379ce1c07f5ce742ec95ad52eac7519261ce2979 --- /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 0000000000000000000000000000000000000000..78bb87ad7f5672bbc24ff61be4a5d8d125b04b5b --- /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 0000000000000000000000000000000000000000..cf5d8a6971a821471047cd57845935ad968f50f0 --- /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 0000000000000000000000000000000000000000..350be12fdb7e885da167ceb99bfbc07897835f86 --- /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 0000000000000000000000000000000000000000..a916a215c8689b45762b9f7787e669a7e6abf2e9 --- /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<