diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-07-01 03:24:58 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-07-01 03:24:58 +0200 |
commit | 7601149f476c1aa3dae6cd55027a36b62efabf12 (patch) | |
tree | 947a8ebeaebaf6a366a0490975e5fa2fa689db9c /src/madc.cpp | |
parent | 7be6ee9c1cd2c2c5172ad4a094b67c25d6c5b72c (diff) | |
download | mad-7601149f476c1aa3dae6cd55027a36b62efabf12.tar mad-7601149f476c1aa3dae6cd55027a36b62efabf12.zip |
RequestManager hinzugef?gt
Diffstat (limited to 'src/madc.cpp')
-rw-r--r-- | src/madc.cpp | 33 |
1 files changed, 15 insertions, 18 deletions
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 <iostream> 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; |