The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
network_worker.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef NETWORK_WORKER_HPP_INCLUDED
16 #define NETWORK_WORKER_HPP_INCLUDED
17 
18 #include <map>
19 #include "network.hpp"
20 
21 class config;
22 
23 /**
24  * Aligns a variable on a 4 byte boundary.
25  *
26  * The address needs to be aligned on a Sparc system, if it's not aligned the
27  * SDLNet_Read32 call will cause a SIGBUS and the server will be terminated [1].
28  * Best use this alignment for all buffers used in for the SDL_Net calls.
29  *
30  * [1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=426318
31  */
32 #ifdef __GNUC__
33 #define ALIGN_4 __attribute__ ((aligned (4)))
34 #else
35 #define ALIGN_4
36 #endif
37 
38 namespace network_worker_pool
39 {
40 
41 struct manager
42 {
43  explicit manager(size_t min_threads,size_t max_threads);
44  ~manager();
45 
46 private:
47  manager(const manager&);
48  void operator=(const manager&);
49 
50  bool active_;
51 };
52 
54 
55 void set_raw_data_only();
56 void set_use_system_sendfile(bool);
57 
58 /** Function to asynchronously received data to the given socket. */
59 void receive_data(TCPsocket sock);
60 
61 TCPsocket get_received_data(TCPsocket sock, config& cfg, network::bandwidth_in_ptr&);
62 
63 TCPsocket get_received_data(std::vector<char>& buf);
64 
65 void queue_file(TCPsocket sock, const std::string&);
66 
67 void queue_raw_data(TCPsocket sock, const char* buf, int len);
68 size_t queue_data(TCPsocket sock, const config& buf, const std::string& packet_type);
69 bool is_locked(const TCPsocket sock);
70 bool close_socket(TCPsocket sock);
71 TCPsocket detect_error();
72 
73 std::pair<network::statistics,network::statistics> get_current_transfer_stats(TCPsocket sock);
74 
75 }
76 
77 #endif
void receive_data(TCPsocket sock)
Function to asynchronously received data to the given socket.
void queue_raw_data(TCPsocket sock, const char *buf, int len)
size_t queue_data(TCPsocket sock, const config &buf, const std::string &packet_type)
bool is_locked(const TCPsocket sock)
manager(size_t min_threads, size_t max_threads)
TCPsocket get_received_data(TCPsocket sock, config &cfg, network::bandwidth_in_ptr &bandwidth_in)
void queue_file(TCPsocket sock, const std::string &filename)
GLenum GLsizei len
Definition: glew.h:5662
GLenum GLuint GLsizei const char * buf
Definition: glew.h:2498
network::pending_statistics get_pending_stats()
void operator=(const manager &)
void set_use_system_sendfile(bool use)
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
bool close_socket(TCPsocket sock)
GLsizei const GLcharARB ** string
Definition: glew.h:4503
std::pair< network::statistics, network::statistics > get_current_transfer_stats(TCPsocket sock)