summaryrefslogtreecommitdiff
path: root/cpp/demo/cookbook/compression/Client.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2009-12-18 08:29:41 -0800
committerMark Spruiell <mes@zeroc.com>2009-12-18 08:29:41 -0800
commita0deeca18e2c62cda2ee4b7b12a12970d270d26c (patch)
tree3e376a4ebd932661a21bcb973ed63a2b3aeb1089 /cpp/demo/cookbook/compression/Client.cpp
parentediting vsplugin text files (diff)
downloadice-a0deeca18e2c62cda2ee4b7b12a12970d270d26c.tar.bz2
ice-a0deeca18e2c62cda2ee4b7b12a12970d270d26c.tar.xz
ice-a0deeca18e2c62cda2ee4b7b12a12970d270d26c.zip
bug 4510 - remove cookbook demos
Diffstat (limited to 'cpp/demo/cookbook/compression/Client.cpp')
-rw-r--r--cpp/demo/cookbook/compression/Client.cpp193
1 files changed, 0 insertions, 193 deletions
diff --git a/cpp/demo/cookbook/compression/Client.cpp b/cpp/demo/cookbook/compression/Client.cpp
deleted file mode 100644
index 54685ef45a5..00000000000
--- a/cpp/demo/cookbook/compression/Client.cpp
+++ /dev/null
@@ -1,193 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-
-#include <Ice/Ice.h>
-#include <Compression.h>
-#include <fstream>
-
-using namespace std;
-using namespace Compression;
-
-//
-// Implementation of the Ice::Stats interface.
-//
-class StatsI : public Ice::Stats
-{
-public:
-
- StatsI() : _total(0) {}
-
- virtual void bytesSent(const string&, Ice::Int sz)
- {
- _total += sz;
- }
-
- virtual void bytesReceived(const string&, Ice::Int)
- {
- }
-
- void reset()
- {
- _total = 0;
- }
-
- Ice::Int total() const
- {
- return _total;
- }
-
-private:
-
- Ice::Int _total;
-};
-typedef IceUtil::Handle<StatsI> StatsIPtr;
-
-class Client : public Ice::Application
-{
-public:
-
- Client() : _stats(new StatsI)
- {
- }
-
- Ice::StatsPtr stats() const
- {
- return _stats;
- }
-
- virtual int run(int, char*[]);
-
-private:
-
- StatsIPtr _stats;
-};
-
-int
-main(int argc, char* argv[])
-{
- Client app;
-
- Ice::InitializationData initData;
- initData.properties = Ice::createProperties();
- initData.properties->load("config.client");
- initData.stats = app.stats();
- return app.main(argc, argv, initData);
-}
-
-int
-Client::run(int argc, char* argv[])
-{
- if(argc == 1)
- {
- cerr << "Usage: " << argv[0] << " file" << endl;
- return 1;
- }
-
- //
- // Read the input file into a byte sequence.
- //
- ifstream in;
- in.open(argv[1], ios::binary);
- if(!in.good())
- {
- cerr << argv[0] << ": unable to open file `" << argv[1] << "'" << endl;
- return 1;
- }
-
- in.seekg(0, ios::end);
- ifstream::pos_type len = in.tellg();
- in.seekg(0, ios::beg);
-
- ByteSeq source;
- source.resize(len);
- in.read(reinterpret_cast<char*>(&source[0]), len);
-
- //
- // Create our proxies.
- //
- Ice::PropertiesPtr properties = communicator()->getProperties();
- const char* proxyProperty = "Compression.Proxy";
- std::string proxy = properties->getProperty(proxyProperty);
- if(proxy.empty())
- {
- cerr << argv[0] << ": property `" << proxyProperty << "' not set" << endl;
- return EXIT_FAILURE;
- }
-
- Ice::ObjectPrx base = communicator()->stringToProxy(proxy);
- ReceiverPrx uncompressed = ReceiverPrx::checkedCast(base->ice_compress(false));
- if(!uncompressed)
- {
- cerr << argv[0] << ": invalid proxy" << endl;
- return EXIT_FAILURE;
- }
- ReceiverPrx compressed = ReceiverPrx::uncheckedCast(base->ice_compress(true));
-
- const int repetitions = 10;
- int sz = 200;
-
- while(true)
- {
- cout << "time for " << sz << " bytes:" << endl;
-
- ByteSeq seq;
- seq.resize(sz);
- copy(source.begin(), source.begin() + sz, seq.begin());
-
- IceUtil::Time tm;
- int i;
-
- //
- // Measure uncompressed latency.
- //
- _stats->reset();
- tm = IceUtil::Time::now();
- for(i = 0; i < repetitions; ++i)
- {
- uncompressed->sendData(seq);
- }
- tm = IceUtil::Time::now() - tm;
- cout << " uncompressed = " << tm * 1000 / repetitions << "ms" << flush;
- Ice::Int uncompressedTotal = _stats->total();
-
- //
- // Measure compressed latency.
- //
- _stats->reset();
- tm = IceUtil::Time::now();
- for(i = 0; i < repetitions; ++i)
- {
- compressed->sendData(seq);
- }
- tm = IceUtil::Time::now() - tm;
- cout << "\tcompressed = " << tm * 1000 / repetitions << "ms" << flush;
- Ice::Int compressedTotal = _stats->total();
- cout << "\tcompression = " << compressedTotal * 100.0 / uncompressedTotal << "%" << endl;
-
- if(sz == len)
- {
- break;
- }
- else
- {
- //
- // ifstream::pos_type has not *= operator.
- //
- sz = sz * 10;
- if(sz > len)
- {
- sz = static_cast<int>(len);
- }
- }
- }
-
- cout << "done" << endl;
-
- return EXIT_SUCCESS;
-}