@@ -78,66 +78,66 @@ namespace web { namespace http
78
78
79
79
linux_connection_pool (boost::asio::io_service& io_service, utility::seconds idle_timeout) :
80
80
m_io_service (io_service),
81
- m_idle_timeout (idle_timeout)
81
+ m_timeout_secs (idle_timeout)
82
82
{}
83
83
84
84
~linux_connection_pool ()
85
85
{
86
- std::lock_guard<std::mutex> lock (m_conns_mutex );
87
- for (auto & conn : m_conns_list )
86
+ std::lock_guard<std::mutex> lock (m_connections_mutex );
87
+ for (auto & connection : m_connections )
88
88
{
89
- conn ->m_pool_timer .cancel ();
89
+ connection ->m_pool_timer .cancel ();
90
90
91
91
boost::system::error_code error;
92
- conn ->m_socket .shutdown (tcp::socket::shutdown_both, error);
93
- conn ->m_socket .close (error);
92
+ connection ->m_socket .shutdown (tcp::socket::shutdown_both, error);
93
+ connection ->m_socket .close (error);
94
94
}
95
95
}
96
96
97
- void put (std::shared_ptr<linux_connection> conn )
97
+ void put (std::shared_ptr<linux_connection> connection )
98
98
{
99
- std::lock_guard<std::mutex> lock (m_conns_mutex );
99
+ std::lock_guard<std::mutex> lock (m_connections_mutex );
100
100
101
- const int secs = static_cast <int >(m_idle_timeout .count ());
102
- conn ->m_pool_timer .expires_from_now (boost::posix_time::milliseconds (secs * 1000 ));
103
- conn ->m_pool_timer .async_wait (boost::bind (&linux_connection::handle_pool_timer, conn , boost::asio::placeholders::error));
101
+ const int secs = static_cast <int >(m_timeout_secs .count ());
102
+ connection ->m_pool_timer .expires_from_now (boost::posix_time::milliseconds (secs * 1000 ));
103
+ connection ->m_pool_timer .async_wait (boost::bind (&linux_connection::handle_pool_timer, connection , boost::asio::placeholders::error));
104
104
105
- m_conns_list .insert (conn );
105
+ m_connections .insert (connection );
106
106
}
107
107
108
108
std::shared_ptr<linux_connection> get ()
109
109
{
110
- std::lock_guard<std::mutex> lock (m_conns_mutex );
110
+ std::lock_guard<std::mutex> lock (m_connections_mutex );
111
111
112
- if (m_conns_list .empty ())
112
+ if (m_connections .empty ())
113
113
{
114
114
return std::make_shared<linux_connection>(shared_from_this (), m_io_service);
115
115
}
116
116
else
117
117
{
118
- (*m_conns_list .begin ())->m_pool_timer .cancel ();
119
- auto result (*m_conns_list .begin ());
118
+ (*m_connections .begin ())->m_pool_timer .cancel ();
119
+ auto result (*m_connections .begin ());
120
120
result->m_is_reused = true ;
121
- m_conns_list .erase (m_conns_list .begin ());
121
+ m_connections .erase (m_connections .begin ());
122
122
123
123
return result;
124
124
}
125
125
}
126
126
127
- void remove (std::shared_ptr<linux_connection> conn )
127
+ void remove (std::shared_ptr<linux_connection> connection )
128
128
{
129
- std::lock_guard<std::mutex> lock (m_conns_mutex );
130
- m_conns_list .erase (conn );
129
+ std::lock_guard<std::mutex> lock (m_connections_mutex );
130
+ m_connections .erase (connection );
131
131
}
132
132
133
133
private:
134
134
boost::asio::io_service& m_io_service;
135
- utility::seconds m_idle_timeout ;
136
- std::unordered_set<std::shared_ptr<linux_connection> > m_conns_list ;
137
- std::mutex m_conns_mutex ;
135
+ const utility::seconds m_timeout_secs ;
136
+ std::unordered_set<std::shared_ptr<linux_connection> > m_connections ;
137
+ std::mutex m_connections_mutex ;
138
138
};
139
139
140
- class linux_client_request_context : public request_context
140
+ class linux_client_request_context : public request_context , public std ::enable_shared_from_this<linux_client_request_context>
141
141
{
142
142
public:
143
143
static std::shared_ptr<request_context> create_request_context (std::shared_ptr<_http_client_communicator> &client, http_request &request);
@@ -185,14 +185,14 @@ namespace web { namespace http
185
185
void set_timer (const int secs)
186
186
{
187
187
m_timeout_timer.expires_from_now (boost::posix_time::milliseconds (secs * 1000 ));
188
- m_timeout_timer.async_wait (boost::bind (&linux_client_request_context::handle_timeout_timer, this , boost::asio::placeholders::error));
188
+ m_timeout_timer.async_wait (boost::bind (&linux_client_request_context::handle_timeout_timer, shared_from_this () , boost::asio::placeholders::error));
189
189
}
190
190
191
191
void reset_timer (const int secs)
192
192
{
193
193
if (m_timeout_timer.expires_from_now (boost::posix_time::milliseconds (secs * 1000 )) > 0 )
194
194
{
195
- m_timeout_timer.async_wait (boost::bind (&linux_client_request_context::handle_timeout_timer, this , boost::asio::placeholders::error));
195
+ m_timeout_timer.async_wait (boost::bind (&linux_client_request_context::handle_timeout_timer, shared_from_this () , boost::asio::placeholders::error));
196
196
}
197
197
}
198
198
@@ -223,7 +223,7 @@ namespace web { namespace http
223
223
}
224
224
}
225
225
226
- linux_client_request_context (std::shared_ptr<_http_client_communicator> &client, http_request request, std::shared_ptr<linux_connection> conn );
226
+ linux_client_request_context (std::shared_ptr<_http_client_communicator> &client, http_request request, std::shared_ptr<linux_connection> connection );
227
227
228
228
protected:
229
229
virtual void cleanup ()
@@ -980,23 +980,23 @@ namespace web { namespace http
980
980
}
981
981
982
982
linux_client_request_context::linux_client_request_context (std::shared_ptr<_http_client_communicator> &client, http_request request,
983
- std::shared_ptr<linux_connection> conn )
983
+ std::shared_ptr<linux_connection> connection )
984
984
: request_context(client, request)
985
985
, m_known_size(0 )
986
986
, m_needChunked(false )
987
987
, m_timedout(false )
988
988
, m_current_size(0 )
989
989
, m_timeout_timer(crossplat::threadpool::shared_instance().service())
990
- , m_conn(conn )
990
+ , m_conn(connection )
991
991
, m_close_socket_in_destructor(false )
992
992
{}
993
993
994
994
std::shared_ptr<request_context> linux_client_request_context::create_request_context (
995
995
std::shared_ptr<_http_client_communicator> &client, http_request &request)
996
996
{
997
997
auto client_cast (std::static_pointer_cast<linux_client>(client));
998
- auto conn (client_cast->m_pool ->get ());
999
- return std::make_shared<linux_client_request_context>(client, request, conn );
998
+ auto connection (client_cast->m_pool ->get ());
999
+ return std::make_shared<linux_client_request_context>(client, request, connection );
1000
1000
}
1001
1001
1002
1002
linux_client_request_context::~linux_client_request_context ()
0 commit comments