From ef7fa6bcb273fedace340016e21d67019b6a99e3 Mon Sep 17 00:00:00 2001 From: cxl Date: Sat, 22 Sep 2012 16:28:50 +0000 Subject: [PATCH] examples: cmdsrv removed git-svn-id: svn://ultimatepp.org/upp/trunk@5387 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- examples/cmdsrv/cmdsrv.cpp | 120 ------------------------------------- examples/cmdsrv/cmdsrv.upp | 11 ---- 2 files changed, 131 deletions(-) delete mode 100644 examples/cmdsrv/cmdsrv.cpp delete mode 100644 examples/cmdsrv/cmdsrv.upp diff --git a/examples/cmdsrv/cmdsrv.cpp b/examples/cmdsrv/cmdsrv.cpp deleted file mode 100644 index d89b57007..000000000 --- a/examples/cmdsrv/cmdsrv.cpp +++ /dev/null @@ -1,120 +0,0 @@ -#include - -#ifdef PLATFORM_WIN32 -#include -#endif - -using namespace Upp; - -#define APP_VERSION "1.0.r2" -#define APP_DATE Date(2008, 9, 22) - -bool service_stopped = false; - -#ifdef PLATFORM_WIN32 -static BOOL WINAPI EventHandler(DWORD CtrlType) -{ - RLOG("EventHandler (CtrlType = " << (int)CtrlType << ")"); - if(CtrlType == CTRL_LOGOFF_EVENT) - RLOG("LOGOFF_EVENT (ignored)"); - else { - RLOG("exiting"); - service_stopped = true; - } - return true; -} - -void InstallSignalHandler() -{ - SetConsoleCtrlHandler(&EventHandler, true); -} -#endif - -#ifdef PLATFORM_POSIX -static void QuitSignal(int signal) -{ - RLOG("Received signal " << signal << ", quitting..."); - service_stopped = true; -} - -void InstallSignalHandler() -{ - signal(SIGPIPE, SIG_IGN); - signal(SIGINT, &QuitSignal); - signal(SIGTERM, &QuitSignal); - signal(SIGKILL, &QuitSignal); -} -#endif - -CONSOLE_APP_MAIN -{ - InstallSignalHandler(); - - HttpServer server; - int next_id = 0; - server.Logging(); - - Vector cmd; - cmd <<= CommandLine(); - int port = 1536; - if(cmd.GetCount() >= 1) - port = Nvl(ScanInt(cmd[0]), port); - - if(!server.Open(port)) { - puts(Socket::GetErrorText()); - return; - } - - while(!service_stopped) { - server.DelayedWrite(); - server.Wait(1000); - if(server.IsError()) { - puts("Server error: " + Socket::GetErrorText()); - puts("Reopening socket..."); - fflush(stdout); - if(!server.Reopen()) { - puts("Reopen on server socket failed: " + Socket::GetErrorText()); - return; - } - } - fputs(NFormat("\rserver(%d) running at %`", port, GetSysTime()), stdout); - fflush(stdout); - One request = server.GetRequest(); - if(!request) - continue; - HttpQuery query = request->GetQuery(); - String header, body; - int items = query.GetInt("ITEMS", 0, 100000, 10); - String svr = query.GetString("SVR"); - Htmls image_page; - int i; - image_page << - "CMDSRV, version " << APP_VERSION << ", release date: " << Format(APP_DATE) << "
\n" - "Copyright © 2005 Tomas Rylek

\n" - "CMDSRV parameters: <port number, default = 1536>

\n" - "Current parameters: cmdsrv " << port << "

\n" - "items (" << FormatInt(items) << ") = number of output lines to generate (default = 10)
\n" - "svr (" << (IsNull(svr) ? "empty" : "" + svr + "") - << ") = identifier for generated output lines (default = test)
\n" - "Example: http://localhost"; - String wisapi = GetFileName(query.GetString("$$WISAPI")); - String sample_query; - sample_query << "items=" << minmax(2 * items, 10, 100000) << "&svr=A"; - if(!IsNull(wisapi)) - image_page << "/dir/" << wisapi << "?"; - else - image_page << ':' << port << "/" << "any?"; - image_page << sample_query << "

\n"; - for(i = 0; i < items; i++) - image_page << "Line #" << (i + 1) << ", svr=" << UrlEncode(svr) << "
\n"; - image_page << "

\n" - "Current request:
\n"; - for(i = 0; i < query.GetCount(); i++) - image_page << ToHtml(query.GetKey(i)) << "=" << ToHtml(query.GetValue(i)) << "
\n"; - - header = HttpContentType(HttpTextHtml(CHARSET_WIN1252)); - body = HtmlTitlePage("Simple text HTTP server", image_page); - request->Write(header, body); - request.Clear(); - } -} diff --git a/examples/cmdsrv/cmdsrv.upp b/examples/cmdsrv/cmdsrv.upp deleted file mode 100644 index bbd72fbab..000000000 --- a/examples/cmdsrv/cmdsrv.upp +++ /dev/null @@ -1,11 +0,0 @@ -description "Simple HTTP text server"; - -uses - Web; - -file - cmdsrv.cpp; - -mainconfig - "" = ""; -