nngn
Loading...
Searching...
No Matches
socket.h
Go to the documentation of this file.
1#ifndef NNGN_OS_SOCKET_H
2#define NNGN_OS_SOCKET_H
3
4#include <array>
5#include <string>
6#include <vector>
7
8#include "timing/profile.h"
9
10namespace nngn {
11
12class Socket {
13 class lock {
14 int fd = -1;
15 std::string m_path = {};
16 public:
17 lock() = default;
18 lock(const lock&) = delete;
19 lock(const lock&&) = delete;
20 lock &operator=(const lock&) = delete;
21 lock &operator=(const lock&&) = delete;
23 bool path(std::string_view path);
24 };
25 lock m_lock = {};
26 int fd = -1;
27 std::vector<std::byte> poll_data = {};
28 std::string path = {};
29 bool accept();
30 bool process(std::string *buffer);
31 bool recv(std::string *buffer);
32public:
34 Socket(const Socket&) = delete;
35 Socket(const Socket&&) = delete;
36 Socket &operator=(const Socket&) = delete;
37 Socket &operator=(const Socket&&) = delete;
39 bool init(std::string_view path);
40 template<typename F> bool process(F f);
41};
42
43template<typename F> bool Socket::process(F f) {
45 std::string buffer;
46 if(!this->process(&buffer))
47 return false;
48 if(!buffer.empty())
49 f(std::string_view{buffer});
50 return true;
51}
52
53}
54
55#endif
Definition: socket.h:13
lock(const lock &)=delete
lock(const lock &&)=delete
std::string m_path
Definition: socket.h:15
lock & operator=(const lock &&)=delete
lock & operator=(const lock &)=delete
bool path(std::string_view path)
Definition: socket.h:12
lock m_lock
Definition: socket.h:25
Socket & operator=(const Socket &)=delete
bool recv(std::string *buffer)
Socket & operator=(const Socket &&)=delete
Socket(const Socket &)=delete
bool process(F f)
std::vector< std::byte > poll_data
Definition: socket.h:27
std::string path
Definition: socket.h:28
Socket(const Socket &&)=delete
bool init(std::string_view path)
bool process(std::string *buffer)
function f()) end
#define NNGN_PROFILE_CONTEXT(p)
Definition: profile.h:18
std::chrono::duration< float, typename T::period > fd
Definition: timing.cpp:8
#define F(...)
Definition: pp.cpp:12
Definition: audio.cpp:7