cpp-console-game/eRPC/Server.hpp

45 lines
710 B
C++
Raw Normal View History

2024-07-05 20:37:02 +01:00
#ifndef ERPC_SERVER_HPP
#define ERPC_SERVER_HPP
#include <string>
#include <functional>
#include <unordered_map>
namespace eRPC
{
class Server
{
public:
/**
* Construct a server on the given port.
*/
Server(int port);
/**
* Destroy the server.
*/
~Server();
/**
* Start the server loop.
*/
void start();
/**
* Stop the server loop.
*/
void stop();
/**
* Bind a method to a callback.
*/
void bindMethod(std::string method, std::function<void *()> callback);
private:
int sockfd;
bool running;
std::unordered_map<std::string, std::function<void *()>> methods;
};
}
#endif // ERPC_SERVER_HPP