network Namespace Reference

High level network layer for config object transport. More...


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


Detailed Description

High level network layer for config object transport.

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 Documentation

typedef int network::connection

Definition at line 88 of file network.hpp.


Function Documentation

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  ) 

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  ) 

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 (  ) 

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  ) 

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 
)

void network::send_data ( const config cfg,
connection  connection_num,
const bool  gzipped 
)

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'.

Todo:
Note the gzipped parameter should be removed later.

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 
)

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().


Variable Documentation

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