#include "global.hpp"
#include "serialization/binary_wml.hpp"
#include "config.hpp"
#include "gettext.hpp"
#include "log.hpp"
#include "network.hpp"
#include "network_worker.hpp"
#include "thread.hpp"
#include "SDL_net.h"
#include <algorithm>
#include <cassert>
#include <cerrno>
#include <queue>
#include <iostream>
#include <set>
#include <vector>
#include <ctime>
#include <signal.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <fcntl.h>
Go to the source code of this file.
Namespaces | |
namespace | network |
Defines | |
#define | SOCKET int |
#define | DBG_NW LOG_STREAM(debug, network) |
#define | LOG_NW LOG_STREAM(info, network) |
#define | WRN_NW LOG_STREAM(warn, network) |
#define | ERR_NW LOG_STREAM(err, network) |
Typedefs | |
typedef std::map < network::connection, connection_details > | connection_map |
typedef std::vector < network::connection > | sockets_list |
Functions | |
static int | create_connection (TCPsocket sock, const std::string &host, int port) |
static connection_details & | get_connection_details (network::connection handle) |
static TCPsocket | get_socket (network::connection handle) |
static void | remove_connection (network::connection handle) |
static bool | is_pending_remote_handle (network::connection handle) |
static void | set_remote_handle (network::connection handle, int remote_handle) |
static void | check_error () |
static void | check_timeout () |
Check whether too much time since the last server ping has passed and we timed out. | |
connection_stats | network::get_connection_stats (connection connection_num) |
pending_statistics | network::get_pending_stats () |
void | network::set_raw_data_only () |
size_t | network::nconnections () |
The number of peers we are connected to. | |
bool | network::is_server () |
If we are currently accepting connections. | |
connection | network::connect (const std::string &host, int port=15000) |
Function to attempt to connect to a remote host. | |
connection | network::connect (const std::string &host, int port, threading::waiter &waiter) |
connection | network::accept_connection () |
Function to accept a connection from a remote host. | |
bool | network::disconnect (connection connection_num=0, bool force=false) |
Function to disconnect from a certain host, or close all connections if connection_num is 0. | |
void | network::queue_disconnect (connection connection_num) |
Function to queue a disconnection. | |
connection | network::receive_data (config &cfg, connection connection_num, unsigned int timeout) |
connection | network::receive_data (config &cfg, connection connection_num=0) |
Function to receive data from either a certain connection, or all connections if connection_num is 0. | |
connection | network::receive_data (std::vector< char > &buf) |
void | network::send_data (const config &cfg, connection connection_num, const bool gzipped) |
Function to send data down a given connection, or broadcast to all peers if connection_num is 0. | |
void | network::send_raw_data (const char *buf, int len, connection connection_num) |
void | network::process_send_queue (connection connection_num=0, size_t max_size=0) |
Function to send any data that is in a connection's send_queue, up to a maximum of 'max_size' bytes -- or the entire send queue if 'max_size' bytes is 0. | |
void | network::send_data_all_except (const config &cfg, connection connection_num, const bool gzipped) |
Function to send data to all peers except 'connection_num'. | |
std::string | network::ip_address (connection connection_num) |
Function to get the remote ip address of a socket. | |
statistics | network::get_send_stats (connection handle) |
Function to see the number of bytes being processed on the current socket. | |
statistics | network::get_receive_stats (connection handle) |
Variables | |
connection_map | connections |
network::connection | connection_id = 1 |
time_t | last_ping |
Stores the time of the last server ping we received. | |
time_t | last_ping_check = 0 |
SDLNet_SocketSet | socket_set = 0 |
std::set< network::connection > | waiting_sockets |
sockets_list | sockets |
TCPsocket | server_socket |
std::deque< network::connection > | disconnection_queue |
std::set< network::connection > | bad_sockets |
network_worker_pool::manager * | worker_pool_man = NULL |
unsigned int | network::ping_timeout = 0 |
Amount of seconds after the last server ping when we assume to have timed out. |
Definition in file network.cpp.
#define DBG_NW LOG_STREAM(debug, network) |
Definition at line 59 of file network.cpp.
#define ERR_NW LOG_STREAM(err, network) |
Definition at line 62 of file network.cpp.
#define LOG_NW LOG_STREAM(info, network) |
Definition at line 60 of file network.cpp.
#define SOCKET int |
Definition at line 56 of file network.cpp.
#define WRN_NW LOG_STREAM(warn, network) |
Definition at line 61 of file network.cpp.
Referenced by network::accept_connection(), and network::manager::manager().
typedef std::map<network::connection,connection_details> connection_map [static] |
Definition at line 87 of file network.cpp.
typedef std::vector<network::connection> sockets_list [static] |
Definition at line 181 of file network.cpp.
static void check_error | ( | ) | [static] |
Definition at line 134 of file network.cpp.
References _, connections, network_worker_pool::detect_error(), and sock.
Referenced by network::process_send_queue(), and network::receive_data().
static void check_timeout | ( | ) | [static] |
Check whether too much time since the last server ping has passed and we timed out.
If the last check is too long ago reset the last_ping to 'now'. This happens when we "freeze" the client one way or another or we just didn't try to receive data.
Definition at line 150 of file network.cpp.
References DBG_NW, ERR_NW, last_ping, last_ping_check, lexical_cast(), LOG_NW, network::nconnections(), network::ping_timeout, and vngettext().
Referenced by network::receive_data().
static int create_connection | ( | TCPsocket | sock, | |
const std::string & | host, | |||
int | port | |||
) | [static] |
Definition at line 97 of file network.cpp.
References connection_id, and connections.
Referenced by network::accept_connection().
static connection_details& get_connection_details | ( | network::connection | handle | ) | [static] |
Definition at line 103 of file network.cpp.
References _, and connections.
Referenced by network::get_connection_stats(), get_socket(), is_pending_remote_handle(), network::receive_data(), and set_remote_handle().
static TCPsocket get_socket | ( | network::connection | handle | ) | [static] |
Definition at line 113 of file network.cpp.
References get_connection_details().
Referenced by network::disconnect(), network::get_receive_stats(), network::get_send_stats(), network::ip_address(), network::receive_data(), and network::server_manager::server_manager().
static bool is_pending_remote_handle | ( | network::connection | handle | ) | [static] |
Definition at line 123 of file network.cpp.
References get_connection_details().
Referenced by network::receive_data().
static void remove_connection | ( | network::connection | handle | ) | [static] |
Definition at line 118 of file network.cpp.
References connections.
Referenced by network::accept_connection(), and network::disconnect().
static void set_remote_handle | ( | network::connection | handle, | |
int | remote_handle | |||
) | [static] |
Definition at line 129 of file network.cpp.
References get_connection_details().
Referenced by network::receive_data().
std::set<network::connection> bad_sockets [static] |
Definition at line 194 of file network.cpp.
Referenced by network::disconnect(), network::error::error(), network::receive_data(), network::send_data(), and network::send_raw_data().
std::vector<char> buf |
Definition at line 187 of file network.cpp.
Referenced by replay::add_attack(), replay::add_disband(), replay::add_recall(), replay::add_recruit(), replay::add_value(), simple_wml::node::apply_diff(), terrain_label::cfg_colour(), simple_wml::document::clone(), simple_wml::compress_buffer(), simple_wml::node::copy_into(), game::describe_slots(), describe_turns(), simple_wml::string_span::duplicate(), map_editor::edit_rotate_selection(), play_controller::expand_wml_commands(), dialogs::format_time_summary(), preprocessor_data::get_chunk(), get_cwd(), config::get_diff(), wesnothd::banned::get_human_end_time(), network_worker_pool::get_received_data(), lg::get_timestamp(), get_user_data_dir(), simple_wml::document::output(), map_editor::perform_selection_move(), dfool::dfool_ai::play_turn(), preprocess_file(), mp::create::process_event(), mp::connect::side::process_event(), game_events::pump(), unit::redraw_unit(), network_worker_pool::remove_buffers(), server::run(), game::send_history(), simple_wml::node::set_attr_dup(), simple_wml::node::set_attr_int(), gamestatus::set_start_ToD(), simple_wml::string_span::to_int(), simple_wml::uncompress_buffer(), mp::connect::side::update_ui(), gamemap::location::write(), gamestatus::write(), time_of_day::write(), write_battle_result_map(), write_file(), events::menu_handler::write_game_snapshot(), write_player(), and write_str_int_map().
SOCKET channel |
Definition at line 353 of file network.cpp.
Referenced by sound::play_sound_internal(), receive_with_timeout(), and send_buffer().
Definition at line 340 of file network.cpp.
int connected_at |
Definition at line 84 of file network.cpp.
network::connection connection_id = 1 [static] |
connection_map connections [static] |
Definition at line 88 of file network.cpp.
Referenced by check_error(), create_connection(), network::disconnect(), get_connection_details(), server::ip_exceeds_connection_limit(), network::receive_data(), remove_connection(), network::send_data(), and network::send_raw_data().
std::deque<network::connection> disconnection_queue [static] |
Definition at line 193 of file network.cpp.
Referenced by network::disconnect(), network::queue_disconnect(), and network::receive_data().
const char* error_ |
Definition at line 339 of file network.cpp.
std::string host |
Definition at line 77 of file network.cpp.
Referenced by open_connection(), and game::remove_player().
std::string host_ |
Definition at line 337 of file network.cpp.
time_t last_ping [static] |
Stores the time of the last server ping we received.
Definition at line 93 of file network.cpp.
Referenced by check_timeout(), network::disconnect(), and network::receive_data().
time_t last_ping_check = 0 [static] |
IPaddress localAddress |
Definition at line 355 of file network.cpp.
int port |
int port_ |
Definition at line 338 of file network.cpp.
int ready |
Definition at line 352 of file network.cpp.
int remote_handle |
IPaddress remoteAddress |
Definition at line 354 of file network.cpp.
TCPsocket server_socket [static] |
Definition at line 191 of file network.cpp.
Referenced by network::accept_connection(), network::server_manager::is_running(), network::is_server(), network::send_data(), network::server_manager::server_manager(), and network::server_manager::stop().
int sflag |
Definition at line 356 of file network.cpp.
TCPsocket sock |
Definition at line 76 of file network.cpp.
Referenced by check_error(), check_send_buffer_size(), network_worker_pool::detect_error(), open_connection(), mp::ui::process_network(), receive_bytes(), server::run(), and upload_logs().
SDLNet_SocketSet socket_set = 0 [static] |
Definition at line 179 of file network.cpp.
Referenced by network::accept_connection(), network::disconnect(), network::manager::manager(), network::receive_data(), and network::manager::~manager().
sockets_list sockets [static] |
Definition at line 182 of file network.cpp.
Referenced by network::accept_connection(), network::disconnect(), network::get_receive_stats(), network::get_send_stats(), network::nconnections(), network::receive_data(), network::send_data(), network::send_data_all_except(), and network::send_raw_data().
size_t upto |
std::set<network::connection> waiting_sockets [static] |
Definition at line 180 of file network.cpp.
Referenced by network::accept_connection(), network::disconnect(), network::receive_data(), and network::manager::~manager().
network_worker_pool::manager* worker_pool_man = NULL [static] |
Definition at line 196 of file network.cpp.
Referenced by network::manager::manager(), and network::manager::~manager().
Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |