Remove some unused files.
This commit is contained in:
parent
f2d3cef13f
commit
a2acee4356
2 changed files with 0 additions and 376 deletions
|
@ -1,226 +0,0 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file network.cpp
|
||||
//! Networking
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#include "serialization/binary_wml.hpp"
|
||||
#include "config.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "log.hpp"
|
||||
#include "network_new.hpp"
|
||||
#include "network_boost.hpp"
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cerrno>
|
||||
#include <queue>
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <ctime>
|
||||
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
|
||||
#undef INADDR_ANY
|
||||
#undef INADDR_BROADCAST
|
||||
#undef INADDR_NONE
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h> // for TCP_NODELAY
|
||||
#ifdef __BEOS__
|
||||
#include <socket.h>
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#define SOCKET int
|
||||
#endif
|
||||
|
||||
#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)
|
||||
// Only warnings and not errors to avoid DoS by log flooding
|
||||
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
} // end anon namespace
|
||||
|
||||
namespace network {
|
||||
|
||||
network_boost::connection::statistics get_connection_stats(connection connection_num)
|
||||
{
|
||||
return network_boost::manager::get_manager()->get_connection(connection_num)->get_statistics();
|
||||
}
|
||||
|
||||
network_boost::manager* manager::boost_manager_ = 0;
|
||||
|
||||
manager::manager(size_t /*min_threads*/, size_t /*max_threads*/) : free_(true)
|
||||
{
|
||||
// If the network is already being managed
|
||||
if(!boost_manager_) {
|
||||
free_ = false;
|
||||
return;
|
||||
}
|
||||
|
||||
boost_manager_ = new network_boost::manager();
|
||||
|
||||
}
|
||||
|
||||
manager::~manager()
|
||||
{
|
||||
if(free_) {
|
||||
delete boost_manager_;
|
||||
boost_manager_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void set_raw_data_only()
|
||||
{
|
||||
}
|
||||
|
||||
network_boost::connection_id server_connection;
|
||||
|
||||
server_manager::server_manager(int port, CREATE_SERVER create_server) : free_(false)
|
||||
{
|
||||
if(create_server != NO_SERVER) {
|
||||
server_connection = network_boost::manager::get_manager()->listen(port)->get_id();
|
||||
free_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
server_manager::~server_manager()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
void server_manager::stop()
|
||||
{
|
||||
if(free_) {
|
||||
network_boost::manager::get_manager()->get_connection(server_connection)->disconnect();
|
||||
free_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool server_manager::is_running() const
|
||||
{
|
||||
return !free_;
|
||||
}
|
||||
|
||||
size_t nconnections()
|
||||
{
|
||||
return network_boost::manager::get_manager()->nconnections();
|
||||
}
|
||||
|
||||
|
||||
connection connect(const std::string& host, int port)
|
||||
{
|
||||
return network_boost::manager::get_manager()->connect(host,port, network_boost::connection::GZIP)->get_id();
|
||||
}
|
||||
|
||||
connection connect(const std::string& host, int port, threading::waiter& /*waiter*/)
|
||||
{
|
||||
return connect(host, port);
|
||||
}
|
||||
|
||||
connection accept_connection()
|
||||
{
|
||||
network_boost::connection_ptr new_con;
|
||||
if (network_boost::manager::get_manager()->accept(new_con))
|
||||
{
|
||||
return new_con->get_id();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool disconnect(connection s, bool force)
|
||||
{
|
||||
if(s == 0) {
|
||||
network_boost::manager::get_manager()->disconnect_all();
|
||||
}
|
||||
else
|
||||
{
|
||||
network_boost::manager::get_manager()->get_connection(s)->disconnect(force);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void queue_disconnect(network::connection sock)
|
||||
{
|
||||
network_boost::manager::get_manager()->get_connection(sock)->disconnect();
|
||||
}
|
||||
|
||||
|
||||
connection receive_data(config& cfg, connection /*connection_num*/, bool*)
|
||||
{
|
||||
network_boost::connection_ptr connection;
|
||||
network_boost::buffer_ptr buffer;
|
||||
if (network_boost::manager::get_manager()->receive_data(connection, buffer))
|
||||
{
|
||||
buffer->get_config(cfg);
|
||||
return connection->get_id();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
connection receive_data(std::vector<char>& buf)
|
||||
{
|
||||
network_boost::connection_ptr connection;
|
||||
network_boost::buffer_ptr buffer;
|
||||
if (network_boost::manager::get_manager()->receive_data(connection, buffer))
|
||||
{
|
||||
buffer->get_raw_buffer(buf);
|
||||
return connection->get_id();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void send_file(const std::string& filename, connection connection_num)
|
||||
{
|
||||
network_boost::buffer_ptr buffer(new network_boost::file_buffer(filename));
|
||||
network_boost::manager::get_manager()->get_connection(connection_num)->send_buffer(buffer);
|
||||
}
|
||||
|
||||
//! @todo Note the gzipped parameter should be removed later, we want to send
|
||||
//! all data gzipped. This can be done once the campaign server is also updated
|
||||
//! to work with gzipped data.
|
||||
void send_data(const config& cfg, connection connection_num, const bool /*gzipped*/)
|
||||
{
|
||||
network_boost::buffer_ptr buffer(new network_boost::config_buffer(cfg));
|
||||
network_boost::manager::get_manager()->get_connection(connection_num)->send_buffer(buffer);
|
||||
}
|
||||
|
||||
void process_send_queue(connection, size_t)
|
||||
{
|
||||
network_boost::manager::get_manager()->handle_network();
|
||||
}
|
||||
|
||||
std::string ip_address(connection connection_num)
|
||||
{
|
||||
return network_boost::manager::get_manager()->get_connection(connection_num)->get_ip_address();
|
||||
}
|
||||
|
||||
} // end namespace network
|
|
@ -1,150 +0,0 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file network.hpp
|
||||
//!
|
||||
|
||||
#ifndef NETWORK_HPP_INCLUDED
|
||||
#define NETWORK_HPP_INCLUDED
|
||||
|
||||
class config;
|
||||
|
||||
#include "network_boost.hpp"
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace threading
|
||||
{
|
||||
class waiter;
|
||||
}
|
||||
|
||||
// This module wraps the network interface.
|
||||
|
||||
namespace network {
|
||||
|
||||
// A network manager must be created before networking can be used.
|
||||
// It must be destroyed only after all networking activity stops.
|
||||
|
||||
// min_threads is the maximum number we allow to wait,
|
||||
// if more threads attempt to wait, they will die.
|
||||
// If min_threads == 0 no thread will ever be destroyed,
|
||||
// and we will stay at the max number of threads ever needed.
|
||||
|
||||
// max_threads is the overall max number of helper threads.
|
||||
// If we have that many threads already running, we will never create more.
|
||||
// If max_threads == 0 we will always create a thread if we need it.
|
||||
struct manager {
|
||||
explicit manager(size_t min_threads = 1,size_t max_threads = 0);
|
||||
~manager();
|
||||
|
||||
private:
|
||||
bool free_;
|
||||
static network_boost::manager* boost_manager_;
|
||||
|
||||
manager(const manager&);
|
||||
void operator=(const manager&);
|
||||
};
|
||||
|
||||
void set_raw_data_only();
|
||||
|
||||
//! A server manager causes listening on a given port
|
||||
//! to occur for the duration of its lifetime.
|
||||
struct server_manager {
|
||||
|
||||
//! Parameter to pass to the constructor.
|
||||
enum CREATE_SERVER { MUST_CREATE_SERVER, //!< Will throw exception on failure
|
||||
TRY_CREATE_SERVER, //!< Will swallow failure
|
||||
NO_SERVER }; //!< Won't try to create a server at all
|
||||
|
||||
// Throws error.
|
||||
server_manager(int port, CREATE_SERVER create_server=MUST_CREATE_SERVER);
|
||||
~server_manager();
|
||||
|
||||
bool is_running() const;
|
||||
void stop();
|
||||
|
||||
private:
|
||||
bool free_;
|
||||
};
|
||||
|
||||
typedef int connection;
|
||||
|
||||
connection const null_connection = 0;
|
||||
|
||||
//! The number of peers we are connected to.
|
||||
size_t nconnections();
|
||||
|
||||
//! Function to attempt to connect to a remote host.
|
||||
//! Returns the new connection on success, or 0 on failure.
|
||||
//! Throws error.
|
||||
connection connect(const std::string& host, int port=15000);
|
||||
|
||||
connection connect(const std::string& host, int port, threading::waiter& waiter);
|
||||
|
||||
//! 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.
|
||||
connection accept_connection();
|
||||
|
||||
//! 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.
|
||||
bool disconnect(connection connection_num=0, bool force=false);
|
||||
|
||||
//! 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).
|
||||
void queue_disconnect(connection connection_num);
|
||||
|
||||
//! 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.
|
||||
connection receive_data(config& cfg, connection, bool* g = 0);
|
||||
//connection receive_data(std::vector<char>& buf);
|
||||
|
||||
void send_file(const std::string&, connection);
|
||||
|
||||
//! Function to send data down a given connection,
|
||||
//! or broadcast to all peers if connection_num is 0.
|
||||
//! Throws error.
|
||||
void send_data(const config& cfg, connection connection_num /*= 0*/, const bool gzipped);
|
||||
|
||||
void send_raw_data(const char* buf, int len, connection connection_num);
|
||||
|
||||
//! 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 process_send_queue(connection connection_num=0, size_t max_size=0);
|
||||
|
||||
//! Function to send data to all peers except 'connection_num'.
|
||||
//void send_data_all_except(const config& cfg, connection connection_num, const bool gzipped);
|
||||
|
||||
//! Function to get the remote ip address of a socket.
|
||||
std::string ip_address(connection connection_num);
|
||||
|
||||
} // network namespace
|
||||
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue