summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2005-02-23 22:38:22 +0000
committerMarc Laukien <marc@zeroc.com>2005-02-23 22:38:22 +0000
commitae78f93a665efe66b878016c933ccb702f83fc85 (patch)
treee4f4a8b1f29e3256d31035942c42181c0c28f6ca /cpp
parentmore optimizations (diff)
downloadice-ae78f93a665efe66b878016c933ccb702f83fc85.tar.bz2
ice-ae78f93a665efe66b878016c933ccb702f83fc85.tar.xz
ice-ae78f93a665efe66b878016c933ccb702f83fc85.zip
more optimizations
Diffstat (limited to 'cpp')
-rw-r--r--cpp/demo/Ice/throughput/Client.cpp17
-rw-r--r--cpp/demo/Ice/throughput/Throughput.ice1
-rw-r--r--cpp/demo/Ice/throughput/ThroughputI.h20
-rw-r--r--cpp/src/Ice/BasicStream.cpp261
4 files changed, 173 insertions, 126 deletions
diff --git a/cpp/demo/Ice/throughput/Client.cpp b/cpp/demo/Ice/throughput/Client.cpp
index 8113ae724b0..11bae701e8c 100644
--- a/cpp/demo/Ice/throughput/Client.cpp
+++ b/cpp/demo/Ice/throughput/Client.cpp
@@ -18,10 +18,11 @@ menu()
{
cout <<
"usage:\n"
- "s: send byte sequence\n"
+ "t: send byte sequence as twoway\n"
"o: send byte sequence as oneway\n"
"r: receive byte sequence\n"
"e: echo (send and receive) byte sequence\n"
+ "s: shutdown server\n"
"x: exit\n"
"?: help\n";
}
@@ -51,6 +52,8 @@ run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator)
menu();
+ throughput->ice_ping(); // Initial ping to setup the connection.
+
char c;
do
{
@@ -59,16 +62,14 @@ run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator)
cout << "==> ";
cin >> c;
- throughput->ice_ping(); // Initial ping to setup the connection.
-
IceUtil::Time tm = IceUtil::Time::now();
const int repetitions = 1000;
- if(c == 's' || c == 'o' || c == 'r' || c == 'e')
+ if(c == 't' || c == 'o' || c == 'r' || c == 'e')
{
switch(c)
{
- case 's':
+ case 't':
case 'o':
{
cout << "sending";
@@ -101,7 +102,7 @@ run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator)
{
switch(c)
{
- case 's':
+ case 't':
{
throughput->sendByteSeq(seq);
break;
@@ -137,6 +138,10 @@ run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator)
}
cout << "throughput: " << mbit << " MBit/s" << endl;
}
+ else if(c == 's')
+ {
+ throughput->shutdown();
+ }
else if(c == 'x')
{
// Nothing to do
diff --git a/cpp/demo/Ice/throughput/Throughput.ice b/cpp/demo/Ice/throughput/Throughput.ice
index 42a614186ae..d0a541a1145 100644
--- a/cpp/demo/Ice/throughput/Throughput.ice
+++ b/cpp/demo/Ice/throughput/Throughput.ice
@@ -22,6 +22,7 @@ interface Throughput
void sendByteSeq(ByteSeq seq);
ByteSeq recvByteSeq();
ByteSeq echoByteSeq(ByteSeq seq);
+ idempotent void shutdown();
};
};
diff --git a/cpp/demo/Ice/throughput/ThroughputI.h b/cpp/demo/Ice/throughput/ThroughputI.h
index 75ab70c61c2..7817500af0b 100644
--- a/cpp/demo/Ice/throughput/ThroughputI.h
+++ b/cpp/demo/Ice/throughput/ThroughputI.h
@@ -13,35 +13,41 @@
#include <Ice/Ice.h>
#include <Throughput.h>
-class ThroughputI : public ::Demo::Throughput
+class ThroughputI : public Demo::Throughput
{
public:
ThroughputI() :
- _seq(::Demo::seqSize, 0)
+ _seq(Demo::seqSize, 0)
{
}
virtual void
- sendByteSeq(const ::Demo::ByteSeq&, const Ice::Current&)
+ sendByteSeq(const Demo::ByteSeq&, const Ice::Current&)
{
}
- virtual ::Demo::ByteSeq
+ virtual Demo::ByteSeq
recvByteSeq(const Ice::Current&)
{
return _seq;
}
- virtual ::Demo::ByteSeq
- echoByteSeq(const ::Demo::ByteSeq& seq, const Ice::Current&)
+ virtual Demo::ByteSeq
+ echoByteSeq(const Demo::ByteSeq& seq, const Ice::Current&)
{
return seq;
}
+ virtual void
+ shutdown(const Ice::Current& c)
+ {
+ c.adapter->getCommunicator()->shutdown();
+ }
+
private:
- ::Demo::ByteSeq _seq;
+ Demo::ByteSeq _seq;
};
#endif
diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp
index 95945758f6b..5bd461b563d 100644
--- a/cpp/src/Ice/BasicStream.cpp
+++ b/cpp/src/Ice/BasicStream.cpp
@@ -22,24 +22,6 @@
#include <Ice/TraceLevels.h>
#include <Ice/LoggerUtil.h>
-template<typename InputIter, typename OutputIter>
-inline void
-ice_copy(InputIter first, InputIter last, OutputIter result)
-{
- std::copy(first, last, result);
-}
-
-template<>
-inline void
-ice_copy(std::vector<Ice::Byte>::const_iterator first, std::vector<Ice::Byte>::const_iterator last,
- std::vector<Ice::Byte>::iterator result)
-{
- if(last != first)
- {
- memcpy(&*result, &*first, last - first);
- }
-}
-
using namespace std;
using namespace Ice;
using namespace IceInternal;
@@ -670,39 +652,55 @@ IceInternal::BasicStream::readTypeId(string& id)
void
IceInternal::BasicStream::writeBlob(const vector<Byte>& v)
{
- Container::size_type pos = b.size();
- resize(pos + v.size());
- memcpy(&b[pos], &v[0], v.size());
+ if(!v.empty())
+ {
+ Container::size_type pos = b.size();
+ resize(pos + v.size());
+ memcpy(&b[pos], &v[0], v.size());
+ }
}
void
IceInternal::BasicStream::readBlob(vector<Byte>& v, Int sz)
{
- if(b.end() - i < sz)
+ if(sz > 0)
{
- throw UnmarshalOutOfBoundsException(__FILE__, __LINE__);
+ if(b.end() - i < sz)
+ {
+ throw UnmarshalOutOfBoundsException(__FILE__, __LINE__);
+ }
+ vector<Byte>(i, i + sz).swap(v);
+ i += sz;
+ }
+ else
+ {
+ v.clear();
}
- vector<Byte>(i, i + sz).swap(v);
- i += sz;
}
void
IceInternal::BasicStream::writeBlob(const Ice::Byte* v, Container::size_type sz)
{
- Container::size_type pos = b.size();
- resize(pos + sz);
- memcpy(&b[pos], v, sz);
+ if(sz > 0)
+ {
+ Container::size_type pos = b.size();
+ resize(pos + sz);
+ memcpy(&b[pos], v, sz);
+ }
}
void
IceInternal::BasicStream::readBlob(Ice::Byte* v, Container::size_type sz)
{
- if(static_cast<Container::size_type>(b.end() - i) < sz)
+ if(sz > 0)
{
- throw UnmarshalOutOfBoundsException(__FILE__, __LINE__);
+ if(static_cast<Container::size_type>(b.end() - i) < sz)
+ {
+ throw UnmarshalOutOfBoundsException(__FILE__, __LINE__);
+ }
+ memcpy(v, &*i, sz);
+ i += sz;
}
- memcpy(v, &*i, sz);
- i += sz;
}
void
@@ -710,9 +708,12 @@ IceInternal::BasicStream::write(const vector<Byte>& v)
{
Int sz = static_cast<Int>(v.size());
writeSize(sz);
- Container::size_type pos = b.size();
- resize(pos + sz);
- memcpy(&b[pos], &v[0], sz);
+ if(sz > 0)
+ {
+ Container::size_type pos = b.size();
+ resize(pos + sz);
+ memcpy(&b[pos], &v[0], sz);
+ }
}
void
@@ -720,9 +721,16 @@ IceInternal::BasicStream::read(vector<Byte>& v)
{
Int sz;
readSize(sz);
- checkFixedSeq(sz, 1);
- vector<Byte>(i, i + sz).swap(v);
- i += sz;
+ if(sz > 0)
+ {
+ checkFixedSeq(sz, 1);
+ vector<Byte>(i, i + sz).swap(v);
+ i += sz;
+ }
+ else
+ {
+ v.clear();
+ }
}
void
@@ -730,9 +738,12 @@ IceInternal::BasicStream::write(const vector<bool>& v)
{
Int sz = static_cast<Int>(v.size());
writeSize(sz);
- Container::size_type pos = b.size();
- resize(pos + sz);
- copy(v.begin(), v.end(), b.begin() + pos);
+ if(sz > 0)
+ {
+ Container::size_type pos = b.size();
+ resize(pos + sz);
+ copy(v.begin(), v.end(), b.begin() + pos);
+ }
}
void
@@ -740,10 +751,16 @@ IceInternal::BasicStream::read(vector<bool>& v)
{
Int sz;
readSize(sz);
- checkFixedSeq(sz, 1);
- v.resize(sz);
- copy(i, i + sz, v.begin());
- i += sz;
+ if(sz > 0)
+ {
+ checkFixedSeq(sz, 1);
+ vector<bool>(i, i + sz).swap(v);
+ i += sz;
+ }
+ else
+ {
+ v.clear();
+ }
}
void
@@ -782,9 +799,7 @@ IceInternal::BasicStream::write(const vector<Short>& v)
src += 2 * sizeof(Short);
}
#else
- ice_copy(reinterpret_cast<const Byte*>(&v[0]),
- reinterpret_cast<const Byte*>(&v[0]) + sz * sizeof(Short),
- b.begin() + pos);
+ memcpy(&b[pos], reinterpret_cast<const Byte*>(&v[0]), sz * sizeof(Short));
#endif
}
}
@@ -814,12 +829,12 @@ IceInternal::BasicStream::read(vector<Short>& v)
{
Int sz;
readSize(sz);
- checkFixedSeq(sz, sizeof(Short));
- Container::iterator begin = i;
- i += sz * static_cast<int>(sizeof(Short));
- v.resize(sz);
if(sz > 0)
{
+ checkFixedSeq(sz, sizeof(Short));
+ Container::iterator begin = i;
+ i += sz * static_cast<int>(sizeof(Short));
+ v.resize(sz);
#ifdef ICE_BIG_ENDIAN
const Byte* src = &(*begin);
Byte* dest = reinterpret_cast<Byte*>(&v[0]) + sizeof(Short) - 1;
@@ -830,9 +845,13 @@ IceInternal::BasicStream::read(vector<Short>& v)
dest += 2 * sizeof(Short);
}
#else
- ice_copy(begin, i, reinterpret_cast<Byte*>(&v[0]));
+ copy(begin, i, reinterpret_cast<Byte*>(&v[0]));
#endif
}
+ else
+ {
+ v.clear();
+ }
}
void
@@ -877,9 +896,7 @@ IceInternal::BasicStream::write(const vector<Int>& v)
src += 2 * sizeof(Int);
}
#else
- ice_copy(reinterpret_cast<const Byte*>(&v[0]),
- reinterpret_cast<const Byte*>(&v[0]) + sz * sizeof(Int),
- b.begin() + pos);
+ memcpy(&b[pos], reinterpret_cast<const Byte*>(&v[0]), sz * sizeof(Int));
#endif
}
}
@@ -913,12 +930,12 @@ IceInternal::BasicStream::read(vector<Int>& v)
{
Int sz;
readSize(sz);
- checkFixedSeq(sz, sizeof(Int));
- Container::iterator begin = i;
- i += sz * static_cast<int>(sizeof(Int));
- v.resize(sz);
if(sz > 0)
{
+ checkFixedSeq(sz, sizeof(Int));
+ Container::iterator begin = i;
+ i += sz * static_cast<int>(sizeof(Int));
+ v.resize(sz);
#ifdef ICE_BIG_ENDIAN
const Byte* src = &(*begin);
Byte* dest = reinterpret_cast<Byte*>(&v[0]) + sizeof(Int) - 1;
@@ -931,9 +948,13 @@ IceInternal::BasicStream::read(vector<Int>& v)
dest += 2 * sizeof(Int);
}
#else
- ice_copy(begin, i, reinterpret_cast<Byte*>(&v[0]));
+ copy(begin, i, reinterpret_cast<Byte*>(&v[0]));
#endif
}
+ else
+ {
+ v.clear();
+ }
}
void
@@ -990,9 +1011,7 @@ IceInternal::BasicStream::write(const vector<Long>& v)
src += 2 * sizeof(Long);
}
#else
- ice_copy(reinterpret_cast<const Byte*>(&v[0]),
- reinterpret_cast<const Byte*>(&v[0]) + sz * sizeof(Long),
- b.begin() + pos);
+ memcpy(&b[pos], reinterpret_cast<const Byte*>(&v[0]), sz * sizeof(Long));
#endif
}
}
@@ -1034,12 +1053,12 @@ IceInternal::BasicStream::read(vector<Long>& v)
{
Int sz;
readSize(sz);
- checkFixedSeq(sz, sizeof(Long));
- Container::iterator begin = i;
- i += sz * static_cast<int>(sizeof(Long));
- v.resize(sz);
if(sz > 0)
{
+ checkFixedSeq(sz, sizeof(Long));
+ Container::iterator begin = i;
+ i += sz * static_cast<int>(sizeof(Long));
+ v.resize(sz);
#ifdef ICE_BIG_ENDIAN
const Byte* src = &(*begin);
Byte* dest = reinterpret_cast<Byte*>(&v[0]) + sizeof(Long) - 1;
@@ -1056,9 +1075,13 @@ IceInternal::BasicStream::read(vector<Long>& v)
dest += 2 * sizeof(Long);
}
#else
- ice_copy(begin, i, reinterpret_cast<Byte*>(&v[0]));
+ copy(begin, i, reinterpret_cast<Byte*>(&v[0]));
#endif
}
+ else
+ {
+ v.clear();
+ }
}
void
@@ -1103,9 +1126,7 @@ IceInternal::BasicStream::write(const vector<Float>& v)
src += 2 * sizeof(Float);
}
#else
- ice_copy(reinterpret_cast<const Byte*>(&v[0]),
- reinterpret_cast<const Byte*>(&v[0]) + sz * sizeof(Float),
- b.begin() + pos);
+ memcpy(&b[pos], reinterpret_cast<const Byte*>(&v[0]), sz * sizeof(Float));
#endif
}
}
@@ -1139,12 +1160,12 @@ IceInternal::BasicStream::read(vector<Float>& v)
{
Int sz;
readSize(sz);
- checkFixedSeq(sz, sizeof(Float));
- Container::iterator begin = i;
- i += sz * static_cast<int>(sizeof(Float));
- v.resize(sz);
if(sz > 0)
{
+ checkFixedSeq(sz, sizeof(Float));
+ Container::iterator begin = i;
+ i += sz * static_cast<int>(sizeof(Float));
+ v.resize(sz);
#ifdef ICE_BIG_ENDIAN
const Byte* src = &(*begin);
Byte* dest = reinterpret_cast<Byte*>(&v[0]) + sizeof(Float) - 1;
@@ -1157,9 +1178,13 @@ IceInternal::BasicStream::read(vector<Float>& v)
dest += 2 * sizeof(Float);
}
#else
- ice_copy(begin, i, reinterpret_cast<Byte*>(&v[0]));
+ copy(begin, i, reinterpret_cast<Byte*>(&v[0]));
#endif
}
+ else
+ {
+ v.clear();
+ }
}
void
@@ -1216,9 +1241,7 @@ IceInternal::BasicStream::write(const vector<Double>& v)
src += 2 * sizeof(Double);
}
#else
- ice_copy(reinterpret_cast<const Byte*>(&v[0]),
- reinterpret_cast<const Byte*>(&v[0]) + sz * sizeof(Double),
- b.begin() + pos);
+ memcpy(&b[pos], reinterpret_cast<const Byte*>(&v[0]), sz * sizeof(Double));
#endif
}
}
@@ -1260,12 +1283,12 @@ IceInternal::BasicStream::read(vector<Double>& v)
{
Int sz;
readSize(sz);
- checkFixedSeq(sz, sizeof(Double));
- Container::iterator begin = i;
- i += sz * static_cast<int>(sizeof(Double));
- v.resize(sz);
if(sz > 0)
{
+ checkFixedSeq(sz, sizeof(Double));
+ Container::iterator begin = i;
+ i += sz * static_cast<int>(sizeof(Double));
+ v.resize(sz);
#ifdef ICE_BIG_ENDIAN
const Byte* src = &(*begin);
Byte* dest = reinterpret_cast<Byte*>(&v[0]) + sizeof(Double) - 1;
@@ -1282,9 +1305,13 @@ IceInternal::BasicStream::read(vector<Double>& v)
dest += 2 * sizeof(Double);
}
#else
- ice_copy(begin, i, reinterpret_cast<Byte*>(&v[0]));
+ copy(begin, i, reinterpret_cast<Byte*>(&v[0]));
#endif
}
+ else
+ {
+ v.clear();
+ }
}
//
@@ -1304,40 +1331,44 @@ IceInternal::BasicStream::write(const char*)
void
IceInternal::BasicStream::write(const string& v)
{
- Int len = static_cast<Int>(v.size());
- writeSize(len);
- if(len > 0)
+ Int sz = static_cast<Int>(v.size());
+ writeSize(sz);
+ if(sz > 0)
{
Container::size_type pos = b.size();
- resize(pos + len);
- memcpy(&b[pos], v.c_str(), len);
+ resize(pos + sz);
+ memcpy(&b[pos], v.c_str(), sz);
}
}
void
IceInternal::BasicStream::write(const vector<string>& v)
{
- writeSize(Int(v.size()));
- vector<string>::const_iterator p;
- for(p = v.begin(); p != v.end(); ++p)
+ Int sz = static_cast<Int>(v.size());
+ writeSize(sz);
+ if(sz > 0)
{
- write(*p);
+ vector<string>::const_iterator p;
+ for(p = v.begin(); p != v.end(); ++p)
+ {
+ write(*p);
+ }
}
}
void
IceInternal::BasicStream::read(string& v)
{
- Int len;
- readSize(len);
- if(b.end() - i < len)
- {
- throw UnmarshalOutOfBoundsException(__FILE__, __LINE__);
- }
- if(len > 0)
+ Int sz;
+ readSize(sz);
+ if(sz > 0)
{
- v.assign(reinterpret_cast<const char*>(&(*i)), len);
- i += len;
+ if(b.end() - i < sz)
+ {
+ throw UnmarshalOutOfBoundsException(__FILE__, __LINE__);
+ }
+ v.assign(reinterpret_cast<const char*>(&(*i)), sz);
+ i += sz;
}
else
{
@@ -1350,18 +1381,22 @@ IceInternal::BasicStream::read(vector<string>& v)
{
Int sz;
readSize(sz);
- startSeq(sz, 1);
- v.clear();
-
- v.resize(sz);
- for(int i = 0; i < sz; ++i)
+ if(sz > 0)
{
- read(v[i]);
- checkSeq();
- endElement();
+ startSeq(sz, 1);
+ v.resize(sz);
+ for(int i = 0; i < sz; ++i)
+ {
+ read(v[i]);
+ checkSeq();
+ endElement();
+ }
+ endSeq(sz);
+ }
+ else
+ {
+ v.clear();
}
-
- endSeq(sz);
}
void