#include "global.hpp"
#include "log.hpp"
#include "network_worker.hpp"
#include "network.hpp"
#include "thread.hpp"
#include "serialization/binary_or_text.hpp"
#include "serialization/binary_wml.hpp"
#include "serialization/parser.hpp"
#include <algorithm>
#include <cassert>
#include <cerrno>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <vector>
#include <boost/iostreams/filter/gzip.hpp>
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <sys/time.h>
#include <unistd.h>
Go to the source code of this file.
Namespaces | |
namespace | network_worker_pool |
Defines | |
#define | SOCKET int |
Network worker handles data transfers in threads Remember to use mutexs as little as possible All global vars should be used in mutex FIXME:. | |
#define | USE_SELECT 1 |
#define | DBG_NW LOG_STREAM(debug, network) |
#define | LOG_NW LOG_STREAM(info, network) |
#define | ERR_NW LOG_STREAM(err, network) |
#define | NUM_SHARDS 1 |
Typedefs | |
typedef std::vector< buffer * > | buffer_set |
typedef std::map< TCPsocket, schema_pair > | schema_map |
typedef std::vector< TCPsocket > | receive_list |
typedef std::deque< buffer * > | received_queue |
typedef std::map< TCPsocket, SOCKET_STATE > | socket_state_map |
typedef std::map< TCPsocket, std::pair< network::statistics, network::statistics > > | socket_stats_map |
Enumerations | |
enum | SOCKET_STATE { SOCKET_READY, SOCKET_LOCKED, SOCKET_ERRORED, SOCKET_INTERRUPT } |
Functions | |
size_t | get_shard (TCPsocket sock) |
int | receive_bytes (TCPsocket s, char *buf, size_t nbytes) |
void | check_send_buffer_size (TCPsocket &s) |
bool | receive_with_timeout (TCPsocket s, char *buf, size_t nbytes, bool update_stats=false, int timeout_ms=60000) |
static void | output_to_buffer (TCPsocket sock, const config &cfg, std::ostringstream &compressor, bool gzipped) |
static void | make_network_buffer (const char *input, int len, std::vector< char > &buf) |
static SOCKET_STATE | send_buffer (TCPsocket sock, std::vector< char > &buf) |
static SOCKET_STATE | receive_buf (TCPsocket sock, std::vector< char > &buf) |
void | check_socket_result (TCPsocket &sock, SOCKET_STATE &result) |
static int | process_queue (void *shard_num) |
network::pending_statistics | network_worker_pool::get_pending_stats () |
void | network_worker_pool::set_raw_data_only () |
void | network_worker_pool::receive_data (TCPsocket sock) |
Function to asynchronously received data to the given socket. | |
TCPsocket | network_worker_pool::get_received_data (TCPsocket sock, config &cfg) |
TCPsocket | network_worker_pool::get_received_data (std::vector< char > &out) |
void | network_worker_pool::queue_raw_data (TCPsocket sock, const char *buf, int len) |
void | network_worker_pool::queue_data (TCPsocket sock, const config &buf, const bool gzipped) |
void | network_worker_pool::remove_buffers (TCPsocket sock) |
Caller has to make sure to own the mutex for this shard. | |
bool | network_worker_pool::is_locked (const TCPsocket sock) |
bool | network_worker_pool::close_socket (TCPsocket sock, bool force) |
TCPsocket | network_worker_pool::detect_error () |
std::pair< network::statistics, network::statistics > | network_worker_pool::get_current_transfer_stats (TCPsocket sock) |
Variables | |
unsigned int | waiting_threads [NUM_SHARDS] |
size_t | min_threads = 0 |
size_t | max_threads = 0 |
bool | managed = false |
bool | raw_data_only = false |
buffer_set | outgoing_bufs [NUM_SHARDS] |
schema_map | schemas |
receive_list | pending_receives [NUM_SHARDS] |
received_queue | received_data_queue |
socket_state_map | sockets_locked [NUM_SHARDS] |
socket_stats_map | transfer_stats |
int | socket_errors [NUM_SHARDS] |
threading::mutex * | shard_mutexes [NUM_SHARDS] |
threading::mutex * | stats_mutex = NULL |
threading::mutex * | schemas_mutex = NULL |
threading::mutex * | received_mutex = NULL |
threading::condition * | cond [NUM_SHARDS] |
std::map< Uint32, threading::thread * > | threads [NUM_SHARDS] |
std::vector< Uint32 > | to_clear [NUM_SHARDS] |
int | system_send_buffer_size = 0 |
#define DBG_NW LOG_STREAM(debug, network) |
Definition at line 83 of file network_worker.cpp.
#define ERR_NW LOG_STREAM(err, network) |
Definition at line 85 of file network_worker.cpp.
#define LOG_NW LOG_STREAM(info, network) |
Definition at line 84 of file network_worker.cpp.
#define NUM_SHARDS 1 |
Definition at line 97 of file network_worker.cpp.
Referenced by network_worker_pool::detect_error(), network_worker_pool::get_pending_stats(), get_shard(), network_worker_pool::manager::manager(), and network_worker_pool::manager::~manager().
#define SOCKET int |
Network worker handles data transfers in threads Remember to use mutexs as little as possible All global vars should be used in mutex FIXME:.
Definition at line 63 of file network_worker.cpp.
#define USE_SELECT 1 |
Definition at line 72 of file network_worker.cpp.
typedef std::vector< buffer* > buffer_set [static] |
Definition at line 131 of file network_worker.cpp.
typedef std::vector<TCPsocket> receive_list [static] |
Definition at line 144 of file network_worker.cpp.
typedef std::deque<buffer*> received_queue [static] |
Definition at line 147 of file network_worker.cpp.
typedef std::map<TCPsocket,schema_pair> schema_map [static] |
Definition at line 139 of file network_worker.cpp.
typedef std::map<TCPsocket,SOCKET_STATE> socket_state_map [static] |
Definition at line 151 of file network_worker.cpp.
typedef std::map<TCPsocket, std::pair<network::statistics,network::statistics> > socket_stats_map [static] |
Definition at line 152 of file network_worker.cpp.
enum SOCKET_STATE |
Definition at line 150 of file network_worker.cpp.
void @144::check_send_buffer_size | ( | TCPsocket & | s | ) | [static] |
void @144::check_socket_result | ( | TCPsocket & | sock, | |
SOCKET_STATE & | result | |||
) | [inline, static] |
Definition at line 431 of file network_worker.cpp.
References boost::foreach_detail_::end(), get_shard(), and SOCKET_ERRORED.
Referenced by process_queue().
size_t @144::get_shard | ( | TCPsocket | sock | ) | [static] |
Definition at line 104 of file network_worker.cpp.
References NUM_SHARDS.
Referenced by check_socket_result(), network_worker_pool::close_socket(), network_worker_pool::is_locked(), network_worker_pool::queue_data(), network_worker_pool::queue_raw_data(), network_worker_pool::receive_data(), network_worker_pool::remove_buffers(), and send_buffer().
static void @144::make_network_buffer | ( | const char * | input, | |
int | len, | |||
std::vector< char > & | buf | |||
) | [static] |
Definition at line 289 of file network_worker.cpp.
Referenced by process_queue(), and network_worker_pool::queue_raw_data().
static void @144::output_to_buffer | ( | TCPsocket | sock, | |
const config & | cfg, | |||
std::ostringstream & | compressor, | |||
bool | gzipped | |||
) | [static] |
Definition at line 274 of file network_worker.cpp.
References config_writer::write(), and write_compressed().
Referenced by network_worker_pool::queue_data().
static int @144::process_queue | ( | void * | shard_num | ) | [static] |
Definition at line 443 of file network_worker.cpp.
References check_socket_result(), DBG_NW, boost::foreach_detail_::end(), threading::get_current_thread_id(), threading::thread::get_id(), make_network_buffer(), config::error::message, raw_data_only, read_compressed(), read_gz(), receive_buf(), proxy::received_data(), send_buffer(), size, SOCKET_LOCKED, SOCKET_READY, stream, value, and threading::condition::wait().
Referenced by network_worker_pool::manager::manager().
static SOCKET_STATE @144::receive_buf | ( | TCPsocket | sock, | |
std::vector< char > & | buf | |||
) | [static] |
Definition at line 390 of file network_worker.cpp.
References boost::foreach_detail_::end(), raw_data_only, receive_with_timeout(), SOCKET_ERRORED, and SOCKET_READY.
Referenced by process_queue().
int @144::receive_bytes | ( | TCPsocket | s, | |
char * | buf, | |||
size_t | nbytes | |||
) | [static] |
Definition at line 168 of file network_worker.cpp.
References sock.
Referenced by receive_with_timeout().
bool @144::receive_with_timeout | ( | TCPsocket | s, | |
char * | buf, | |||
size_t | nbytes, | |||
bool | update_stats = false , |
|||
int | timeout_ms = 60000 | |||
) | [static] |
Definition at line 200 of file network_worker.cpp.
References channel, raw_data_only, and receive_bytes().
Referenced by receive_buf().
static SOCKET_STATE @144::send_buffer | ( | TCPsocket | sock, | |
std::vector< char > & | buf | |||
) | [static] |
Definition at line 297 of file network_worker.cpp.
References channel, check_send_buffer_size(), get_shard(), raw_data_only, size, SOCKET_ERRORED, SOCKET_LOCKED, SOCKET_READY, and upto.
Referenced by process_queue().
SOCKET channel |
Definition at line 90 of file network_worker.cpp.
threading::condition* cond[NUM_SHARDS] [static] |
Definition at line 162 of file network_worker.cpp.
Referenced by terrain_filter::get_locations(), terrain_filter::match(), and unit::matches_filter().
Definition at line 115 of file network_worker.cpp.
std::string config_error |
Definition at line 116 of file network_worker.cpp.
bool gzipped |
Do we wish to send the data gzipped, if not use binary wml.
This needs to stay until the last user of binary_wml has been removed.
Definition at line 121 of file network_worker.cpp.
Definition at line 136 of file network_worker.cpp.
IPaddress localAddress |
Definition at line 92 of file network_worker.cpp.
bool managed = false [static] |
Definition at line 130 of file network_worker.cpp.
size_t max_threads = 0 [static] |
size_t min_threads = 0 [static] |
Definition at line 136 of file network_worker.cpp.
buffer_set outgoing_bufs[NUM_SHARDS] [static] |
Definition at line 132 of file network_worker.cpp.
receive_list pending_receives[NUM_SHARDS] [static] |
Definition at line 145 of file network_worker.cpp.
std::vector<char> raw_buffer |
Definition at line 126 of file network_worker.cpp.
bool raw_data_only = false [static] |
Definition at line 130 of file network_worker.cpp.
Referenced by network_worker_pool::get_received_data(), process_queue(), receive_buf(), receive_with_timeout(), send_buffer(), and network_worker_pool::set_raw_data_only().
int ready |
Definition at line 89 of file network_worker.cpp.
received_queue received_data_queue [static] |
Definition at line 148 of file network_worker.cpp.
threading::mutex* received_mutex = NULL [static] |
Definition at line 161 of file network_worker.cpp.
IPaddress remoteAddress |
Definition at line 91 of file network_worker.cpp.
schema_map schemas [static] |
Definition at line 141 of file network_worker.cpp.
threading::mutex* schemas_mutex = NULL [static] |
Definition at line 160 of file network_worker.cpp.
int sflag |
Definition at line 93 of file network_worker.cpp.
threading::mutex* shard_mutexes[NUM_SHARDS] [static] |
Definition at line 158 of file network_worker.cpp.
TCPsocket sock |
Definition at line 114 of file network_worker.cpp.
int socket_errors[NUM_SHARDS] [static] |
Definition at line 157 of file network_worker.cpp.
socket_state_map sockets_locked[NUM_SHARDS] [static] |
Definition at line 154 of file network_worker.cpp.
threading::mutex* stats_mutex = NULL [static] |
Definition at line 159 of file network_worker.cpp.
std::ostringstream stream |
Definition at line 117 of file network_worker.cpp.
Referenced by game::ban_user(), preferences::base_manager::base_manager(), check_python_scripts(), simple_wml::compress_buffer(), format_file_size(), get_campaign_info(), display::get_fog_shroud_graphics(), cutter::load_config(), font::load_font_config(), load_language_list(), gui2::load_settings(), main(), map_editor::map_editor(), dialogs::network_data_dialog(), process_queue(), server::read_config(), read_ignore_patterns(), read_tips_of_day(), events::menu_handler::save_game(), save_index(), set_campaign_info(), help::help_text_area::set_items(), set_language(), simple_wml::uncompress_buffer(), display::update_display(), and write_save_index().
int system_send_buffer_size = 0 [static] |
Definition at line 166 of file network_worker.cpp.
std::map<Uint32,threading::thread*> threads[NUM_SHARDS] [static] |
Definition at line 164 of file network_worker.cpp.
std::vector<Uint32> to_clear[NUM_SHARDS] [static] |
Definition at line 165 of file network_worker.cpp.
Referenced by game_state::clear_variable(), and game_state::clear_variable_cfg().
socket_stats_map transfer_stats [static] |
Definition at line 155 of file network_worker.cpp.
unsigned int waiting_threads[NUM_SHARDS] [static] |
Definition at line 100 of file network_worker.cpp.
Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |