Classes | |
struct | pending_statistics |
struct | manager |
struct | server_manager |
A server manager causes listening on a given port to occur for the duration of its lifetime. More... | |
struct | connection_stats |
struct | error |
struct | statistics |
Typedefs | |
typedef int | connection |
Functions | |
connection_stats | get_connection_stats (connection connection_num) |
pending_statistics | get_pending_stats () |
void | set_raw_data_only () |
size_t | nconnections () |
The number of peers we are connected to. | |
bool | is_server () |
If we are currently accepting connections. | |
connection | connect (const std::string &host, int port=15000) |
Function to attempt to connect to a remote host. | |
connection | connect (const std::string &host, int port, threading::waiter &waiter) |
connection | accept_connection () |
Function to accept a connection from a remote host. | |
bool | 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 | queue_disconnect (connection connection_num) |
Function to queue a disconnection. | |
connection | receive_data (config &cfg, connection connection_num, unsigned int timeout) |
connection | 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 | receive_data (std::vector< char > &buf) |
void | 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 | send_raw_data (const char *buf, int len, connection connection_num) |
void | 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 | 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 | ip_address (connection connection_num) |
Function to get the remote ip address of a socket. | |
statistics | get_send_stats (connection handle) |
Function to see the number of bytes being processed on the current socket. | |
statistics | get_receive_stats (connection handle) |
Variables | |
unsigned int | ping_timeout = 0 |
Amount of seconds after the last server ping when we assume to have timed out. | |
connection const | null_connection = 0 |
This module provides high level network access using an API similiar to sockets, but primarily for the transport of config objects. This is how the games protocols work - data is sent via config objects.
A client would create a manager object to initialize the network layer, connect(), and then send_data(). A server would create a server_manager object, then accept_connection(), and finally receive_data().
typedef int network::connection |
Definition at line 88 of file network.hpp.
connection network::accept_connection | ( | ) |
Function to accept a connection from a remote host.
If no host is attempting to connect, it will return 0 immediately. Otherwise returns the new connection. Throws error.
Definition at line 482 of file network.cpp.
References _, connect(), create_connection(), DBG_NW, remove_connection(), server_socket, socket_set, sockets, waiting_sockets, and WRN_NW.
Referenced by mp::ui::process_network(), and server::run().
connection network::connect | ( | const std::string & | host, | |
int | port, | |||
threading::waiter & | waiter | |||
) |
Definition at line 470 of file network.cpp.
References threading::async_operation_holder< T >::operation().
Referenced by accept_connection().
connection network::connect | ( | const std::string & | host, | |
int | port = 15000 | |||
) |
Function to attempt to connect to a remote host.
Returns the new connection on success, or 0 on failure. Throws error.
Definition at line 462 of file network.cpp.
Referenced by proxy::create_proxy(), dialogs::network_connect_dialog(), and network::server_manager::server_manager().
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.
Returns true if the connection was disconnected. Returns false on failure to disconnect, since the socket is in the middle of sending/receiving data. The socket will be closed when it has finished its send/receive.
Definition at line 575 of file network.cpp.
References bad_sockets, network_worker_pool::close_socket(), connections, DBG_NW, proxy::disconnect(), disconnection_queue, get_socket(), lg::info, is_server(), last_ping, remove_connection(), socket_set, sockets, and waiting_sockets.
Referenced by proxy::create_proxy(), proxy::disconnect(), network::error::disconnect(), mp::connect::kick_player(), open_connection(), server::run(), and network::manager::~manager().
connection_stats network::get_connection_stats | ( | connection | connection_num | ) |
Definition at line 211 of file network.cpp.
References get_connection_details(), get_receive_stats(), and get_send_stats().
Referenced by server::process_command().
pending_statistics network::get_pending_stats | ( | ) |
Definition at line 229 of file network.cpp.
References network_worker_pool::get_pending_stats().
Referenced by server::process_command().
statistics network::get_receive_stats | ( | connection | handle | ) |
Definition at line 926 of file network.cpp.
References network_worker_pool::get_current_transfer_stats(), get_socket(), and sockets.
Referenced by get_connection_stats(), and dialogs::network_receive_dialog().
statistics network::get_send_stats | ( | connection | handle | ) |
Function to see the number of bytes being processed on the current socket.
Definition at line 922 of file network.cpp.
References network_worker_pool::get_current_transfer_stats(), get_socket(), and sockets.
Referenced by get_connection_stats(), and dialogs::network_send_dialog().
std::string network::ip_address | ( | connection | connection_num | ) |
Function to get the remote ip address of a socket.
Definition at line 904 of file network.cpp.
References get_socket().
Referenced by game::ban_user(), server::ip_exceeds_connection_limit(), game::kick_member(), game::mute_observer(), game::player_is_banned(), server::process_command(), server::process_data_game(), server::process_data_lobby(), server::process_login(), game::process_message(), server::process_query(), game::remove_player(), server::run(), and game::start_game().
bool network::is_server | ( | ) |
If we are currently accepting connections.
Definition at line 318 of file network.cpp.
References server_socket.
Referenced by disconnect(), mp::connect::kick_player(), mp::connect::process_network_error(), and receive_data().
size_t network::nconnections | ( | ) |
The number of peers we are connected to.
Definition at line 313 of file network.cpp.
References sockets.
Referenced by playmp_controller::can_execute_command(), play_controller::can_execute_command(), check_timeout(), replay_network_sender::commit_and_sync(), events::console_handler::do_control(), events::console_handler::do_debug(), events::console_handler::is_enabled(), team::knows_about_team(), open_connection(), mp::connect::process_event(), turn_info::sync_network(), and replay_network_sender::sync_non_undoable().
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.
Definition at line 887 of file network.cpp.
References check_error().
Referenced by server::run().
void network::queue_disconnect | ( | connection | connection_num | ) |
Function to queue a disconnection.
Next time receive_data is called, it will generate an error on the given connection (and presumably then the handling of the error will include closing the connection).
Definition at line 623 of file network.cpp.
References disconnection_queue.
Referenced by server::process_command().
connection network::receive_data | ( | std::vector< char > & | buf | ) |
Definition at line 749 of file network.cpp.
References bad_sockets, check_error(), connections, disconnection_queue, get_connection_details(), network_worker_pool::get_received_data(), is_pending_remote_handle(), network_worker_pool::receive_data(), remote_handle, set_remote_handle(), socket_set, sockets, and waiting_sockets.
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.
Will store the data received in cfg. Times out after timeout milliseconds. Returns the connection that data was received from, or 0 if timeout occurred. Throws error if an error occurred.
Definition at line 650 of file network.cpp.
References bad_sockets, check_error(), check_timeout(), connections, DBG_NW, disconnection_queue, config::empty(), get_connection_details(), network_worker_pool::get_received_data(), get_socket(), network_worker_pool::is_locked(), is_pending_remote_handle(), is_server(), last_ping, lexical_cast(), LOG_NW, ping_timeout, network_worker_pool::receive_data(), remote_handle, set_remote_handle(), socket_set, sockets, config::values, and waiting_sockets.
connection network::receive_data | ( | config & | cfg, | |
connection | connection_num, | |||
unsigned int | timeout | |||
) |
Definition at line 628 of file network.cpp.
References network_worker_pool::receive_data().
Referenced by dialogs::network_data_dialog(), open_connection(), playmp_controller::play_human_turn(), playmp_controller::play_network_turn(), mp::ui::process_network(), server::run(), and turn_info::sync_network().
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.
Definition at line 825 of file network.cpp.
References bad_sockets, connections, DBG_NW, config::empty(), ERR_NW, lg::info, LOG_NW, network_worker_pool::queue_data(), game::send_data(), server_socket, and sockets.
Referenced by turn_info::change_side_controller(), events::menu_handler::change_side_controller(), replay_network_sender::commit_and_sync(), mp::connect::connect(), events::chat_command_handler::do_whisper(), enter_connect_mode(), enter_create_mode(), enter_lobby_mode(), mp::ui::handle_event(), mp::wait::join_game(), mp::connect::kick_player(), open_connection(), play_game(), playsingle_controller::play_scenario(), mp::lobby::process_event(), mp::connect::process_event(), server::process_login(), mp::connect::process_network_connection(), turn_info::process_network_data(), mp::ui::process_network_data(), mp::connect::process_network_data(), server::run(), mp::ui::send_chat_message(), events::chat_handler::send_command(), mp::connect::start_game(), replay_network_sender::sync_non_undoable(), and mp::connect::update_and_send_diff().
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'.
Definition at line 893 of file network.cpp.
References game::send_data(), and sockets.
Referenced by turn_info::process_network_data().
void network::send_raw_data | ( | const char * | buf, | |
int | len, | |||
connection | connection_num | |||
) |
Definition at line 859 of file network.cpp.
References bad_sockets, connections, ERR_NW, lg::info, network_worker_pool::queue_raw_data(), and sockets.
Referenced by game::add_player(), game::ban_user(), game::kick_member(), game::load_next_scenario(), game::notify_new_host(), proxy::received_data(), game::send_data(), game::send_data_observers(), game::send_data_team(), send_doc(), server::send_error(), server::send_error_dup(), game::send_history(), game::send_observerjoins(), game::send_to_one(), game::take_side(), and game::transfer_ai_sides().
void network::set_raw_data_only | ( | ) |
Definition at line 271 of file network.cpp.
References network_worker_pool::set_raw_data_only().
Referenced by main().
connection const network::null_connection = 0 |
Definition at line 90 of file network.hpp.
Referenced by playmp_controller::play_human_turn(), playmp_controller::play_network_turn(), turn_info::process_network_data(), server::run(), and playmp_controller::wait_for_upload().
unsigned int network::ping_timeout = 0 |
Amount of seconds after the last server ping when we assume to have timed out.
When set to '0' ping timeout isn't checked. Gets set in preferences::manager according to the preferences file.
Definition at line 205 of file network.cpp.
Referenced by check_timeout(), preferences::manager::manager(), receive_data(), preferences::set_ping_timeout(), and preferences::manager::~manager().
Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |