Aesthetic changes, all of the files I created have lines shorter than 100 chars.

This commit is contained in:
Guillermo Biset 2010-07-23 21:27:58 +00:00
parent a0123917c3
commit 96f2dc192c
20 changed files with 261 additions and 144 deletions

View file

@ -202,7 +202,8 @@ namespace ana
/**
* Get associated stats_collector object.
*
* @returns A pointer to the associated stats_collector object, NULL if not keeping stats.
* @returns A pointer to the associated stats_collector object,
* NULL if not keeping stats.
*
* \sa stats_collector.
*/
@ -273,7 +274,8 @@ namespace ana
virtual void set_raw_buffer_max_size( size_t size ) = 0;
/**
* Switch to raw data mode and perform a blocking wait, only POD types should be used.
* Switch to raw data mode and perform a blocking wait.
* Only POD types should be used.
*/
virtual void wait_raw_object(ana::serializer::bistream& bis, size_t size) = 0;
@ -355,9 +357,11 @@ namespace ana
* Send a buffer to every connected client.
*
* @param buffer : Buffer to be sent. Should be constucted with the buffer function.
* @param handler : Handler of events resulting from this operation. It will be called with _each_
* event, meaning that it will be called exactly once for every connected client.
* @param send_type : Optional, type of the send operation. Defaults to a value of CopyBufer.
* @param handler : Handler of events resulting from this operation. It will be called
* with _each_ event, meaning that it will be called exactly once
* for every connected client.
* @param send_type : Optional, type of the send operation.
* Defaults to a value of COPY_BUFFER.
*
* Examples:
* - server_->send_all( ana::buffer( str ), this );
@ -377,13 +381,13 @@ namespace ana
* Send a buffer to every connected client that satisfies a given condition/property.
*
* @param buffer : Buffer to be sent. Should be constucted with the buffer function.
* @param handler : Handler of events resulting from this operation. It will be called exactly
* once for every client that holds the property.
* @param send_type : Optional, type of the send operation. Defaults to a value of CopyBufer.
* @param handler : Handler of events resulting from this operation. It will be called
* exactly once for every client that holds the property.
* @param send_type : Optional, type of the send operation. Defaults to COPY_BUFFER.
*
* Examples:
* - server_->send_if( ana::buffer( str() ), this,
* create_predicate( boost::bind( std::not_equal_to<net_id>(), client, _1) ) );
* - server_->send_if( ana::buffer( str() ), this,
* create_predicate( boost::bind( std::not_equal_to<net_id>(), client, _1) ) );
*
* @returns : The unique operation id of the send operation.
*
@ -398,11 +402,12 @@ namespace ana
send_type type = COPY_BUFFER ) = 0;
/**
* Send a buffer to every connected client except one. Equals a send_all if the client doesn't exist.
* Send a buffer to every connected client except one.
* Equals a send_all if the client doesn't exist.
*
* @param buffer : Buffer to be sent. Should be constucted with the buffer function.
* @param handler : Handler of a possible event resulting from this operation.
* @param send_type : Optional, type of the send operation. Defaults to a value of CopyBufer.
* @param send_type : Optional, type of the send operation. Defaults to COPY_BUFFER.
*
* Examples:
* - server_->send_all_except( client, ana::buffer( str ), this, ana::ZERO_COPY);
@ -419,11 +424,12 @@ namespace ana
send_type type = COPY_BUFFER ) = 0;
/**
* Send a buffer to a connected client with a given net_id. Does nothing if no such client exists.
* Send a buffer to a connected client with a given net_id.
* Does nothing if no such client exists.
*
* @param buffer : Buffer to be sent. Should be constucted with the buffer function.
* @param handler : Handler of a possible event resulting from this operation.
* @param send_type : Optional, type of the send operation. Defaults to a value of CopyBufer.
* @param send_type : Optional, type of the send operation. Defaults to COPY_BUFFER.
*
* Examples:
* - server_->send_one( client, ana::buffer( str ), this, ana::ZERO_COPY);
@ -449,8 +455,8 @@ namespace ana
/**
* Start the server on a given port.
*
* @param port : The port to be used for the server incoming connections. The port shouldn't be
* currently occupied.
* @param port : The port to be used for the server incoming connections.
* The port shouldn't be currently occupied.
*/
virtual void run(port pt) = 0;
@ -479,10 +485,13 @@ namespace ana
virtual void cancel( operation_id operation ) = 0;
/* Allow external object to call set_raw_data_mode() directly. */
/** Set the server to raw data mode, every time a client connects it will use the current mode. */
/**
* Set the server to raw data mode, every time a client connects
* it will use the current mode.
*/
using ana::detail::ana_component::set_raw_data_mode;
/** Returns the string representing the ip address of the connected client with id net_id. */
/** Returns the string representing the ip address of a connected client. */
virtual std::string ip_address( net_id ) const = 0;
/** Returns a pointer to an ana::stats object of a connected client. */
@ -583,7 +592,7 @@ namespace ana
*
* @param buffer : The buffer being sent.
* @param handler : Handler of events resulting from this operation.
* @param send_type : Optional, type of the send operation. Defaults to a value of CopyBufer.
* @param send_type : Optional, type of the send operation. Defaults to COPY_BUFFER.
*
* @returns : The unique operation id of the send operation.
*

View file

@ -66,7 +66,7 @@ namespace ana
* Resize the buffer, this won't affect the amount of memory usage.
* It is only possible to downsize the buffer.
*
* @Pre : The new size is smaller than the original size used to construct this object.
* @Pre : The new size is smaller than the original size used to construct this.
*/
void resize( size_t new_size )
{
@ -126,7 +126,7 @@ namespace ana
size_t size_;
};
/** A shared pointer to a read_buffer, self destructs when no one is left referencing it. */
/** A shared pointer to a read_buffer, self destructs when no one is referencing it. */
typedef boost::shared_ptr<read_buffer_implementation> read_buffer;
/**
@ -182,7 +182,8 @@ namespace ana
* The ana::buffer function is used to create a buffer object to represent raw memory,
* an array of POD elements, a vector of POD elements, or a std::string.
*
* Check <http://think-async.com/Asio/boost_asio_1_3_1/doc/html/boost_asio/reference/buffer.html>
* Check:
* <http://think-async.com/Asio/boost_asio_1_3_1/doc/html/boost_asio/reference/buffer.html>
*/
//@{
@ -191,7 +192,8 @@ namespace ana
return boost::asio::buffer(b);
}
inline boost::asio::mutable_buffers_1 buffer(const boost::asio::mutable_buffer & b, std::size_t max_size_in_bytes)
inline boost::asio::mutable_buffers_1 buffer(const boost::asio::mutable_buffer & b,
std::size_t max_size_in_bytes)
{
return boost::asio::buffer(b, max_size_in_bytes);
}
@ -201,7 +203,8 @@ namespace ana
return boost::asio::buffer(b);
}
inline boost::asio::const_buffers_1 buffer(const boost::asio::const_buffer & b, std::size_t max_size_in_bytes)
inline boost::asio::const_buffers_1 buffer(const boost::asio::const_buffer & b,
std::size_t max_size_in_bytes)
{
return boost::asio::buffer(b, max_size_in_bytes);
}
@ -300,7 +303,7 @@ namespace ana
template<typename PodType, typename Allocator>
inline boost::asio::const_buffers_1 buffer(const std::vector< PodType, Allocator > & data,
std::size_t max_size_in_bytes)
std::size_t max_size_in_bytes)
{
return boost::asio::buffer(data, max_size_in_bytes);
}
@ -310,7 +313,8 @@ namespace ana
return boost::asio::buffer(data);
}
inline boost::asio::const_buffers_1 buffer(const std::string & data, std::size_t max_size_in_bytes)
inline boost::asio::const_buffers_1 buffer(const std::string & data,
std::size_t max_size_in_bytes)
{
return boost::asio::buffer(data, max_size_in_bytes);
}

View file

@ -44,31 +44,53 @@ namespace ana
* Definitions of main types and relevant constants.
*/
//@{
typedef boost::uint32_t ana_uint32 /** Standard unsigned int, with fixed size to 32 bits. */ ;
typedef boost::int32_t ana_int32 /** Standard int, with fixed size to 32 bits. */ ;
typedef boost::uint16_t ana_uint16 /** Standard unsigned int, with fixed size to 16 bits. */ ;
typedef boost::int16_t ana_int16 /** Standard int, with fixed size to 16 bits. */ ;
/** Standard unsigned int, with fixed size to 32 bits. */
typedef boost::uint32_t ana_uint32 ;
/** Standard int, with fixed size to 32 bits. */
typedef boost::int32_t ana_int32 ;
typedef ana_uint32 message_size /** Message size type. */ ;
/** Standard unsigned int, with fixed size to 16 bits. */
typedef boost::uint16_t ana_uint16 ;
typedef size_t net_id /** IDs of connected components, unique, non zero. */ ;
typedef size_t operation_id /** IDs of network operations, unique, zero = no-op. */ ;
/** Standard int, with fixed size to 16 bits. */
typedef boost::int16_t ana_int16 ;
typedef std::string port /** Port type, a std::string (instead of a short.) */ ;
typedef std::string address /** Address type, a string. Either IP of hostname. */ ;
/** Message size type. */
typedef ana_uint32 message_size ;
typedef bool send_type /** Send operation type, true to copy the buffer. */ ;
/** IDs of connected components, unique, non zero. */
typedef size_t net_id ;
typedef boost::system::error_code error_code /** Standard error code, can evaluate to bool. */ ;
/** IDs of network operations, unique, zero = no-op. */
typedef size_t operation_id ;
const operation_id no_operation = 0 /** A network operation that didn't do anything. */ ;
/** Port type, a std::string (instead of a short.) */
typedef std::string port ;
const send_type ZERO_COPY = false /** Don't copy the buffer. */ ;
const send_type COPY_BUFFER = true /** Copy the buffer. */ ;
/** Address type, a string. Either IP of hostname. */
typedef std::string address ;
const message_size HEADER_LENGTH = sizeof(ana_uint32) /** Length of message header, 4 bytes. */ ;
const message_size INITIAL_RAW_MODE_BUFFER_SIZE = 256 /** Initial length of raw message buffer. */ ;
/** Send operation type, true to copy the buffer. */
typedef bool send_type ;
/** Standard error code, can evaluate to bool. */
typedef boost::system::error_code error_code ;
/** A network operation that didn't do anything. */
const operation_id no_operation = 0;
/** Don't copy the buffer. */
const send_type ZERO_COPY = false;
/** Copy the buffer. */
const send_type COPY_BUFFER = true ;
/** Length of message header, 4 bytes. */
const message_size HEADER_LENGTH = sizeof(ana_uint32);
/** Initial length of raw message buffer. */
const message_size INITIAL_RAW_MODE_BUFFER_SIZE = 256 ;
//@}
}

