mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-06 22:36:34 +00:00
Wesnothd Connection: clarified data queues' nature by wrapping them in std::queue
I kept the underlying container an std::list like before.
This commit is contained in:
parent
2051e7fc5b
commit
1e9d649271
@ -182,7 +182,7 @@ void wesnothd_connection::send_data(const configr_of& request)
|
|||||||
// TODO: should I capture a shared_ptr for this?
|
// TODO: should I capture a shared_ptr for this?
|
||||||
io_service_.post([this, buf_ptr]() {
|
io_service_.post([this, buf_ptr]() {
|
||||||
DBG_NW << "In wesnothd_connection::send_data::lambda\n";
|
DBG_NW << "In wesnothd_connection::send_data::lambda\n";
|
||||||
send_queue_.push_back(buf_ptr);
|
send_queue_.push(buf_ptr);
|
||||||
|
|
||||||
if(send_queue_.size() == 1) {
|
if(send_queue_.size() == 1) {
|
||||||
send();
|
send();
|
||||||
@ -248,7 +248,7 @@ void wesnothd_connection::handle_write(const boost::system::error_code& ec, std:
|
|||||||
MPTEST_LOG;
|
MPTEST_LOG;
|
||||||
DBG_NW << "Written " << bytes_transferred << " bytes.\n";
|
DBG_NW << "Written " << bytes_transferred << " bytes.\n";
|
||||||
|
|
||||||
send_queue_.pop_front();
|
send_queue_.pop();
|
||||||
|
|
||||||
if(ec) {
|
if(ec) {
|
||||||
{
|
{
|
||||||
@ -332,7 +332,7 @@ void wesnothd_connection::handle_read(const boost::system::error_code& ec, std::
|
|||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(recv_queue_mutex_);
|
std::lock_guard<std::mutex> lock(recv_queue_mutex_);
|
||||||
recv_queue_.emplace_back(std::move(data));
|
recv_queue_.emplace(std::move(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
recv();
|
recv();
|
||||||
@ -395,7 +395,7 @@ bool wesnothd_connection::receive_data(config& result)
|
|||||||
std::lock_guard<std::mutex> lock(recv_queue_mutex_);
|
std::lock_guard<std::mutex> lock(recv_queue_mutex_);
|
||||||
if(!recv_queue_.empty()) {
|
if(!recv_queue_.empty()) {
|
||||||
result.swap(recv_queue_.front());
|
result.swap(recv_queue_.front());
|
||||||
recv_queue_.pop_front();
|
recv_queue_.pop();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
class config;
|
class config;
|
||||||
enum class loading_stage;
|
enum class loading_stage;
|
||||||
@ -159,8 +160,11 @@ private:
|
|||||||
void send();
|
void send();
|
||||||
void recv();
|
void recv();
|
||||||
|
|
||||||
std::list<std::shared_ptr<boost::asio::streambuf>> send_queue_;
|
template<typename T>
|
||||||
std::list<config> recv_queue_;
|
using data_queue = std::queue<T, std::list<T>>;
|
||||||
|
|
||||||
|
data_queue<std::shared_ptr<boost::asio::streambuf>> send_queue_;
|
||||||
|
data_queue<config> recv_queue_;
|
||||||
|
|
||||||
std::mutex recv_queue_mutex_;
|
std::mutex recv_queue_mutex_;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user