mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-17 20:02:54 +00:00

The main advantage is that the new code is much shorter and easier to understand then the preivous one. It currently still used the network::error class on some places This also removed support for 'ping' packages, the plan is to replace it with SO_KEEPALIVE Also this temporaily breaks the gui2 lobby since it still uses the old network code.
44 lines
1.5 KiB
C++
44 lines
1.5 KiB
C++
|
|
|
|
#ifndef PLAYTURN_NETWORK_ADAPTER_HPP_INCLUDED
|
|
#define PLAYTURN_NETWORK_ADAPTER_HPP_INCLUDED
|
|
|
|
#include "config.hpp"
|
|
#include <list>
|
|
#include "utils/functional.hpp"
|
|
/*
|
|
The purpose if this class is to preprocess incoming network data, and provide a steam that always returns just one command/action at a time.
|
|
Especially we want each replay command in his own [turn].
|
|
*/
|
|
class playturn_network_adapter
|
|
{
|
|
public:
|
|
typedef std::function<bool(config&)> source_type;
|
|
|
|
playturn_network_adapter(source_type source);
|
|
~playturn_network_adapter();
|
|
|
|
//returns true on success.
|
|
//dst has to be empty before the call.
|
|
//after the call dst contains one child when returned true otherwise it's empty.
|
|
bool read(config& dst);
|
|
//returns false if there is still data in the internal buffer.
|
|
bool is_at_end();
|
|
void set_source(source_type source);
|
|
//returns a function to be passed to set_source.
|
|
static source_type get_source_from_config(config& src);
|
|
private:
|
|
//reads data from the network stream.
|
|
void read_from_network();
|
|
//this always contains one empty config because we want a valid value for next_.
|
|
std::list<config> data_;
|
|
//the position of the next to be received element in data_->front().
|
|
config::all_children_iterator next_;
|
|
//if we are processing a [turn] with multiple [command] we want to split them.
|
|
//In this case next_command_num_ is the next to be processed turn into a command otherwise it's 0;
|
|
unsigned int next_command_num_;
|
|
//a function to receive data from the network.
|
|
source_type network_reader_;
|
|
};
|
|
#endif
|