-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cpp_server.cpp
More file actions
67 lines (57 loc) · 2.36 KB
/
test_cpp_server.cpp
File metadata and controls
67 lines (57 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* Pure C++ test of the HTTP server with CoroIO
* This tests the server WITHOUT Python callbacks to isolate the issue
*/
#include "src/cpp/http/http1_coroio_handler.h"
#include "src/cpp/http/server.h"
#include <iostream>
#include <thread>
#include <chrono>
int main() {
std::cout << "======================================================================" << std::endl;
std::cout << "FasterAPI Pure C++ HTTP Server Test" << std::endl;
std::cout << "======================================================================" << std::endl;
std::cout << std::endl;
// Create server config
HttpServer::Config config;
config.port = 9000;
config.host = "0.0.0.0";
config.enable_h1 = true;
config.enable_h2 = false;
config.enable_h3 = false;
config.enable_compression = false;
config.enable_websocket = false;
std::cout << "Creating HTTP server..." << std::endl;
HttpServer server(config);
std::cout << "✓ Server created!" << std::endl;
std::cout << std::endl;
std::cout << "Starting server on port 8000..." << std::endl;
int result = server.start();
if (result != 0) {
std::cerr << "✗ Failed to start server: error code " << result << std::endl;
return 1;
}
std::cout << "✓ Server started!" << std::endl;
std::cout << " Running: " << (server.is_running() ? "YES" : "NO") << std::endl;
std::cout << std::endl;
std::cout << "======================================================================" << std::endl;
std::cout << "Server is running on http://0.0.0.0:9000" << std::endl;
std::cout << "Test with: curl http://localhost:9000/" << std::endl;
std::cout << "Press Ctrl+C to stop..." << std::endl;
std::cout << "======================================================================" << std::endl;
std::cout << std::endl;
// Keep running
while (server.is_running()) {
std::this_thread::sleep_for(std::chrono::seconds(1));
auto stats = server.get_stats();
if (stats.total_requests > 0) {
std::cout << "\rRequests: " << stats.total_requests
<< ", Connections: " << stats.active_connections
<< ", Bytes sent: " << stats.total_bytes_sent
<< std::flush;
}
}
std::cout << std::endl;
std::cout << "Server stopped." << std::endl;
return 0;
}