Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit 6fbaa7a

Browse files
author
hamidr
committed
Removing templateness of connection
1 parent 2e30934 commit 6fbaa7a

File tree

7 files changed

+34
-37
lines changed

7 files changed

+34
-37
lines changed

includes/connection.hpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,29 @@
1111

1212
namespace async_redis
1313
{
14-
template<typename InputOutputHandler>
1514
class connection
1615
{
17-
using async_socket = network::async_socket<InputOutputHandler>;
18-
using tcp_socket = network::tcp_socket<InputOutputHandler>;
19-
using unix_socket = network::unix_socket<InputOutputHandler>;
16+
using async_socket = network::async_socket;
17+
using tcp_socket = network::tcp_socket;
18+
using unix_socket = network::unix_socket;
2019

2120
public:
2221
using parser_t = parser::redis_response::parser;
2322
using reply_cb_t = std::function<void (parser_t)>;
2423

25-
connection(InputOutputHandler &event_loop)
24+
connection(event_loop::event_loop_ev& event_loop)
2625
: event_loop_(event_loop) {
2726
}
2827

29-
void connect(typename async_socket::connect_handler_t handler, const std::string& ip, int port)
28+
void connect(async_socket::connect_handler_t handler, const std::string& ip, int port)
3029
{
3130
if (!socket_ || !socket_->is_valid())
3231
socket_ = std::make_unique<tcp_socket>(event_loop_);
3332

3433
socket_->template async_connect<tcp_socket>(0, handler, ip, port);
3534
}
3635

37-
void connect(typename async_socket::connect_handler_t handler, const std::string& path)
36+
void connect(async_socket::connect_handler_t handler, const std::string& path)
3837
{
3938
if (!socket_ || !socket_->is_valid())
4039
socket_ = std::make_unique<unix_socket>(event_loop_);
@@ -116,7 +115,7 @@ namespace async_redis
116115
std::unique_ptr<async_socket> socket_;
117116
std::queue<std::tuple<reply_cb_t, parser_t>> req_queue_;
118117

119-
InputOutputHandler& event_loop_;
118+
event_loop::event_loop_ev& event_loop_;
120119
enum { max_data_size = 1024 };
121120
char data_[max_data_size];
122121
};

includes/monitor.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ namespace async_redis
1010
template<typename InputOutputHandler>
1111
class monitor
1212
{
13-
using async_socket = network::async_socket<InputOutputHandler>;
14-
using tcp_socket = network::tcp_socket<InputOutputHandler>;
15-
using unix_socket = network::unix_socket<InputOutputHandler>;
13+
using async_socket = network::async_socket;
14+
using tcp_socket = network::tcp_socket;
15+
using unix_socket = network::unix_socket;
1616

1717
public:
1818
enum EventState {

includes/network/async_socket.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <arpa/inet.h>
1111

1212
#include <string>
13+
#include <event_loop/event_loop_ev.h>
1314

1415
namespace async_redis {
1516
namespace network
@@ -22,20 +23,20 @@ namespace async_redis {
2223
class connect_socket_exception : socket_excetion {};
2324
class nonblocking_socket_exception : socket_excetion {};
2425

25-
template <typename InputOutputHanler>
2626
class async_socket
2727
{
2828
public:
29-
using socket_identifier_t = typename InputOutputHanler::socket_identifier_t;
29+
30+
using socket_identifier_t = event_loop::event_loop_ev::socket_identifier_t;
3031
using recv_cb_t = std::function<void (ssize_t)>;
3132
using ready_cb_t = std::function<void (ssize_t)>;
3233
using connect_handler_t = std::function<void (bool)>;
3334

34-
async_socket(InputOutputHanler& io)
35+
async_socket(event_loop::event_loop_ev& io)
3536
: io_(io)
3637
{ }
3738

38-
async_socket(InputOutputHanler &io, int fd)
39+
async_socket(event_loop::event_loop_ev &io, int fd)
3940
: io_(io)
4041
{
4142
fd_ = fd;
@@ -180,7 +181,7 @@ namespace async_redis {
180181

181182
private:
182183
bool is_connected_ = false;
183-
InputOutputHanler& io_;
184+
event_loop::event_loop_ev& io_;
184185
socket_identifier_t id_;
185186
int fd_ = -1;
186187
};

includes/network/tcp_socket.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@
55
namespace async_redis {
66
namespace network
77
{
8-
template<typename InputOutputHanler>
9-
class tcp_socket : public async_socket<InputOutputHanler>
8+
class tcp_socket : public async_socket
109
{
1110

1211
public:
13-
tcp_socket(InputOutputHanler& io)
14-
: async_socket<InputOutputHanler>(io)
12+
tcp_socket(event_loop::event_loop_ev& io)
13+
: async_socket(io)
1514
{
1615
this->create_socket(AF_INET);
1716
}
1817

19-
tcp_socket(InputOutputHanler& io, int fd)
20-
: async_socket<InputOutputHanler>(io, fd)
18+
tcp_socket(event_loop::event_loop_ev& io, int fd)
19+
: async_socket(io, fd)
2120
{}
2221

2322
bool bind(const string& host, int port)

includes/network/unix_socket.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@
55
namespace async_redis {
66
namespace network
77
{
8-
template<typename InputOutputHanler>
9-
class unix_socket : public async_socket<InputOutputHanler>
8+
class unix_socket : public async_socket
109
{
1110
public:
1211

1312
inline
14-
unix_socket(InputOutputHanler &io)
15-
: async_socket<InputOutputHanler>(io)
13+
unix_socket(event_loop::event_loop_ev &io)
14+
: async_socket(io)
1615
{
1716
this->create_socket(AF_UNIX);
1817
}
1918

2019
inline
21-
unix_socket(InputOutputHanler &io, int fd)
22-
: async_socket<InputOutputHanler>(io, fd)
20+
unix_socket(event_loop::event_loop_ev &io, int fd)
21+
: async_socket(io, fd)
2322
{}
2423

2524
int connect(const string& path) {

includes/redis_client.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,20 @@ namespace async_redis
1515
template<typename InputOutputHandler>
1616
class redis_client
1717
{
18-
using connection_t = connection<InputOutputHandler>;
19-
using reply_cb_t = typename connection_t::reply_cb_t;
20-
using connect_cb_t = typename async_redis::network::async_socket<InputOutputHandler>::connect_handler_t;
18+
using reply_cb_t = connection::reply_cb_t;
19+
using connect_cb_t = network::async_socket::connect_handler_t;
2120

2221
public:
2322
class connect_exception : std::exception {};
24-
using parser_t = typename connection_t::parser_t;
23+
using parser_t = connection::parser_t;
2524

2625
redis_client(InputOutputHandler &eventIO, int n = 1)
2726
: ev_loop_(eventIO)
2827
{
2928
conn_pool_.reserve(n);
3029

3130
for (int i = 0; i < conn_pool_.capacity(); ++i)
32-
conn_pool_.push_back(std::make_unique<connection_t>(ev_loop_));
31+
conn_pool_.push_back(std::make_unique<connection>(ev_loop_));
3332
}
3433

3534
bool is_connected() const
@@ -140,7 +139,7 @@ namespace async_redis
140139
pipelined_cbs_.push_back(std::move(reply));
141140
}
142141

143-
connection_t& get_connection()
142+
connection& get_connection()
144143
{
145144
auto &con = conn_pool_[con_rr_ctr_++];
146145
if (con_rr_ctr_ == conn_pool_.size())
@@ -173,7 +172,7 @@ namespace async_redis
173172
std::string pipeline_buffer_;
174173
bool pipelined_state_ = false;
175174
std::vector<reply_cb_t> pipelined_cbs_;
176-
std::vector<std::unique_ptr<connection_t>> conn_pool_;
175+
std::vector<std::unique_ptr<connection>> conn_pool_;
177176
int con_rr_ctr_ = 0;
178177
int connected_called_ = 0;
179178
bool is_connected_ = false;

includes/sentinel.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ namespace async_redis {
1616
template<typename InputOutputHandler>
1717
class sentinel
1818
{
19-
using socket_t = ::async_redis::network::tcp_socket<InputOutputHandler>;
19+
using socket_t = ::async_redis::network::tcp_socket;
2020
using connect_cb_t = typename socket_t::connect_handler_t;
2121

2222
using redis_resp_t = ::async_redis::parser::redis_response;
2323
using monitor_t = monitor<InputOutputHandler>;
24-
using connection_t = connection<InputOutputHandler>;
24+
using connection_t = connection;
2525

2626

2727
public:

0 commit comments

Comments
 (0)