-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex_signal.cpp
41 lines (30 loc) · 992 Bytes
/
ex_signal.cpp
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
// SPDX-License-Identifier: MIT
#include "../../sockets.h"
#include <cstdlib>
void signal_handler(int sig) {
static const char *text = "A signal has been caught!\n";
write(STDOUT_FILENO, text, strlen(text));
}
int main(int argc, char **argv) {
std::signal(SIGALRM, signal_handler);
alarm(3);
SOCKETS sockets;
printf("Initializing networking (SOCKETS v%s).\n", SOCKETS::VERSION);
if (!sockets.init()) {
printf("%s\n", "Failed to initialize sockets.");
return EXIT_FAILURE;
}
sockets.set_logger(
[](SOCKETS::SESSION, const char *txt) noexcept {
printf("Sockets: %s\n", txt);
}
);
printf("%s\n", "Sleeping indefinitely.");
SOCKETS::ERROR error;
if ((error = sockets.next_error()) != SOCKETS::NO_ERROR) {
printf("Error serving the sockets (%s).\n", sockets.to_string(error));
}
printf("%s\n", "Deinitializing networking.");
sockets.deinit();
return EXIT_SUCCESS;
}