network.cpp File Reference

Networking. More...

#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>

Include dependency graph for network.cpp:

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::connectionwaiting_sockets
sockets_list sockets
TCPsocket server_socket
std::deque< network::connectiondisconnection_queue
std::set< network::connectionbad_sockets
network_worker_pool::managerworker_pool_man = NULL
unsigned int network::ping_timeout = 0
 Amount of seconds after the last server ping when we assume to have timed out.


Detailed Description

Networking.

Definition in file network.cpp.


Define Documentation

#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 Documentation

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.


Function Documentation

static void check_error (  )  [static]

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]

static TCPsocket get_socket ( network::connection  handle  )  [static]

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


Variable Documentation

std::set<network::connection> bad_sockets [static]

std::vector<char> buf

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.

Definition at line 84 of file network.cpp.

Definition at line 90 of file network.cpp.

Referenced by create_connection().

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]

Definition at line 93 of file network.cpp.

Referenced by check_timeout().

IPaddress localAddress

Definition at line 355 of file network.cpp.

int port

Definition at line 78 of file network.cpp.

Referenced by main(), and open_connection().

int port_

Definition at line 338 of file network.cpp.

int ready

Definition at line 352 of file network.cpp.

Definition at line 82 of file network.cpp.

Referenced by network::receive_data().

IPaddress remoteAddress

Definition at line 354 of file network.cpp.

TCPsocket server_socket [static]

int sflag

Definition at line 356 of file network.cpp.

TCPsocket sock

SDLNet_SocketSet socket_set = 0 [static]

size_t upto

Definition at line 188 of file network.cpp.

Referenced by send_buffer().

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