Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 336 vs 337 for /trunk/Source Code/Libs/src/DivideNetworking/ASIO.cpp

Diff revisions: vs.
  @@ -5,12 +5,12 @@
5 5 // the user-defined operator,() below doesn't cause spurious warning all over the place,
6 6 // so unconditionally turn it off.
7 7 #if defined(_MSC_VER)
8 - # pragma warning( push )
8 + # pragma warning( push )
9 9 // user defined binary operator ',' exists but no overload could convert all operands, default built-in binary operator ',' used
10 - # pragma warning(disable:4913)
10 + # pragma warning(disable:4913)
11 11 #elif defined(__GNUC__)
12 - # pragma GCC diagnostic push
13 - # //pragma GCC diagnostic ignored "-Wall"
12 + # pragma GCC diagnostic push
13 + # //pragma GCC diagnostic ignored "-Wall"
14 14 #endif
15 15
16 16 #include "OPCodesTpl.h"
  @@ -27,73 +27,73 @@
27 27
28 28 ASIO::~ASIO()
29 29 {
30 - _work.reset();
31 - _thread->join();
32 - _localClient->stop();
33 - io_service_.stop();
34 - delete _localClient;
35 - _localClient = nullptr;
30 + _work.reset();
31 + _thread->join();
32 + _localClient->stop();
33 + io_service_.stop();
34 + delete _localClient;
35 + _localClient = nullptr;
36 36 }
37 37
38 38 void ASIO::disconnect(){
39 - if(!_connected) return;
40 - WorldPacket p(CMSG_REQUEST_DISCONNECT);
41 - p << _localClient->getSocket().local_endpoint().address().to_string();
42 - sendPacket(p);
39 + if(!_connected) return;
40 + WorldPacket p(CMSG_REQUEST_DISCONNECT);
41 + p << _localClient->getSocket().local_endpoint().address().to_string();
42 + sendPacket(p);
43 43 }
44 44
45 45 void ASIO::init(const stringImpl& address,const stringImpl& port){
46 - try{
47 - tcp::resolver res(io_service_);
48 - _localClient = new Client(this, io_service_,_debugOutput);
49 - _work.reset(new boost::asio::io_service::work(io_service_));
50 - _localClient->start(res.resolve(tcp::resolver::query(address.c_str(), port.c_str())));
51 - _thread = new std::thread([&]{ io_service_.run(); });
52 - io_service_.poll();
53 - _connected = true;
54 - }catch (std::exception& e){
55 - if(_debugOutput){
56 - stringImpl msg("ASIO Exception: ");
57 - msg.append(e.what());
58 - std::cout << msg.c_str() << std::endl;
59 - }
60 - }
46 + try{
47 + tcp::resolver res(io_service_);
48 + _localClient = new Client(this, io_service_,_debugOutput);
49 + _work.reset(new boost::asio::io_service::work(io_service_));
50 + _localClient->start(res.resolve(tcp::resolver::query(address.c_str(), port.c_str())));
51 + _thread = new std::thread([&]{ io_service_.run(); });
52 + io_service_.poll();
53 + _connected = true;
54 + }catch (std::exception& e){
55 + if(_debugOutput){
56 + stringImpl msg("ASIO Exception: ");
57 + msg.append(e.what());
58 + std::cout << msg.c_str() << std::endl;
59 + }
60 + }
61 61 }
62 62
63 63 void ASIO::connect(const stringImpl& address,const stringImpl& port){
64 - if(!_connected) {
65 - init(address,port);
66 - }
64 + if(!_connected) {
65 + init(address,port);
66 + }
67 67 }
68 68
69 69 bool ASIO::isConnected() const {
70 - return _connected;
70 + return _connected;
71 71 }
72 72
73 73 void ASIO::close(){
74 - _localClient->stop();
75 - _connected = false;
74 + _localClient->stop();
75 + _connected = false;
76 76 }
77 77
78 78 void ASIO::sendPacket(WorldPacket& p)const {
79 - if(!_connected) return;
79 + if(!_connected) return;
80 80
81 - _localClient->sendPacket(p);
81 + _localClient->sendPacket(p);
82 82
83 - if(_debugOutput){
84 - std::cout << "ASIO: sent opcode [ 0x" << Util::toString(p.getOpcode()).c_str() << "]" << std::endl;
85 - }
83 + if(_debugOutput){
84 + std::cout << "ASIO: sent opcode [ 0x" << Util::toString(p.getOpcode()).c_str() << "]" << std::endl;
85 + }
86 86 }
87 87
88 88 void ASIO::toggleDebugOutput(const bool debugOutput){
89 - _debugOutput = debugOutput;
90 - _localClient->toggleDebugOutput(_debugOutput);
89 + _debugOutput = debugOutput;
90 + _localClient->toggleDebugOutput(_debugOutput);
91 91 }
92 92
93 93 }; //namespace Divide
94 94
95 95 #if defined(_MSC_VER)
96 - # pragma warning( pop )
96 + # pragma warning( pop )
97 97 #elif defined(__GNUC__)
98 - # pragma GCC diagnostic pop
98 + # pragma GCC diagnostic pop
99 99 #endif