View file

@ -78,7 +78,8 @@ namespace ana
if (secs_to_reset_ > 0 )
{
timer_.expires_from_now( secs_to_reset_ );
timer_.async_wait(boost::bind( &stats_logger::reset, this, boost::asio::placeholders::error ) );
timer_.async_wait(boost::bind( &stats_logger::reset, this,
boost::asio::placeholders::error ) );
}
}
@ -121,7 +122,8 @@ namespace ana
if (secs_to_reset_ > 0 )
{
timer_.expires_from_now( secs_to_reset_ );
timer_.async_wait(boost::bind( &stats_logger::reset, this, boost::asio::placeholders::error ) );
timer_.async_wait(boost::bind( &stats_logger::reset, this,
boost::asio::placeholders::error ) );
}
}
@ -178,7 +180,8 @@ namespace ana
hours_stats_( time::hours(1), io_service_ ),
days_stats_( time::days(1), io_service_ )
{
collector_thread_ = new boost::thread( boost::bind(&boost::asio::io_service::run, &io_service_) );
collector_thread_ = new boost::thread( boost::bind(&boost::asio::io_service::run,
&io_service_) );
}
const stats* get_stats( stat_type type ) const

View file

@ -154,7 +154,8 @@ namespace ana
typedef boost::asio::basic_deadline_timer<std::time_t,detail::time_t_traits> boost_timer;
/** The default timeout error. */
const ana::error_code timeout_error = boost::asio::error::make_error_code( boost::asio::error::timed_out );
const ana::error_code timeout_error =
boost::asio::error::make_error_code( boost::asio::error::timed_out );
/**
* General purpose asynchronous timer.
@ -162,7 +163,10 @@ namespace ana
class timer
{
public:
/** Standard constructor. Creates its own io_service object and runs in its own thread.*/
/**
* Standard constructor.
* Creates its own io_service object and runs in its own thread.
*/
timer();
/**
@ -193,7 +197,8 @@ namespace ana
template<class Handler>
void wait(size_t milliseconds, Handler handler)
{
timer_.expires_from_now( milliseconds / 1000.0); //conversion will use a double or float
//conversion will use a double or float
timer_.expires_from_now( milliseconds / 1000.0);
timer_.async_wait(handler);
if ( holds_fresh_io_service_ )
@ -259,7 +264,8 @@ namespace ana
if ( timer != NULL )
{
if ( timeout_type_ == TimePerKilobyte)
timer->wait( (buffer->size() / 1024.0) * timeout_milliseconds_, handler);
timer->wait( (buffer->size() / 1024.0) * timeout_milliseconds_,
handler);
else
timer->wait( timeout_milliseconds_, handler);
}
@ -278,8 +284,11 @@ namespace ana
/** Standard constructor. */
timed_sender();
timeout_policy timeout_type_ /** Type of timer policy. */ ;
size_t timeout_milliseconds_ /** Amount of ms relevant to this policy. */ ;
/** Type of timer policy. */
timeout_policy timeout_type_ ;
/** Amount of ms relevant to this policy. */
size_t timeout_milliseconds_ ;
};
}
}

View file

@ -57,7 +57,7 @@ void show_help(char* const command)
"\t" << command << " billy localhost 12345\n" <<
"\t\tConnect to a local server on port 12345 with nick billy.\n" <<
"\t" << command << " billy X.K.C.D 12345 localhost 3128 foo bar\n" <<
"\t\tConnect to a remote server at X.K.C.D:12345 using a local proxy with credentials foo:bar.\n\n";
"\t\tConnect to a remote server at X.K.C.D:12345 with proxy credentials foo:bar.\n\n";
;
}
@ -121,37 +121,37 @@ class ChatClient : public ana::listener_handler,
const ana::stats* day_stats = client_->get_stats( ana::DAYS );
std::cout << " Network Statistics\n\n"
<< "Uptime : " << acum_stats->uptime() << " seconds.\n\n"
<< "+-----------------+-----------------+-----------------+\n"
<< "| | Packets | Bytes |\n"
<< "| +-----------------+--------+--------+\n"
<< "| | In | Out | In | Out |\n"
<< "+-----------------+--------+--------+--------+--------+\n"
<< "| Accumulated |" << std::setw(8) << acum_stats->packets_in() <<"|"
<< std::setw(8) << acum_stats->packets_out() <<"|"
<< std::setw(8) << acum_stats->bytes_in() <<"|"
<< std::setw(8) << acum_stats->bytes_out() <<"|\n"
<< "+-----------------+-----------------+-----------------+\n"
<< "| Last second |" << std::setw(8) << sec_stats->packets_in() <<"|"
<< std::setw(8) << sec_stats->packets_out() <<"|"
<< std::setw(8) << sec_stats->bytes_in() <<"|"
<< std::setw(8) << sec_stats->bytes_out() <<"|\n"
<< "+-----------------+-----------------+-----------------+\n"
<< "| Last minute |" << std::setw(8) << min_stats->packets_in() <<"|"
<< std::setw(8) << min_stats->packets_out() <<"|"
<< std::setw(8) << min_stats->bytes_in() <<"|"
<< std::setw(8) << min_stats->bytes_out() <<"|\n"
<< "+-----------------+-----------------+-----------------+\n"
<< "| Last hour |" << std::setw(8) << hour_stats->packets_in() <<"|"
<< std::setw(8) << hour_stats->packets_out() <<"|"
<< std::setw(8) << hour_stats->bytes_in() <<"|"
<< std::setw(8) << hour_stats->bytes_out() <<"|\n"
<< "+-----------------+-----------------+-----------------+\n"
<< "| Last day |" << std::setw(8) << day_stats->packets_in() <<"|"
<< std::setw(8) << day_stats->packets_out() <<"|"
<< std::setw(8) << day_stats->bytes_in() <<"|"
<< std::setw(8) << day_stats->bytes_out() <<"|\n"
<< "+-----------------+-----------------+-----------------+\n";
<< "Uptime : " << acum_stats->uptime() << " seconds.\n\n"
<< "+-----------------+-----------------+-----------------+\n"
<< "| | Packets | Bytes |\n"
<< "| +-----------------+--------+--------+\n"
<< "| | In | Out | In | Out |\n"
<< "+-----------------+--------+--------+--------+--------+\n"
<< "| Accumulated |" << std::setw(8) << acum_stats->packets_in() <<"|"
<< std::setw(8) << acum_stats->packets_out() <<"|"
<< std::setw(8) << acum_stats->bytes_in() <<"|"
<< std::setw(8) << acum_stats->bytes_out() <<"|\n"
<< "+-----------------+-----------------+-----------------+\n"
<< "| Last second |" << std::setw(8) << sec_stats->packets_in() <<"|"
<< std::setw(8) << sec_stats->packets_out() <<"|"
<< std::setw(8) << sec_stats->bytes_in() <<"|"
<< std::setw(8) << sec_stats->bytes_out() <<"|\n"
<< "+-----------------+-----------------+-----------------+\n"
<< "| Last minute |" << std::setw(8) << min_stats->packets_in() <<"|"
<< std::setw(8) << min_stats->packets_out() <<"|"
<< std::setw(8) << min_stats->bytes_in() <<"|"
<< std::setw(8) << min_stats->bytes_out() <<"|\n"
<< "+-----------------+-----------------+-----------------+\n"
<< "| Last hour |" << std::setw(8) << hour_stats->packets_in() <<"|"
<< std::setw(8) << hour_stats->packets_out() <<"|"
<< std::setw(8) << hour_stats->bytes_in() <<"|"
<< std::setw(8) << hour_stats->bytes_out() <<"|\n"
<< "+-----------------+-----------------+-----------------+\n"
<< "| Last day |" << std::setw(8) << day_stats->packets_in() <<"|"
<< std::setw(8) << day_stats->packets_out() <<"|"
<< std::setw(8) << day_stats->bytes_in() <<"|"
<< std::setw(8) << day_stats->bytes_out() <<"|\n"
<< "+-----------------+-----------------+-----------------+\n";
}
}

View file

