added a first "minimal" example - splitted code to be prepared for generator
[libt2n] / examples / minimalistic-server.cpp
diff --git a/examples/minimalistic-server.cpp b/examples/minimalistic-server.cpp
new file mode 100644 (file)
index 0000000..46cb9ec
--- /dev/null
@@ -0,0 +1,42 @@
+/***************************************************************************
+ *   Copyright (C) 2004 by Intra2net AG                                    *
+ *   info@intra2net.com                                                    *
+ *                                                                         *
+ ***************************************************************************/
+
+#include <string>
+#include <stdexcept>
+
+#include "minimalistic-stub.hxx"
+
+#include <socket_server.hxx>
+#include <command_server.hxx>
+
+using namespace std;
+
+LIBT2P_EXPORT string testfunc(const string& str) 
+{
+    string ret;
+    if (str=="throw")
+        throw libt2n::t2n_runtime_error("throw me around");
+    if (str=="big")
+        ret.insert(0,100*1024,'x');
+    else
+        ret=str+", testfunc() was here";
+    return ret;
+}
+
+using namespace libt2n;
+
+int main(int argc, char** argv) {
+  extended_type_info_test();
+
+  socket_server ss("./socket");
+  group_command_server<cmd_group_example> cs(ss);
+
+  // handle requests (without timeout)
+  while(true)
+    cs.handle();
+
+  return 0;
+}