From c36dc43d0774f22b2fe2e135bc6f9bfbe35e4a00 Mon Sep 17 00:00:00 2001 From: hugbgithub Date: Mon, 21 Dec 2015 22:15:37 +0800 Subject: [PATCH 1/7] build with libprocess --- compile.sh | 1 + simpleserver.cpp | 123 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 compile.sh create mode 100644 simpleserver.cpp diff --git a/compile.sh b/compile.sh new file mode 100644 index 0000000..d1b2c69 --- /dev/null +++ b/compile.sh @@ -0,0 +1 @@ +g++ -std=c++11 simpleserver.cpp -lmesos diff --git a/simpleserver.cpp b/simpleserver.cpp new file mode 100644 index 0000000..e1642b4 --- /dev/null +++ b/simpleserver.cpp @@ -0,0 +1,123 @@ +/* + * simpleserver.cpp + * + * Created on: Jun 26, 2015 + * Author: Marco Massenzio, http://codetrips.com + * + * This code is explained in a blog entry at the above URL. + */ + +#include +#include +#include + +#include +#include +#include +#include + + +#include +#include + + +using std::cerr; +using std::cout; +using std::endl; + +using std::chrono::seconds; + +using process::Future; +using process::Promise; + +using process::http::Request; +using process::http::OK; +using process::http::InternalServerError; + + +class SimpleProcess : public process::Process { + +public: + SimpleProcess() : ProcessBase("simple") {} + + virtual void initialize(); + + Future done() { + cout << "are we done yet? " << endl; + return shouldQuit.future(); + } + + void shutdown() { + cout << "Shutting down server..." << endl; + this->shouldQuit.set(true); + } + +private: + Promise shouldQuit; +}; + + +void SimpleProcess::initialize() { + route( + "/add", + "Adds the two query arguments", + [] (Request request) { + int a = numify(request.query["a"]).get(); + int b = numify(request.query["b"]).get(); + std::ostringstream result; + result << "{ \"result\": " << a + b << "}"; + JSON::Value body = JSON::parse(result.str()).get(); + return OK(body); + }); + route( + "/quit", + "Shuts the server down", + [this] (Request request) { + this->shutdown(); + return OK("Shutting down server"); + }); + route( + "/error", + "Forces an Internal Server Error (500)", + [this](Request request) { + this->shouldQuit.set(false); + return InternalServerError("We encountered an error"); + }); +} + + +int runServer() { + int retCode; + SimpleProcess simpleProcess; + process::PID pid = process::spawn(simpleProcess); + + cout << "Running Server on http://" << process::address().ip << ":" + << process::address().port << "/simple" << endl + << "Use /quit to terminate server..." << endl; + + cout << "Waiting for it to terminate..." << endl; + Future quit = simpleProcess.done(); + quit.await(); + + // wait for the server to complete the request + std::this_thread::sleep_for(seconds(2)); + + if (!quit.get()) { + cerr << "The server encountered an error and is exiting now" << endl; + retCode = EXIT_FAILURE; + } else { + cout << "Done" << endl; + retCode = EXIT_SUCCESS; + } + + process::terminate(simpleProcess); + process::wait(simpleProcess); + return retCode; +} + +int main(int argc, char *argv[]){ + + return runServer(); + + +} From c3d9a8060c06830737285f473b34ae9e7db6c412 Mon Sep 17 00:00:00 2001 From: hugbgithub Date: Mon, 21 Dec 2015 22:43:57 +0800 Subject: [PATCH 2/7] Create my_test.c --- my_test.c | 1 + 1 file changed, 1 insertion(+) create mode 100644 my_test.c diff --git a/my_test.c b/my_test.c new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/my_test.c @@ -0,0 +1 @@ + From da993556f544e61b9fcb6ff4888dd82697c1a7b7 Mon Sep 17 00:00:00 2001 From: hugbgithub Date: Mon, 21 Dec 2015 22:48:18 +0800 Subject: [PATCH 3/7] Update my_test.c --- my_test.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/my_test.c b/my_test.c index 8b13789..c20c572 100644 --- a/my_test.c +++ b/my_test.c @@ -1 +1,3 @@ +#include + From 325884fc4f8d3d5dff8fa8a4201d1ab2310797b0 Mon Sep 17 00:00:00 2001 From: hugbgithub Date: Mon, 21 Dec 2015 22:55:25 +0800 Subject: [PATCH 4/7] write main func --- my_test.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/my_test.c b/my_test.c index c20c572..937cfc9 100644 --- a/my_test.c +++ b/my_test.c @@ -1,3 +1,11 @@ #include +int main(int argc , char *argv[]){ + + printf("prog name is %s\n", argv[0]); + + return 0; + +} + From 0332c8f02f2fdf68c6e43d699adb17e2b954b02e Mon Sep 17 00:00:00 2001 From: hugbgithub Date: Wed, 23 Dec 2015 21:03:33 +0800 Subject: [PATCH 5/7] branch file --- local_branch_to_add.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 local_branch_to_add.txt diff --git a/local_branch_to_add.txt b/local_branch_to_add.txt new file mode 100644 index 0000000..a330899 --- /dev/null +++ b/local_branch_to_add.txt @@ -0,0 +1 @@ +test branch From 17c7ac8157c7794a823e7132ac185bf1d05cb8ed Mon Sep 17 00:00:00 2001 From: hugbgithub Date: Fri, 25 Dec 2015 22:57:04 +0800 Subject: [PATCH 6/7] add watch list for mesos --- mesos_note/watch.list | 1 + 1 file changed, 1 insertion(+) create mode 100644 mesos_note/watch.list diff --git a/mesos_note/watch.list b/mesos_note/watch.list new file mode 100644 index 0000000..6217e96 --- /dev/null +++ b/mesos_note/watch.list @@ -0,0 +1 @@ +https://issues.apache.org/jira/browse/MESOS-2145 From c01f159ea4e85cc83001095f7690ab2231f9d8df Mon Sep 17 00:00:00 2001 From: hugbgithub Date: Wed, 2 Mar 2016 16:20:08 +0800 Subject: [PATCH 7/7] excep.cpp demonstrate stack unwind when throw exception, only automatic variables will be reclaimed --- excep.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 excep.cpp diff --git a/excep.cpp b/excep.cpp new file mode 100644 index 0000000..bf541a0 --- /dev/null +++ b/excep.cpp @@ -0,0 +1,84 @@ +#include +#include +#include +#include + +using namespace std; + +class MyException{}; +class Dummy +{ + public: + Dummy(string s) : MyName(s) { PrintMsg("Created Dummy:"); } + Dummy(const Dummy& other) : MyName(other.MyName){ PrintMsg("Copy created Dummy:"); } + ~Dummy(){ PrintMsg("Destroyed Dummy:"); } + void PrintMsg(string s) { cout << s << MyName << endl; } + string MyName; + int level; +}; + + +void C(Dummy d, int i) +{ + cout << "Entering FunctionC" << endl; + d.MyName = " C"; + throw MyException(); + + cout << "Exiting FunctionC" << endl; +} + +void B(Dummy d, int i) +{ + cout << "Entering FunctionB" << endl; + d.MyName = "B"; + C(d, i + 1); + cout << "Exiting FunctionB" << endl; +} + +void A(Dummy d, int i) +{ + cout << "Entering FunctionA" << endl; + d.MyName = " A" ; + //Dummy* pd = new Dummy("new Dummy"); //Not exception safe!!! + tr1::shared_ptr sp(new Dummy("new Dummy")); + B(d, i + 1); + //delete pd; + cout << "Exiting FunctionA" << endl; +} + + +int main() +{ + cout << "Entering main" << endl; + try + { + Dummy d(" M"); + A(d,1); + } + catch (MyException& e) + { + cout << "Caught an exception of type: " << typeid(e).name() << endl; + } + + cout << "Exiting main." << endl; + char c; + cin >> c; +} + +/* Output: + Entering main + Created Dummy: M + Copy created Dummy: M + Entering FunctionA + Copy created Dummy: A + Entering FunctionB + Copy created Dummy: B + Entering FunctionC + Destroyed Dummy: C + Destroyed Dummy: B + Destroyed Dummy: A + Destroyed Dummy: M + Caught an exception of type: class MyException + Exiting main. + +*/