@ -77,7 +77,8 @@ class ChatServer : public listener_handler,
if (! error)
{
std::stringstream ss;
ss << "Server: User " << client << " has joined from " << server_->ip_address( client ) << ".";
ss << "Server: User " << client << " has joined from "
<< server_->ip_address( client ) << ".";
server_->send_all_except(client, ana::buffer( ss.str() ), this);
}
}
@ -123,7 +124,9 @@ class ChatServer : public listener_handler,
}
}
virtual void handle_message( ana::error_code error, net_id client, ana::detail::read_buffer buffer)
virtual void handle_message( ana::error_code error,
net_id client,
ana::detail::read_buffer buffer)
{
if (! error)
{

View file

@ -69,7 +69,8 @@ namespace network
client( wesnoth_client_interface* handler );
// Example, set_timeout( network::SEND_OPERATIONS, ana::time::seconds( 10 ) );
// set_timeout( network::SEND_OPERATIONS, ana::KILOBYTES(1), ana::time::seconds( 1 ) ); (?)
// set_timeout( network::SEND_OPERATIONS, ana::KILOBYTES(1),
// ana::time::seconds( 1 ) ); (?)
// set_timeout( network::CONNECT_OPERATIONS, ana::time::seconds( 30 ) );
void set_timeout( ... );
@ -110,7 +111,8 @@ namespace network
// Set timeouts for a given client
// Example, set_timeout( 1, network::SEND_OPERATIONS, ana::time::seconds( 10 ) );
// set_timeout( 2, network::SEND_OPERATIONS, ana::KILOBYTES(1), ana::time::seconds( 1 ) ); (?)
// set_timeout( 2, network::SEND_OPERATIONS, ana::KILOBYTES(1),
// ana::time::seconds( 1 ) ); (?)
void set_timeout( ana::net_id, ... );
// Attempt to send a WML config to a client

View file

@ -73,7 +73,8 @@ void asio_client::run()
io_thread_ = boost::thread( boost::bind( &boost::asio::io_service::run, &io_service_) );
}
void asio_client::handle_proxy_connection(const boost::system::error_code& ec, ana::connection_handler* handler)
void asio_client::handle_proxy_connection(const boost::system::error_code& ec,
ana::connection_handler* handler)
{
handler->handle_connect( ec, 0 );

View file

@ -81,7 +81,8 @@ class asio_client : public ana::client,
virtual void disconnect_listener();
virtual void handle_proxy_connection(const boost::system::error_code&, ana::connection_handler*);
virtual void handle_proxy_connection(const boost::system::error_code&,
ana::connection_handler*);
virtual tcp::socket& socket();

View file

@ -118,7 +118,8 @@ void asio_listener::handle_header(char* header, const boost::system::error_code&
if (size != 0)
{
ana::detail::read_buffer read_buf( new ana::detail::read_buffer_implementation( size ) );
ana::detail::read_buffer read_buf(
new ana::detail::read_buffer_implementation( size ) );
socket().async_read_some(boost::asio::buffer(read_buf->base(), read_buf->size() ),
boost::bind(&asio_listener::handle_partial_body,
@ -127,7 +128,9 @@ void asio_listener::handle_header(char* header, const boost::system::error_code&
}
else
{ // copy the header to a read_buffer
ana::detail::read_buffer read_buf ( new ana::detail::read_buffer_implementation( ana::HEADER_LENGTH ) );
ana::detail::read_buffer read_buf ( new ana::detail::read_buffer_implementation(
ana::HEADER_LENGTH ) );
for (size_t i(0); i< ana::HEADER_LENGTH; ++i)
static_cast<char*>(read_buf->base())[i] = header[i];
@ -171,7 +174,8 @@ void asio_listener::handle_partial_body( ana::detail::read_buffer buffer
buffer->size() - accumulated),
boost::bind(&asio_listener::handle_partial_body,
this, buffer,
boost::asio::placeholders::error, accumulated, _2 ));
boost::asio::placeholders::error,
accumulated, _2 ));
}
}
catch(const std::exception& e)
@ -181,7 +185,9 @@ void asio_listener::handle_partial_body( ana::detail::read_buffer buffer
}
void asio_listener::handle_raw_buffer( ana::detail::read_buffer buf, const boost::system::error_code& ec, size_t read_size)
void asio_listener::handle_raw_buffer( ana::detail::read_buffer buf,
const boost::system::error_code& ec,
size_t read_size)
{
try
{
@ -238,9 +244,11 @@ void asio_listener::listen_one_message()
header_, boost::asio::placeholders::error));
else
{
ana::detail::read_buffer raw_buffer( new ana::detail::read_buffer_implementation( raw_mode_buffer_size_ ) );
ana::detail::read_buffer raw_buffer(
new ana::detail::read_buffer_implementation( raw_mode_buffer_size_ ) );
socket().async_read_some(boost::asio::buffer(raw_buffer->base(), raw_mode_buffer_size_ ),
socket().async_read_some(boost::asio::buffer(raw_buffer->base(),
raw_mode_buffer_size_ ),
boost::bind(&asio_listener::handle_raw_buffer, this,
raw_buffer, boost::asio::placeholders::error, _2));
}

View file

@ -34,7 +34,10 @@
#include "asio_proxy_connection.hpp"
proxy_connection::proxy_connection(tcp::socket& socket, proxy_information pi, ana::address address, ana::port port) :
proxy_connection::proxy_connection(tcp::socket& socket,
proxy_information pi,
ana::address address,
ana::port port) :
socket_(socket),
proxy_info_(pi),
address_(address),
@ -63,7 +66,8 @@ std::string* proxy_connection::generate_base64_credentials() const
"CONNECT " + address_ + ":" + port_ + " HTTP/1.0\n"
"User-agent: ana 0.1 \n"
"Proxy-Connection: keep-alive\n"
"Proxy-Authorization: Basic " + base64_encode(user_and_pass.c_str(), user_and_pass.size() ) + "\n"
"Proxy-Authorization: Basic " + base64_encode(user_and_pass.c_str(),
user_and_pass.size() ) + "\n"
"\n"
);
}
@ -75,7 +79,8 @@ std::string proxy_connection::base64_encode(char const* bytes_to_encode, unsigne
int j = 0;
unsigned char char_array_3[3];
unsigned char char_array_4[4];
const char base64_chars[(1 << 6) + 2] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
const char base64_chars[(1 << 6) + 2]
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
while (in_len--) {
char_array_3[i++] = *(bytes_to_encode++);
@ -150,7 +155,7 @@ void proxy_connection::handle_response(boost::asio::streambuf* buf,
conn_handler_);
}
else //Couldn't connect, wrong password or wasn't offered the possibility to authenticate
else //Can't connect, wrong password or wasn't offered the possibility to authenticate
manager_->handle_proxy_connection(
boost::system::error_code(1,boost::system::system_category ),
conn_handler_);
@ -210,7 +215,8 @@ void proxy_connection::do_connect()
try
{
tcp::resolver resolver( socket_.get_io_service() );
tcp::resolver::query query(proxy_info_.proxy_address.c_str(), proxy_info_.proxy_port.c_str() );
tcp::resolver::query query(proxy_info_.proxy_address.c_str(),
proxy_info_.proxy_port.c_str() );
tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
tcp::endpoint endpoint = *endpoint_iterator;
@ -227,7 +233,8 @@ void proxy_connection::do_connect()
}
}
void proxy_connection::connect( proxy_connection_manager* manager, ana::connection_handler* handler )
void proxy_connection::connect( proxy_connection_manager* manager,
ana::connection_handler* handler )
{
manager_ = manager;
conn_handler_ = handler;

View file

@ -45,7 +45,8 @@ struct proxy_connection_manager
{
virtual ~proxy_connection_manager() {}
virtual void handle_proxy_connection(const boost::system::error_code&, ana::connection_handler* ) = 0;
virtual void handle_proxy_connection(const boost::system::error_code&,
ana::connection_handler* ) = 0;
};
struct proxy_information
@ -80,11 +81,14 @@ class proxy_connection
void do_connect( );
void handle_connect(const boost::system::error_code& ec, tcp::resolver::iterator endpoint_iterator);
void handle_connect(const boost::system::error_code& ec,
tcp::resolver::iterator endpoint_iterator);
void handle_sent_request(const boost::system::error_code& ec, std::string* request);
void handle_response( boost::asio::streambuf* buf , const boost::system::error_code&, size_t );
void handle_response( boost::asio::streambuf* buf,
const boost::system::error_code&,
size_t );
bool finds( const std::string& source, char const* pattern );

View file

@ -75,7 +75,8 @@ void asio_sender::send(ana::detail::shared_buffer buffer ,
socket.async_write_some( boost::asio::buffer( output_stream->str() ),
boost::bind(&asio_sender::handle_sent_header,this,
boost::asio::placeholders::error, output_stream,
&socket, buffer, handler, running_timer, _2, op_id ));
&socket, buffer,
handler, running_timer, _2, op_id ));
}
}
catch(std::exception& e)
@ -140,7 +141,8 @@ void asio_sender::handle_partial_send( ana::detail::shared_buffer buffer,
buffer->size() - accumulated),
boost::bind(&asio_sender::handle_partial_send, this,
buffer, boost::asio::placeholders::error,
socket, handler, timer, accumulated, _2, op_id ));
socket, handler, timer,
accumulated, _2, op_id ));
}
}
catch(const std::exception& e)

