summaryrefslogtreecommitdiff
path: root/chardev.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'chardev.hpp')
-rw-r--r--chardev.hpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/chardev.hpp b/chardev.hpp
new file mode 100644
index 0000000..0a0d9df
--- /dev/null
+++ b/chardev.hpp
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: Unlicense
+ */
+
+#pragma once
+
+#include <cstdint>
+#include <cstddef>
+
+enum class CharDevType: uint8_t {
+ kUndefined = 0,
+ kPty, ///< Creates new PTY
+ kTcp, ///< Binds and listens to specified address and port
+};
+
+struct CharDev {
+ CharDevType type{};
+ const char* path{};
+ int fd{-1};
+ size_t path_len{};
+ uint16_t port{};
+ static CharDev Invalid(const char* path = nullptr)
+ {
+ return CharDev{CharDevType::kUndefined, path};
+ }
+ static CharDev Pty(void) { return CharDev{CharDevType::kPty}; }
+ static CharDev Tcp(const char* host, size_t path_len, uint16_t port)
+ {
+ return CharDev{CharDevType::kTcp, host, -1, path_len, port};
+ }
+ static CharDev Parse(const char* path);
+};
+