-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.h
More file actions
42 lines (27 loc) · 735 Bytes
/
Client.h
File metadata and controls
42 lines (27 loc) · 735 Bytes
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
33
34
35
36
37
38
39
40
41
42
#ifndef OS_NET_MULTIPLEXING_CLIENT_H
#define OS_NET_MULTIPLEXING_CLIENT_H
#include "safe_poll.h"
#include <cstdint>
#include <atomic>
namespace rd {
struct active_socket {
int fd;
bool init();
bool connect(const char *addr, uint16_t port);
void close();
};
class Client {
static std::atomic<int> id_generator;
int id = ++id_generator;
active_socket sock{};
static const size_t SOCKET_BUFFER_SIZE = 1024;
char socket_buffer[SOCKET_BUFFER_SIZE]{};
static const size_t STDIN_BUFFER_SIZE = 1024;
char stdin_buffer[STDIN_BUFFER_SIZE]{};
public:
Client();
void run(const char *addr, uint16_t port, int input_fd = 0, int output_fd = 1);
void close();
};
}
#endif //OS_NET_MULTIPLEXING_CLIENT_H