#define VCMI_DLL #pragma warning(disable:4355) #include "Connection.h" #include #include using namespace boost; using namespace boost::asio::ip; #define LOG(a) \ if(logging)\ out << a #if defined(__hppa__) || \ defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \ (defined(__MIPS__) && defined(__MISPEB__)) || \ defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \ defined(__sparc__) #define BIG_ENDIAN #else #define LIL_ENDIAN #endif void CConnection::init() { #ifdef LIL_ENDIAN myEndianess = true; #else myEndianess = false; #endif connected = true; std::string pom; //we got connection (*this) << std::string("Aiya!\n") << name << myEndianess; //identify ourselves (*this) >> pom >> pom >> contactEndianess; out << "Established connection with "<connect(*endpoint_iterator, error); if (error){ delete socket; throw "Can't establish connection :("; } init(); } CConnection::CConnection( boost::asio::basic_stream_socket > * Socket, std::string Name, std::ostream & Out ) :socket(Socket),io_service(&Socket->io_service()), out(Out), name(Name)//, send(this), rec(this) { init(); } CConnection::CConnection(boost::asio::basic_socket_acceptor > * acceptor, boost::asio::io_service *Io_service, std::string Name, std::ostream & Out) : out(Out), name(Name)//, send(this), rec(this) { boost::system::error_code error = asio::error::host_not_found; socket = new tcp::socket(*io_service); acceptor->accept(*socket,error); if (error){ delete socket; throw "Can't establish connection :("; } init(); } int CConnection::write(const void * data, unsigned size) { LOG("Sending " << size << " byte(s) of data" <close(); delete socket; delete io_service; delete wmx; delete rmx; } template <> void CConnection::saveSerializable(const std::string &data) { *this << ui32(data.size()); write(data.c_str(),data.size()); } template <> void CConnection::loadSerializable(std::string &data) { ui32 l; *this >> l; data.resize(l); read((void*)data.c_str(),l); }