merge
This commit is contained in:
commit
7739c7bb29
|
@ -76,7 +76,7 @@ void Engine::run()
|
|||
Platform::poll();
|
||||
|
||||
//poll network events
|
||||
//logDebug("%d", g_connections.poll());
|
||||
g_connections.poll();
|
||||
|
||||
// update before redering
|
||||
ticks = Platform::getTicks();
|
||||
|
@ -107,23 +107,6 @@ void Engine::run()
|
|||
|
||||
// swap buffers
|
||||
Platform::swapBuffers();
|
||||
|
||||
/*
|
||||
static ConnectionPtr connection = g_connections.createConnection();
|
||||
|
||||
if(connection->getLastError()){
|
||||
logError("%s", connection->getLastError().message().c_str());
|
||||
}
|
||||
else{
|
||||
if(!connection->isConnecting() && !connection->isConnected()){
|
||||
connection->connect("www.google.com.br", 80);
|
||||
}
|
||||
|
||||
if(!connection->isConnected()){
|
||||
logDebug("still not connected.");
|
||||
}
|
||||
}
|
||||
*/
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,16 +57,18 @@ void Connection::connect(const std::string& ip, uint16 port)
|
|||
logDebug("connecting...");
|
||||
|
||||
//first resolve dns
|
||||
boost::asio::ip::tcp::resolver::query query(ip, "80");
|
||||
boost::asio::ip::tcp::resolver::query query(ip, convertType<std::string, uint16>(port));
|
||||
m_resolver.async_resolve(query, boost::bind(&Connection::onResolveDns, this, boost::asio::placeholders::error, boost::asio::placeholders::iterator));
|
||||
}
|
||||
|
||||
void Connection::onResolveDns(const boost::system::error_code& error, boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
|
||||
{
|
||||
logDebug("resolving dns..");
|
||||
|
||||
m_lastError = error;
|
||||
|
||||
if(error){
|
||||
m_connecting = false;
|
||||
m_lastError = error;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -76,9 +78,10 @@ void Connection::onResolveDns(const boost::system::error_code& error, boost::asi
|
|||
|
||||
void Connection::onConnect(const boost::system::error_code& error)
|
||||
{
|
||||
m_lastError = error;
|
||||
|
||||
if(error){
|
||||
m_connecting = false;
|
||||
m_lastError = error;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,8 @@ public:
|
|||
|
||||
const boost::system::error_code& getLastError() const { return m_lastError; }
|
||||
|
||||
void resetLastError() { m_lastError = boost::system::error_code(); }
|
||||
|
||||
private:
|
||||
void onResolveDns(const boost::system::error_code& error, boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
|
||||
void onConnect(const boost::system::error_code& error);
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "framework/rect.h"
|
||||
#include "framework/fonts.h"
|
||||
#include "framework/input.h"
|
||||
#include "framework/net/connections.h"
|
||||
|
||||
TexturePtr background;
|
||||
|
||||
|
@ -38,6 +39,9 @@ void MenuState::onEnter()
|
|||
{
|
||||
m_background = g_textures.get("background.png");
|
||||
m_background->enableBilinearFilter();
|
||||
|
||||
m_connection = g_connections.createConnection();
|
||||
m_connection->connect("www.google.com.br", 80);
|
||||
}
|
||||
|
||||
void MenuState::onLeave()
|
||||
|
@ -97,5 +101,8 @@ void MenuState::render()
|
|||
|
||||
void MenuState::update(int ticks, int elapsedTicks)
|
||||
{
|
||||
|
||||
if(m_connection->getLastError()){
|
||||
logError("%s", m_connection->getLastError().message().c_str());
|
||||
m_connection->resetLastError();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include "framework/gamestate.h"
|
||||
#include "framework/texture.h"
|
||||
#include "framework/net/connection.h"
|
||||
|
||||
class MenuState : public GameState
|
||||
{
|
||||
|
@ -45,6 +46,8 @@ public:
|
|||
|
||||
private:
|
||||
TexturePtr m_background;
|
||||
ConnectionPtr m_connection;
|
||||
int m_connectionTicks;
|
||||
};
|
||||
|
||||
#endif // MENUSTATE_H
|
||||
|
|
Loading…
Reference in New Issue