-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection_pool.h
53 lines (42 loc) · 1.05 KB
/
connection_pool.h
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
43
44
45
46
47
48
49
50
51
52
53
/** @file
* ConnectionPool declaration.
*
* Copyright 2020, Verizon Media
* SPDX-License-Identifier: Apache-2.0
*
*/
#pragma once
#include "connection.h"
#include <netdb.h>
#include <poll.h>
#include <sys/epoll.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <string>
#include <string_view>
#include <vector>
/**
* A pool of connection, this will be the class we use to do the testing
*/
class ConnectionPool
{
public:
ConnectionPool(unsigned int size, std::string_view host, std::string_view port);
ConnectionPool(const ConnectionPool &source) = delete;
ConnectionPool &operator=(const ConnectionPool &source) = delete;
void connect();
void state();
// this is where most of the work is done
void recycle();
void close();
private:
const std::string _server_name;
const std::string _server_port;
int _epollFd = 0;
std::vector<Connection> _connections;
std::vector<addrinfo *> _local_addresses;
epoll_event *_events = nullptr;
bool _usePoll = false;
struct pollfd *_pollFd = nullptr;
int _num_connections = 0;
};