diff options
author | Benoit Foucher <benoit@zeroc.com> | 2006-02-22 10:38:32 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2006-02-22 10:38:32 +0000 |
commit | 476fb33e7cf9502ea027f2eb4fef856382fecef3 (patch) | |
tree | bbc027b022c48afa6bc3e3cec6e9862af3341208 /cppe/src | |
parent | But 716. (diff) | |
download | ice-476fb33e7cf9502ea027f2eb4fef856382fecef3.tar.bz2 ice-476fb33e7cf9502ea027f2eb4fef856382fecef3.tar.xz ice-476fb33e7cf9502ea027f2eb4fef856382fecef3.zip |
Fixed to allow better inlining.
Diffstat (limited to 'cppe/src')
-rw-r--r-- | cppe/src/IceE/BasicStream.cpp | 135 | ||||
-rw-r--r-- | cppe/src/IceE/Buffer.cpp | 2 | ||||
-rwxr-xr-x | cppe/src/IceE/Connection.cpp | 102 | ||||
-rw-r--r-- | cppe/src/IceE/Incoming.cpp | 2 | ||||
-rw-r--r-- | cppe/src/IceE/Instance.cpp | 7 | ||||
-rw-r--r-- | cppe/src/IceE/Instance.h | 2 | ||||
-rw-r--r-- | cppe/src/IceE/Outgoing.cpp | 6 |
7 files changed, 82 insertions, 174 deletions
diff --git a/cppe/src/IceE/BasicStream.cpp b/cppe/src/IceE/BasicStream.cpp index bd7dd86c998..683499f9601 100644 --- a/cppe/src/IceE/BasicStream.cpp +++ b/cppe/src/IceE/BasicStream.cpp @@ -21,16 +21,8 @@ using namespace std; using namespace Ice; using namespace IceInternal; -IceInternal::BasicStream::BasicStream(Instance* instance) : - _instance(instance), - _currentReadEncaps(0), - _currentWriteEncaps(0), - _messageSizeMax(_instance->messageSizeMax()), // Cached for efficiency. - _seqDataStack(0) -{ -} - -IceInternal::BasicStream::~BasicStream() +void +IceInternal::BasicStream::clear() { while(_currentReadEncaps && _currentReadEncaps != &_preAllocatedReadEncaps) { @@ -54,12 +46,6 @@ IceInternal::BasicStream::~BasicStream() } } -Instance* -IceInternal::BasicStream::instance() const -{ - return _instance; -} - void IceInternal::BasicStream::swap(BasicStream& other) { @@ -258,22 +244,6 @@ IceInternal::BasicStream::endSeq(int sz) delete oldSeqData; } -IceInternal::BasicStream::WriteEncaps::WriteEncaps() - : writeIndex(0), previous(0) -{ -} - -IceInternal::BasicStream::WriteEncaps::~WriteEncaps() -{ -} - -void -IceInternal::BasicStream::WriteEncaps::reset() -{ - writeIndex = 0; - previous = 0; -} - void IceInternal::BasicStream::WriteEncaps::swap(WriteEncaps& other) { @@ -337,21 +307,6 @@ IceInternal::BasicStream::endWriteEncaps() } } -IceInternal::BasicStream::ReadEncaps::ReadEncaps() - : previous(0) -{ -} - -IceInternal::BasicStream::ReadEncaps::~ReadEncaps() -{ -} - -void -IceInternal::BasicStream::ReadEncaps::reset() -{ - previous = 0; -} - void IceInternal::BasicStream::ReadEncaps::swap(ReadEncaps& other) { @@ -532,41 +487,6 @@ IceInternal::BasicStream::skipSlice() } void -IceInternal::BasicStream::writeSize(Int v) -{ - assert(v >= 0); - if(v > 254) - { - write(Byte(255)); - write(v); - } - else - { - write(static_cast<Byte>(v)); - } -} - -void -IceInternal::BasicStream::readSize(Ice::Int& v) -{ - Byte byte; - read(byte); - unsigned val = static_cast<unsigned char>(byte); - if(val == 255) - { - read(v); - if(v < 0) - { - throw NegativeSizeException(__FILE__, __LINE__); - } - } - else - { - v = static_cast<Int>(static_cast<unsigned char>(byte)); - } -} - -void IceInternal::BasicStream::writeBlob(const vector<Byte>& v) { if(!v.empty()) @@ -865,51 +785,6 @@ IceInternal::BasicStream::read(pair<const Short*, const Short*>& v, IceUtil::aut } void -IceInternal::BasicStream::write(Int v) -{ - Container::size_type pos = b.size(); - resize(pos + sizeof(Int)); - Byte* dest = &b[pos]; -#ifdef ICE_BIG_ENDIAN - const Byte* src = reinterpret_cast<const Byte*>(&v) + sizeof(Int) - 1; - *dest++ = *src--; - *dest++ = *src--; - *dest++ = *src--; - *dest = *src; -#else - const Byte* src = reinterpret_cast<const Byte*>(&v); - *dest++ = *src++; - *dest++ = *src++; - *dest++ = *src++; - *dest = *src; -#endif -} - -void -IceInternal::BasicStream::read(Int& v) -{ - if(b.end() - i < static_cast<int>(sizeof(Int))) - { - throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); - } - const Byte* src = &(*i); - i += sizeof(Int); -#ifdef ICE_BIG_ENDIAN - Byte* dest = reinterpret_cast<Byte*>(&v) + sizeof(Int) - 1; - *dest-- = *src++; - *dest-- = *src++; - *dest-- = *src++; - *dest = *src; -#else - Byte* dest = reinterpret_cast<Byte*>(&v); - *dest++ = *src++; - *dest++ = *src++; - *dest++ = *src++; - *dest = *src; -#endif -} - -void IceInternal::BasicStream::write(const Int* begin, const Int* end) { Int sz = static_cast<Int>(end - begin); @@ -1718,6 +1593,12 @@ IceInternal::BasicStream::throwMemoryLimitException(const char* file, int line) throw MemoryLimitException(file, line); } +void +IceInternal::BasicStream::throwNegativeSizeException(const char* file, int line) +{ + throw NegativeSizeException(file, line); +} + IceInternal::BasicStream::SeqData::SeqData(int num, int sz) : numElements(num), minSize(sz) { } diff --git a/cppe/src/IceE/Buffer.cpp b/cppe/src/IceE/Buffer.cpp index 62d5648fbb9..fc262441bea 100644 --- a/cppe/src/IceE/Buffer.cpp +++ b/cppe/src/IceE/Buffer.cpp @@ -71,7 +71,7 @@ IceInternal::Buffer::Container::swap(Container& other) } void -IceInternal::Buffer::Container::resize(size_type n) +IceInternal::Buffer::Container::resizeImpl(size_type n) { if(n == 0) { diff --git a/cppe/src/IceE/Connection.cpp b/cppe/src/IceE/Connection.cpp index cc8bd097a8b..c2ddb0a1bff 100755 --- a/cppe/src/IceE/Connection.cpp +++ b/cppe/src/IceE/Connection.cpp @@ -294,15 +294,6 @@ Ice::Connection::waitUntilFinished() #endif } -// -// TODO: Should not be a member function of Connection. -// -void -Ice::Connection::prepareRequest(BasicStream* os) -{ - os->writeBlob(&_requestHdr[0], headerSize + sizeof(Int)); -} - Int Ice::Connection::fillRequestId(BasicStream* os) @@ -320,11 +311,19 @@ Ice::Connection::fillRequestId(BasicStream* os) // // Fill in the request ID. // - const Byte* p = reinterpret_cast<const Byte*>(&requestId); + Byte* dest = &(os->b[0]) + headerSize; #ifdef ICE_BIG_ENDIAN - reverse_copy(p, p + sizeof(Int), os->b.begin() + headerSize); + const Byte* src = reinterpret_cast<const Byte*>(&requestId) + sizeof(Ice::Int) - 1; + *dest++ = *src--; + *dest++ = *src--; + *dest++ = *src--; + *dest = *src; #else - copy(p, p + sizeof(Int), os->b.begin() + headerSize); + const Byte* src = reinterpret_cast<const Byte*>(&requestId); + *dest++ = *src++; + *dest++ = *src++; + *dest++ = *src++; + *dest = *src; #endif return requestId; @@ -339,12 +338,20 @@ Ice::Connection::sendRequest(BasicStream* os) _exception->ice_throw(); // The exception is immutable at this point. } - Int sz = static_cast<Int>(os->b.size()); - const Byte* p = reinterpret_cast<const Byte*>(&sz); + const Int sz = static_cast<Int>(os->b.size()); + Byte* dest = &(os->b[0]) + 10; #ifdef ICE_BIG_ENDIAN - reverse_copy(p, p + sizeof(Int), os->b.begin() + 10); + const Byte* src = reinterpret_cast<const Byte*>(&sz) + sizeof(Ice::Int) - 1; + *dest++ = *src--; + *dest++ = *src--; + *dest++ = *src--; + *dest = *src; #else - copy(p, p + sizeof(Int), os->b.begin() + 10); + const Byte* src = reinterpret_cast<const Byte*>(&sz); + *dest++ = *src++; + *dest++ = *src++; + *dest++ = *src++; + *dest = *src; #endif // @@ -658,7 +665,7 @@ Ice::Connection::abortBatchRequest() // safe old requests in the batch stream, as they might be // corrupted due to incomplete marshaling. // - BasicStream dummy(_instance.get()); + BasicStream dummy(_instance.get(), _instance->messageSizeMax()); _batchStream.swap(dummy); _batchRequestNum = 0; @@ -717,19 +724,35 @@ Ice::Connection::flushBatchRequests() // // Fill in the number of requests in the batch. // - const Byte* p = reinterpret_cast<const Byte*>(&_batchRequestNum); + Byte* dest = &(_batchStream.b[0]) + headerSize; #ifdef ICE_BIG_ENDIAN - reverse_copy(p, p + sizeof(Int), _batchStream.b.begin() + headerSize); + Byte* src = reinterpret_cast<const Byte*>(&_batchRequestNum) + sizeof(Ice::Int) - 1; + *dest++ = *src--; + *dest++ = *src--; + *dest++ = *src--; + *dest = *src; #else - copy(p, p + sizeof(Int), _batchStream.b.begin() + headerSize); + const Byte* src = reinterpret_cast<const Byte*>(&_batchRequestNum); + *dest++ = *src++; + *dest++ = *src++; + *dest++ = *src++; + *dest = *src; #endif - Int sz = static_cast<Int>(_batchStream.b.size()); - p = reinterpret_cast<const Byte*>(&sz); + const Int sz = static_cast<Int>(_batchStream.b.size()); + dest = &(_batchStream.b[0]) + 10; #ifdef ICE_BIG_ENDIAN - reverse_copy(p, p + sizeof(Int), _batchStream.b.begin() + 10); + src = reinterpret_cast<const Byte*>(&sz) + sizeof(Ice::Int) - 1; + *dest++ = *src--; + *dest++ = *src--; + *dest++ = *src--; + *dest = *src; #else - copy(p, p + sizeof(Int), _batchStream.b.begin() + 10); + src = reinterpret_cast<const Byte*>(&sz); + *dest++ = *src++; + *dest++ = *src++; + *dest++ = *src++; + *dest = *src; #endif // @@ -758,7 +781,7 @@ Ice::Connection::flushBatchRequests() // // Reset the batch stream, and notify that flushing is over. // - BasicStream dummy(_instance.get()); + BasicStream dummy(_instance.get(), _instance->messageSizeMax()); _batchStream.swap(dummy); _batchRequestNum = 0; _batchStreamInUse = false; @@ -783,13 +806,22 @@ Ice::Connection::sendResponse(BasicStream* os) _exception->ice_throw(); // The exception is immutable at this point. } - Int sz = static_cast<Int>(os->b.size()); - const Byte* p = reinterpret_cast<const Byte*>(&sz); + + const Int sz = static_cast<Int>(os->b.size()); + Byte* dest = &(os->b[0]) + 10; #ifdef ICE_BIG_ENDIAN - reverse_copy(p, p + sizeof(Int), os->b.begin() + 10); + const Byte* src = reinterpret_cast<const Byte*>(&sz) + sizeof(Ice::Int) - 1; + *dest++ = *src--; + *dest++ = *src--; + *dest++ = *src--; + *dest = *src; #else - copy(p, p + sizeof(Int), os->b.begin() + 10); -#endif + const Byte* src = reinterpret_cast<const Byte*>(&sz); + *dest++ = *src++; + *dest++ = *src++; + *dest++ = *src++; + *dest = *src; +#endif // // Send the reply. @@ -974,14 +1006,14 @@ Ice::Connection::Connection(const InstancePtr& instance, #ifndef ICEE_PURE_BLOCKING_CLIENT _nextRequestId(1), _requestsHint(_requests.end()), - _stream(_instance.get()), + _stream(_instance.get(), _instance->messageSizeMax()), #endif #ifndef ICEE_PURE_CLIENT _in(_instance.get(), this, _stream, adapter), #endif #ifdef ICEE_HAS_BATCH _requestBatchHdr(headerSize + sizeof(Int), 0), - _batchStream(_instance.get()), + _batchStream(_instance.get(), _instance->messageSizeMax()), _batchStreamInUse(false), _batchRequestNum(0), #endif @@ -1153,7 +1185,7 @@ Ice::Connection::validate() #ifndef ICEE_PURE_CLIENT if(active) { - BasicStream os(_instance.get()); + BasicStream os(_instance.get(), _instance->messageSizeMax()); os.write(magic[0]); os.write(magic[1]); os.write(magic[2]); @@ -1179,7 +1211,7 @@ Ice::Connection::validate() else #endif { - BasicStream is(_instance.get()); + BasicStream is(_instance.get(), _instance->messageSizeMax()); is.b.resize(headerSize); is.i = is.b.begin(); try @@ -1455,7 +1487,7 @@ Ice::Connection::initiateShutdown() const // // Before we shut down, we send a close connection message. // - BasicStream os(_instance.get()); + BasicStream os(_instance.get(), _instance->messageSizeMax()); os.write(magic[0]); os.write(magic[1]); os.write(magic[2]); diff --git a/cppe/src/IceE/Incoming.cpp b/cppe/src/IceE/Incoming.cpp index ab70183f599..26bb7138892 100644 --- a/cppe/src/IceE/Incoming.cpp +++ b/cppe/src/IceE/Incoming.cpp @@ -25,7 +25,7 @@ using namespace Ice; using namespace IceInternal; IceInternal::Incoming::Incoming(Instance* inst, Connection* con, BasicStream& is, const ObjectAdapterPtr& adapter) : - _os(inst), + _os(inst, inst->messageSizeMax()), _is(is), _connection(con) { diff --git a/cppe/src/IceE/Instance.cpp b/cppe/src/IceE/Instance.cpp index 25148880639..67ba7a6aa13 100644 --- a/cppe/src/IceE/Instance.cpp +++ b/cppe/src/IceE/Instance.cpp @@ -225,13 +225,6 @@ IceInternal::Instance::endpointFactory() const return _endpointFactory; } -size_t -IceInternal::Instance::messageSizeMax() const -{ - // No mutex lock, immutable. - return _messageSizeMax; -} - #ifdef ICEE_HAS_BATCH void IceInternal::Instance::flushBatchRequests() diff --git a/cppe/src/IceE/Instance.h b/cppe/src/IceE/Instance.h index 5971b5b94ca..b1e01b5d12a 100644 --- a/cppe/src/IceE/Instance.h +++ b/cppe/src/IceE/Instance.h @@ -51,7 +51,7 @@ public: ProxyFactoryPtr proxyFactory() const; OutgoingConnectionFactoryPtr outgoingConnectionFactory() const; EndpointFactoryPtr endpointFactory() const; - size_t messageSizeMax() const; + size_t messageSizeMax() const { return _messageSizeMax; /* Immutable */ } // Inlined for performance reasons. Ice::Int connectionIdleTime() const; #ifdef ICEE_HAS_BATCH void flushBatchRequests(); diff --git a/cppe/src/IceE/Outgoing.cpp b/cppe/src/IceE/Outgoing.cpp index ed015cfd0f5..b644e7eed48 100644 --- a/cppe/src/IceE/Outgoing.cpp +++ b/cppe/src/IceE/Outgoing.cpp @@ -12,6 +12,8 @@ #include <IceE/Connection.h> #include <IceE/Reference.h> #include <IceE/LocalException.h> +#include <IceE/Instance.h> +#include <IceE/Protocol.h> using namespace std; using namespace Ice; @@ -39,14 +41,14 @@ IceInternal::Outgoing::Outgoing(Connection* connection, Reference* ref, const st _connection(connection), _reference(ref), _state(StateUnsent), - _stream(ref->getInstance().get()) + _stream(ref->getInstance().get(), ref->getInstance()->messageSizeMax()) { switch(_reference->getMode()) { case Reference::ModeTwoway: case Reference::ModeOneway: { - _connection->prepareRequest(&_stream); + _stream.writeBlob(&(_connection->getRequestHeader()[0]), headerSize + sizeof(Int)); break; } |