MXVK Vulkan Framework 0.24.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
recv.cpp File Reference
#include "mxnetwork/socket.hpp"
#include <atomic>
#include <cstdlib>
#include <iostream>
#include <signal.h>
#include <string>
#include <vector>
#include <sys/socket.h>

Go to the source code of this file.

Functions

void exit_signal (int)
int main (int argc, char **argv)

Variables

std::atomic< bool > active_loop {false}

Function Documentation

◆ exit_signal()

void exit_signal ( int )

Definition at line 27 of file recv.cpp.

27 {
28 active_loop.store(false);
29}
std::atomic< bool > active_loop
Definition server.cpp:16

◆ main()

int main ( int argc,
char ** argv )

Definition at line 32 of file recv.cpp.

32 {
33
34 if (argc != 2) {
35 std::cerr << "Usage: " << argv[0] << " <path>\n";
36 return EXIT_FAILURE;
37 }
38#ifdef _WIN32
39 if (!SetConsoleCtrlHandler(console_handler, TRUE)) {
40 std::cerr << "Error setting console handler\n";
41 return EXIT_FAILURE;
42 }
43#else
44 struct sigaction sa = {};
45 sa.sa_handler = exit_signal;
46 sa.sa_flags = 0;
47 if (sigaction(SIGINT, &sa, nullptr) == -1) {
48 perror("sigaction");
49 return EXIT_FAILURE;
50 }
51#endif
52 try {
54 if (sock.bind_unix(argv[1])) {
55 std::cout << "Listening for UDP datagram on port " << argv[1] << "...\n";
56 std::vector<uint8_t> buffer(65536);
57 active_loop.store(true);
58 while (active_loop.load()) {
59 ssize_t bytes = sock.recvfrom(buffer.data(), buffer.size());
60 if (bytes > 0) {
61 std::cout << "Received " << bytes << " bytes.\n";
62 std::string data(buffer.begin(), buffer.end());
63 std::cout << "Data: " << data;
64 } else if (bytes < 0) {
65 if (errno == EINTR)
66 continue;
67 std::cerr << "read error.\n";
68 break;
69 }
70 }
71 }
72 } catch (const mxnetwork::Exception &e) {
73 std::cerr << "Exception: " << e.text() << "\n";
74 return EXIT_FAILURE;
75 }
76 return EXIT_SUCCESS;
77}
Lightweight exception wrapper for MXNetwork failures.
Definition exception.hpp:11
std::string text() const
Return the stored error text.
Definition exception.cpp:5
C++ wrapper around the MXNetwork socket API.
Definition socket.hpp:57
@ TYPE_UNIX_DGRAM
UNIX-domain datagram socket.
Definition socket.hpp:51
void exit_signal(int)
Definition server.cpp:27

Variable Documentation

◆ active_loop

std::atomic<bool> active_loop {false}

Definition at line 17 of file recv.cpp.

17{false};