View file

@ -162,7 +162,9 @@ void asio_server::handle_accept(const boost::system::error_code& ec,
void asio_server::run_listener( )
{
for (std::list<client_proxy*>::iterator it( client_proxies_.begin() ); it != client_proxies_.end(); ++it)
for (std::list<client_proxy*>::iterator it( client_proxies_.begin() );
it != client_proxies_.end();
++it)
{
(*it)->set_listener_handler( listener_ );
(*it)->run_listener( );
@ -301,6 +303,11 @@ void asio_server::stop_logging()
stats_collector_ = NULL;
}
ana::timer* asio_server::create_timer()
{
return new ana::timer( socket_.get_io_service() );
}
const ana::stats* asio_server::get_stats( ana::stat_type type ) const
{
if (stats_collector_ != NULL )
@ -310,7 +317,8 @@ const ana::stats* asio_server::get_stats( ana::stat_type type ) const
}
asio_server::asio_client_proxy::asio_client_proxy(boost::asio::io_service& io_service, asio_proxy_manager* server) :
asio_server::asio_client_proxy::asio_client_proxy(boost::asio::io_service& io_service,
asio_proxy_manager* server) :
client_proxy(),
asio_listener(),
socket_(io_service),
@ -330,10 +338,10 @@ tcp::socket& asio_server::asio_client_proxy::socket()
return socket_;
}
void asio_server::asio_client_proxy::log_conditional_receive( const ana::detail::read_buffer& buffer )
void asio_server::asio_client_proxy::log_conditional_receive( const ana::detail::read_buffer& buf )
{
if ( stats_collector_ != NULL )
stats_collector_->log_receive( buffer );
stats_collector_->log_receive( buf );
}
void asio_server::asio_client_proxy::start_logging()
@ -364,8 +372,12 @@ void asio_server::disconnect()
io_service_.stop();
io_thread_.join();
for (std::list<client_proxy*>::iterator it = client_proxies_.begin(); it != client_proxies_.end(); ++it)
for (std::list<client_proxy*>::iterator it = client_proxies_.begin();
it != client_proxies_.end();
++it)
{
delete *it;
}
client_proxies_.clear();
@ -374,8 +386,12 @@ void asio_server::disconnect()
void asio_server::set_raw_buffer_max_size( size_t size)
{
for (std::list<client_proxy*>::iterator it = client_proxies_.begin(); it != client_proxies_.end(); ++it)
for (std::list<client_proxy*>::iterator it = client_proxies_.begin();
it != client_proxies_.end();
++it)
{
(*it)->set_raw_buffer_max_size( size );
}
}
void asio_server::set_header_first_mode( ana::net_id id )

View file

@ -81,7 +81,7 @@ class asio_server : public ana::server,
virtual ana::stats_collector* stats_collector() { return stats_collector_; }
virtual ana::timer* create_timer() { return new ana::timer( socket_.get_io_service() ); }
virtual ana::timer* create_timer();
virtual const ana::stats* get_stats( ana::stat_type type ) const;
@ -154,7 +154,9 @@ class asio_server : public ana::server,
virtual void set_raw_data_mode( ana::net_id id );
void handle_accept (const boost::system::error_code& ec,asio_client_proxy* client, ana::connection_handler* );
void handle_accept (const boost::system::error_code& ec,
asio_client_proxy* client,
ana::connection_handler* handler);
void register_client(client_proxy* client);

View file

@ -51,13 +51,15 @@ namespace ana
}
// Subtract one time from another.
time_t_traits::duration_type time_t_traits::subtract(const time_type& t1, const time_type& t2)
time_t_traits::duration_type time_t_traits::subtract(const time_type& t1,
const time_type& t2)
{
return duration_type(t1 - t2);
}
// Test whether one time is less than another.
bool time_t_traits::less_than(const time_t_traits::time_type& t1, const time_t_traits::time_type& t2)
bool time_t_traits::less_than(const time_t_traits::time_type& t1,
const time_t_traits::time_type& t2)
{
return t1 < t2;
}

