From 7601149f476c1aa3dae6cd55027a36b62efabf12 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 1 Jul 2008 03:24:58 +0200 Subject: RequestManager hinzugef?gt --- src/madc.cpp | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'src/madc.cpp') diff --git a/src/madc.cpp b/src/madc.cpp index 790baf5..17f6953 100644 --- a/src/madc.cpp +++ b/src/madc.cpp @@ -20,46 +20,43 @@ #include "Net/ClientConnection.h" #include "Net/IPAddress.h" #include "Net/Packet.h" +#include "Common/RequestManager.h" #include int main() { Mad::Net::Connection::init(); - Mad::Net::ClientConnection connection; + Mad::Common::RequestManager requestManager; + Mad::Net::ClientConnection *connection = new Mad::Net::ClientConnection; try { - connection.connect(Mad::Net::IPAddress("127.0.0.1", 6666)); + connection->connect(Mad::Net::IPAddress("127.0.0.1", 6666)); - while(connection.isConnecting()) { - struct pollfd fd = connection.getPollfd(); + while(connection->isConnecting()) { + struct pollfd fd = connection->getPollfd(); if(poll(&fd, 1, 10000) > 0) - connection.sendReceive(fd.revents); + connection->sendReceive(fd.revents); } - connection.send(Mad::Net::Packet(Mad::Net::Packet::TYPE_DEBUG, 0x1234)); - connection.send(Mad::Net::Packet(Mad::Net::Packet::TYPE_DISCONNECT_REQ, 0xABCD)); + requestManager.registerConnection(connection); - while(!connection.sendQueueEmpty()) { - struct pollfd fd = connection.getPollfd(); + requestManager.sendRequest(connection, Mad::Common::Request::TYPE_PING); + requestManager.sendRequest(connection, Mad::Common::Request::TYPE_DISCONNECT); - if(poll(&fd, 1, 10000) > 0) - connection.sendReceive(fd.revents); - } - - connection.disconnect(); - - while(connection.isConnected()) { - struct pollfd fd = connection.getPollfd(); + while(connection->isConnected()) { + struct pollfd fd = connection->getPollfd(); if(poll(&fd, 1, 10000) > 0) - connection.sendReceive(fd.revents); + connection->sendReceive(fd.revents); } } catch(Mad::Net::Exception &e) { std::cerr << "Connection error: " << e.what() << std::endl; } + delete connection; + Mad::Net::Connection::deinit(); return 0; -- cgit v1.2.3