1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

More changes for netcode/serialization

Removed not needed stuff
This commit is contained in:
Michał W. Urbańczyk
2008-07-25 17:28:28 +00:00
parent 358ab062eb
commit 0c139e72f5
62 changed files with 1102 additions and 5137 deletions

View File

@@ -18,6 +18,38 @@ using namespace boost::asio::ip;
#define LIL_ENDIAN
#endif
//CConnection & operator<<(CConnection &c, const std::string &data)
//{
// boost::uint32_t length = data.size();
// c << length;
// c.write(data.c_str(),length);
// return c;
//}
//CConnection & operator>>(CConnection &c, std::string &data)
//{
// boost::uint32_t length;
// c >> length;
// data.resize(length);
// c.read((void*)data.c_str(),length);
// return c;
//}
//CConnection & operator<<(CConnection &c, const char * &data)
//{
// boost::uint32_t length = strlen(data);
// c << length;
// c.write(data,length);
// return c;
//}
//CConnection & operator>>(CConnection &c, char * &data)
//{
// boost::uint32_t length;
// c >> length;
// std::cout <<"Alokujemy " <<length << " bajtow."<<std::endl;
// data = new char[length];
// c.read(data,length);
// return c;
//}
void CConnection::init()
{
#ifdef LIL_ENDIAN
@@ -34,7 +66,7 @@ void CConnection::init()
}
CConnection::CConnection(std::string host, std::string port, std::string Name, std::ostream & Out)
:io_service(new asio::io_service), name(Name), out(Out), send(this), rec(this)
:io_service(new asio::io_service), name(Name), out(Out)//, send(this), rec(this)
{
system::error_code error = asio::error::host_not_found;
socket = new tcp::socket(*io_service);
@@ -48,12 +80,12 @@ CConnection::CConnection(
boost::asio::basic_stream_socket<boost::asio::ip::tcp , boost::asio::stream_socket_service<boost::asio::ip::tcp> > * Socket,
std::string Name,
std::ostream & Out )
:socket(Socket),io_service(Socket->io_service()), out(Out), name(Name), send(this), rec(this)
:socket(Socket),io_service(&Socket->io_service()), out(Out), name(Name)//, send(this), rec(this)
{
init();
}
CConnection::CConnection(boost::asio::basic_socket_acceptor<boost::asio::ip::tcp, boost::asio::socket_acceptor_service<boost::asio::ip::tcp> > * acceptor, boost::asio::io_service *Io_service, std::string Name, std::ostream & Out)
: out(Out), name(Name), send(this), rec(this)
: out(Out), name(Name)//, send(this), rec(this)
{
system::error_code error = asio::error::host_not_found;
socket = new tcp::socket(*io_service);
@@ -70,13 +102,14 @@ int CConnection::write(const void * data, unsigned size)
}
int CConnection::read(void * data, unsigned size)
{
LOG("odbieram dane o rozmiarze " << size << std::endl);
int ret = asio::read(*socket,asio::mutable_buffers_1(asio::mutable_buffer(data,size)));
return ret;
}
CConnection::~CConnection(void)
{
delete io_service;
if(socket)
socket->close();
delete socket;
delete io_service;
}