network_worker.cpp File Reference

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

Include dependency graph for network_worker.cpp:

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::mutexshard_mutexes [NUM_SHARDS]
threading::mutexstats_mutex = NULL
threading::mutexschemas_mutex = NULL
threading::mutexreceived_mutex = NULL
threading::conditioncond [NUM_SHARDS]
std::map< Uint32,
threading::thread * > 
threads [NUM_SHARDS]
std::vector< Uint32 > to_clear [NUM_SHARDS]
int system_send_buffer_size = 0


Define Documentation

#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

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

Todo:
: All code which holds a mutex should run O(1) time for scalability. Implement read/write locks. (postponed for 1.5)

Definition at line 63 of file network_worker.cpp.

#define USE_SELECT   1

Definition at line 72 of file network_worker.cpp.


Typedef Documentation

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.


Enumeration Type Documentation

Enumerator:
SOCKET_READY 
SOCKET_LOCKED 
SOCKET_ERRORED 
SOCKET_INTERRUPT 

Definition at line 150 of file network_worker.cpp.


Function Documentation

void @144::check_send_buffer_size ( TCPsocket &  s  )  [static]

Definition at line 185 of file network_worker.cpp.

References DBG_NW, and sock.

Referenced by send_buffer().

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]

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]

static SOCKET_STATE @144::receive_buf ( TCPsocket  sock,
std::vector< char > &  buf 
) [static]

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]


Variable Documentation

SOCKET channel

Definition at line 90 of file network_worker.cpp.

threading::condition* cond[NUM_SHARDS] [static]

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]

Definition at line 102 of file network_worker.cpp.

Referenced by main().

size_t min_threads = 0 [static]

Definition at line 101 of file network_worker.cpp.

Referenced by main().

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]

int ready

Definition at line 89 of file network_worker.cpp.

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

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