View file

@ -131,7 +131,9 @@ namespace network {
{
}
server_manager::server_manager(int port, CREATE_SERVER create_server) : free_(false), connection_(0)
server_manager::server_manager(int port, CREATE_SERVER create_server)
: free_(false),
connection_(0)
{
std::cout << "DEBUG: server_manager\n";
if ( create_server != NO_SERVER )
@ -307,7 +309,9 @@ namespace network {
{
}
void send_file(const std::string& /*filename*/, connection /*connection_num*/, const std::string& /*packet_type*/)
void send_file(const std::string& /*filename*/,
connection /*connection_num*/,
const std::string& /*packet_type*/)
{
throw std::runtime_error("TODO:Not implemented send_file");
}

View file

@ -30,7 +30,7 @@
#include "gettext.hpp"
// Begin ana_send_handler implementation ---------------------------------------------------------------
// Begin ana_send_handler implementation ----------------------------------------------------------
ana_send_handler::ana_send_handler( size_t calls ) :
mutex_(),
@ -67,7 +67,7 @@ void ana_send_handler::wait_completion()
mutex_.unlock();
}
// Begin ana_handshake_finisher_handler implementation ------------------------------------------------------------
// Begin ana_handshake_finisher_handler implementation --------------------------------------------
ana_handshake_finisher_handler::ana_handshake_finisher_handler( ana::server* server,
clients_manager* mgr)
@ -92,7 +92,7 @@ void ana_handshake_finisher_handler::handle_send(ana::error_code ec,
delete this;
}
// Begin ana_receive_handler implementation ------------------------------------------------------------
// Begin ana_receive_handler implementation -------------------------------------------------------
ana_receive_handler::ana_receive_handler( ana_component_set::iterator iterator ) :
iterator_( iterator ),
@ -130,7 +130,9 @@ void ana_receive_handler::wait_completion(ana::detail::timed_sender* component,
receive_timer_ = component->create_timer();
receive_timer_->wait( ana::time::milliseconds(timeout_ms),
boost::bind(&ana_receive_handler::handle_timeout, this, ana::timeout_error ) );
boost::bind(&ana_receive_handler::handle_timeout,
this,
ana::timeout_error ) );
}
}
@ -192,7 +194,7 @@ void ana_receive_handler::handle_timeout(ana::error_code error_code)
timeout_called_mutex_.unlock();
}
// Begin ana_multiple_receive_handler implementation ------------------------------------------------------------
// Begin ana_multiple_receive_handler implementation ----------------------------------------------
ana_multiple_receive_handler::ana_multiple_receive_handler( ana_component_set& components ) :
components_( components ),
@ -255,7 +257,9 @@ void ana_multiple_receive_handler::wait_completion(size_t timeout_ms )
receive_timer_ = component->create_timer();
receive_timer_->wait( ana::time::milliseconds(timeout_ms),
boost::bind(&ana_multiple_receive_handler::handle_timeout, this, ana::timeout_error ) );
boost::bind(&ana_multiple_receive_handler::handle_timeout,
this,
ana::timeout_error ) );
}
}
mutex_.lock();
@ -329,7 +333,7 @@ void ana_multiple_receive_handler::handle_timeout(ana::error_code error_code)
}
// Begin ana_connect_handler implementation ------------------------------------------------------------
// Begin ana_connect_handler implementation -------------------------------------------------------
ana_connect_handler::ana_connect_handler( ) :
mutex_( ),
@ -368,7 +372,7 @@ void ana_connect_handler::wait_completion()
mutex_.unlock();
}
// Begin ana_component implementation ------------------------------------------------------------------
// Begin ana_component implementation -------------------------------------------------------------
ana_component::ana_component( ) :
base_( ana::server::create() ),
@ -528,7 +532,7 @@ network::connection ana_component::oldest_sender_id_still_pending()
return id;
}
// Begin clients_manager implementation ---------------------------------------------------------------
// Begin clients_manager implementation ----------------------------------------------------------
clients_manager::clients_manager( ana::server* server) :
server_( server ),
@ -600,7 +604,7 @@ network::connection clients_manager::get_pending_connection_id()
return result;
}
// Begin ana_network_manager implementation ------------------------------------------------------------
// Begin ana_network_manager implementation -------------------------------------------------------
ana_network_manager::ana_network_manager() :
connect_timer_( NULL ),
@ -884,7 +888,9 @@ size_t ana_network_manager::send_all( const config& cfg, bool zipped )
return output_string.size();
}
size_t ana_network_manager::send( network::connection connection_num , const config& cfg, bool zipped )
size_t ana_network_manager::send( network::connection connection_num ,
const config& cfg,
bool zipped )
{
if ( ! zipped )
throw std::runtime_error("All send operations should be zipped");
@ -897,7 +903,9 @@ size_t ana_network_manager::send( network::connection connection_num , const con
return send_raw_data( output_string.c_str(), output_string.size(), connection_num );
}
size_t ana_network_manager::send_raw_data( const char* base_char, size_t size, network::connection connection_num )
size_t ana_network_manager::send_raw_data( const char* base_char,
size_t size,
network::connection connection_num )
{
ana::net_id id( connection_num );
ana_component_set::iterator it;
@ -925,8 +933,8 @@ size_t ana_network_manager::send_raw_data( const char* base_char, size_t size, n
{
if ((*it)->is_server())
{
ana_send_handler handler;
(*it)->server()->send_one( id, ana::buffer( base_char, size ), &handler); //, ana::ZERO_COPY);
ana_send_handler handler; //, ana::ZERO_COPY);
(*it)->server()->send_one( id, ana::buffer( base_char, size ), &handler);
handler.wait_completion();
if ( handler.error() )
return 0;
@ -958,7 +966,9 @@ void ana_network_manager::send_all_except(const config& cfg, network::connection
{
if ( server_manager_[ (*it)->server() ]->is_a_client( id_to_avoid ) )
{
const size_t clients_receiving_number = server_manager_[ (*it)->server() ]->client_amount() - 1;
const size_t clients_receiving_number
= server_manager_[ (*it)->server() ]->client_amount() - 1;
ana_send_handler handler( clients_receiving_number );
(*it)->server()->send_all_except( id_to_avoid,
ana::buffer( output_string ),
@ -979,7 +989,8 @@ void ana_network_manager::send_all_except(const config& cfg, network::connection
}
}
network::connection ana_network_manager::read_from_ready_buffer( const ana_component_set::iterator& it, config& cfg)
network::connection ana_network_manager::read_from_ready_buffer(
const ana_component_set::iterator& it, config& cfg)
{
read_config( (*it)->wait_for_element(), cfg);
@ -1055,7 +1066,6 @@ network::connection ana_network_manager::read_from( network::connection connecti
if ( handler.error() )
{
// For concurrency reasons, this checks if the old handler was used before the wait operation
for (it = components_.begin(); it != components_.end(); ++it)
if ( (*it)->new_buffer_ready() )
return read_from_ready_buffer( it, cfg );
@ -1178,7 +1188,8 @@ void ana_network_manager::handle_message( ana::error_code error,
network::disconnect( client );
else
{
std::cout << "DEBUG: Buffer received with size " << buffer->size() << " from " << client << "\n";
std::cout << "DEBUG: Buffer received with size " << buffer->size()
<< " from " << client << "\n";
std::set< ana_component* >::iterator it;
@ -1208,7 +1219,7 @@ void ana_network_manager::handle_message( ana::error_code error,
ana::serializer::bistream bis( buffer->string() );
bis >> handshake;
ana::network_to_host_long( handshake ); //not necessary since I'm expecting a 0 anyway
ana::network_to_host_long( handshake ); //I'm expecting a 0 anyway
}
if ( handshake != 0 )

View file

@ -233,7 +233,8 @@ class ana_receive_handler : public ana::listener_handler
* If the timeout parameter is 0, it will lock the current thread until
* one of these components has received a message.
*
* @param component : A network component running an io_service which supports timeout capabilities.
* @param component : A network component running an io_service which
* supports timeout capabilities.
* @param timeout_ms : Amount of milliseconds to timeout the operation.
*/
void wait_completion(ana::detail::timed_sender* component, size_t timeout_ms = 0);
@ -283,7 +284,8 @@ class ana_multiple_receive_handler : public ana::listener_handler
* If the timeout parameter is 0, it will lock the current thread until
* one of these components has received a message.
*
* @param component : A network component running an io_service which supports timeout capabilities.
* @param component : A network component running an io_service
* which supports timeout capabilities.
* @param timeout_ms : Amount of milliseconds to timeout the operation.
*/
void wait_completion(size_t timeout_ms = 0);
@ -336,7 +338,8 @@ class ana_connect_handler : public ana::connection_handler
/**
* Constructs a connection handler.
*
* @param timer : A pointer to a running timer dealing with the timeout of this connect operation.
* @param timer : A pointer to a running timer dealing with the timeout
* of this connect operation.
*/
ana_connect_handler( );
@ -433,7 +436,8 @@ class ana_network_manager : public ana::listener_handler,
* @param cfg : The config input to place the read data.
* @param timeout_ms : Amount of milliseconds to wait for the data.
*
* @returns The network::connection number of the component that read the data or 0 if an error occurred.
* @returns The network::connection number of the component that read
* the data or 0 if an error occurred.
*/
network::connection read_from( network::connection connection_num,
config& cfg,
@ -446,7 +450,8 @@ class ana_network_manager : public ana::listener_handler,
* @param cfg : The config input to place the read data.
* @param timeout_ms : Amount of milliseconds to wait for the data.
*
* @returns The network::connection number of the component that read the data or 0 if an error occurred.
* @returns The network::connection number of the component that read
* the data or 0 if an error occurred.
*/
network::connection read_from( const ana_component_set::iterator& it,
config& cfg,
@ -460,9 +465,11 @@ class ana_network_manager : public ana::listener_handler,
* @param it : The ana component to read from.
* @param cfg : The config input to place the read data.
*
* @returns The network::connection number of the component that read the data or 0 if an error occurred.
* @returns The network::connection number of the component that read
* the data or 0 if an error occurred.
*/
network::connection read_from_ready_buffer( const ana_component_set::iterator& it, config& cfg);
network::connection read_from_ready_buffer( const ana_component_set::iterator& it,
config& cfg);
/** Retrieve upload statistics on a given component. */
network::statistics get_send_stats(network::connection handle);