]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/prometheus-cpp/3rdparty/civetweb/conan/test_package/test_package.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / third_party / prometheus-cpp / 3rdparty / civetweb / conan / test_package / test_package.cpp
1 /*
2 * Copyright (c) 2018-2020 the CivetWeb developers
3 * MIT License
4 */
5
6 /* Simple demo of a REST callback. */
7 #ifdef _WIN32
8 #include <windows.h>
9 #else
10 #include <unistd.h>
11 #endif
12
13 #include <stdlib.h>
14 #include <string.h>
15 #include <time.h>
16
17 #include "civetweb.h"
18
19 #define PORT "8080"
20 #define HOST_INFO "http://localhost:8080"
21 #define EXAMPLE_URI "/example"
22
23 static int exitNow = 0;
24
25 static int
26 ExampleGET(struct mg_connection* conn)
27 {
28 mg_send_http_ok(conn, "text/plain", 10);
29 exitNow = 1;
30 return 200;
31 }
32
33 static int
34 ExampleHandler(struct mg_connection *conn, void *cbdata)
35 {
36 const struct mg_request_info *ri = mg_get_request_info(conn);
37 (void)cbdata; /* currently unused */
38
39 if (0 == strcmp(ri->request_method, "GET")) {
40 return ExampleGET(conn);
41 }
42 return 405;
43 }
44
45 int
46 log_message(const struct mg_connection *conn, const char *message)
47 {
48 puts(message);
49 return 1;
50 }
51
52 int
53 main(int argc, char *argv[])
54 {
55 struct mg_callbacks callbacks;
56 struct mg_context *ctx;
57 time_t start_t;
58 time_t end_t;
59 double diff_t;
60 int err = 0;
61
62 mg_init_library(0);
63
64 /* Callback will print error messages to console */
65 memset(&callbacks, 0, sizeof(callbacks));
66 callbacks.log_message = log_message;
67
68 /* Start CivetWeb web server */
69 ctx = mg_start(&callbacks, 0, NULL);
70
71 /* Check return value: */
72 if (ctx == NULL) {
73 fprintf(stderr, "Cannot start CivetWeb - mg_start failed.\n");
74 return EXIT_FAILURE;
75 }
76
77 /* Add handler EXAMPLE_URI, to explain the example */
78 mg_set_request_handler(ctx, EXAMPLE_URI, ExampleHandler, 0);
79
80 /* Show sone info */
81 printf("Start example: %s%s\n", HOST_INFO, EXAMPLE_URI);
82
83
84 /* Wait until the server should be closed */
85 time(&start_t);
86 while (!exitNow) {
87 #ifdef _WIN32
88 Sleep(1000);
89 #else
90 sleep(1);
91 #endif
92 time(&end_t);
93 diff_t = difftime(end_t, start_t);
94 if (diff_t > 3.0) {
95 break;
96 }
97 }
98
99 /* Stop the server */
100 mg_stop(ctx);
101 return EXIT_SUCCESS;
102 }