1
0
Fork 0
mirror of https://gitlab.com/niansa/llama_any.git synced 2025-03-06 20:48:27 +01:00
llama_any/Client.hpp
2023-04-03 22:06:29 +02:00

45 lines
1,021 B
C++

#ifndef CLIENT_HPP
#define CLIENT_HPP
#include "Runtime.hpp"
#include "Socket.hpp"
#include "Sender.hpp"
#include "Receiver.hpp"
#include <string>
#include <string_view>
#include <stdexcept>
#include <memory>
#include <functional>
#ifndef PLATFORM_WINDOWS
# include <netdb.h>
#else
# include <ws2tcpip.h>
#endif
class Client
{
struct Exception : public std::runtime_error {
using std::runtime_error::runtime_error;
};
int fd = -1;
# ifdef HAS_ADDRINFO
addrinfo
# else
bool sent = false;
hostent
# endif
*addrInfo; // Can't be null unless request has already been sent
std::unique_ptr<SocketConnection<Sender::Simple, Receiver::Simple>> connection;
void fetchAddr(const std::string& addr, unsigned port);
public:
Client(const std::string &addr, unsigned port);
void ask(std::string_view prompt, const std::function<void (unsigned progress)>& on_progress, const std::function<void (std::string_view token)>& on_token);
};
#endif // CLIENT_HPP