This commit is contained in:
Eduardo Bart
2011-04-07 15:50:48 -03:00
5 changed files with 20 additions and 22 deletions

View File

@@ -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.");
}
}
*/
//}
}
}

View File

@@ -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;
}

View File

@@ -40,6 +40,8 @@ public:
bool isConnected() const { return m_connected; }
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);