-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice.cpp
More file actions
34 lines (26 loc) · 783 Bytes
/
service.cpp
File metadata and controls
34 lines (26 loc) · 783 Bytes
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
#include <os>
#include <chrono>
#include <net/inet4>
constexpr int port {13};
std::string make_daytime_string() {
time_t now = time(nullptr);
return ctime(&now);
}
void Service::start() {
using namespace std::chrono_literals;
auto& inet = net::Inet4::ifconfig(5.0, [](bool timeout) {
if (timeout) {
printf("DHCP TIMEOUT :(\n");
}
});
auto& server = inet.tcp().listen(port);
server.on_connect([] (auto conn) {
std::string response = make_daytime_string();
conn->write(response.data(), response.size());
conn->close();
});
Timers::periodic(5s, 30s, [&inet] (uint32_t) {
printf("<Service> TCP STATUS:\n%s\n", inet.tcp().status().c_str());
});
printf("*** DAYTIME SERVICE STARTED ***\n");
}