summaryrefslogtreecommitdiff
path: root/chardev.hpp
blob: 0a0d9df6afd9b2c47e8a10b6dc2a389c2631715d (plain)
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
/* 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);
};