slige/runtime/rpc_server.hpp

82 lines
1.4 KiB
C++
Raw Normal View History

2024-11-12 09:52:55 +01:00
#pragma once
2024-11-18 12:35:38 +01:00
#include <arpa/inet.h>
#include <netdb.h>
#include <stdlib.h>
2024-11-20 13:04:55 +01:00
#include <string>
2024-11-18 12:35:38 +01:00
#include <unistd.h>
2024-11-12 09:52:55 +01:00
namespace slige_rpc {
2024-11-20 13:04:55 +01:00
struct Err {
std::string msg;
};
template <typename T> class Res {
public:
Res(T value)
{
this->value = value;
this->holds_value = true;
}
Res(Err error)
{
this->error = error;
this->holds_value = false;
}
auto is_ok() -> bool { return this->holds_value; }
auto ok() -> T { return this->value; }
auto err() -> Err { return this->error; }
private:
bool holds_value;
T value;
Err error;
};
struct Unit { };
struct Req { };
class BufferedWriter {
BufferedWriter(int fd)
: fd(fd)
{
}
~BufferedWriter() { close(fd); }
auto flush() -> Res<size_t>;
auto write(uint8_t byte) -> Res<Unit>;
auto write(std::string message) -> Res<Unit>;
private:
static const size_t length = 1024;
size_t occupied = 0;
uint8_t buffer[length];
int fd;
};
2024-11-20 11:07:36 +01:00
/// - load code
/// - program input
/// - run
/// - run debug
/// - fwamegwaph option
/// - code covewage option
/// - fetch fwamegwaph
/// - json string
/// - fetch code covewage
/// - json string
/// - fetch stack
/// - json string
2024-11-20 13:04:55 +01:00
template <typename Functor> class RpcServer {
2024-11-12 09:52:55 +01:00
public:
2024-11-20 13:04:55 +01:00
RpcServer(Functor functor)
: functor(functor) {};
auto listen() -> Res<Unit>;
2024-11-18 12:35:38 +01:00
2024-11-20 11:07:36 +01:00
private:
2024-11-20 13:04:55 +01:00
Functor functor;
2024-11-18 12:35:38 +01:00
};
2024-11-20 13:04:55 +01:00
2024-11-18 12:35:38 +01:00
};