summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2006-01-19 02:27:27 +0000
committerMichi Henning <michi@zeroc.com>2006-01-19 02:27:27 +0000
commitc10d339f366ce8b63f5f486665d072ccff0ad635 (patch)
treec8d064dd1bc4cf48c587fbfc0e8edcd07b3b770e /cpp
parentporting changes for bug 764 (diff)
downloadice-c10d339f366ce8b63f5f486665d072ccff0ad635.tar.bz2
ice-c10d339f366ce8b63f5f486665d072ccff0ad635.tar.xz
ice-c10d339f366ce8b63f5f486665d072ccff0ad635.zip
Bug 341.
Diffstat (limited to 'cpp')
-rw-r--r--cpp/include/Ice/Proxy.h1
-rw-r--r--cpp/src/Ice/OutgoingAsync.cpp5
-rw-r--r--cpp/src/Ice/Proxy.cpp23
-rw-r--r--cpp/src/slice2cpp/Gen.cpp9
-rwxr-xr-xcpp/src/slice2cs/Gen.cpp9
-rw-r--r--cpp/src/slice2java/Gen.cpp7
-rwxr-xr-xcpp/src/slice2vb/Gen.cpp9
-rw-r--r--cpp/test/Ice/operations/TwowaysAMI.cpp33
8 files changed, 57 insertions, 39 deletions
diff --git a/cpp/include/Ice/Proxy.h b/cpp/include/Ice/Proxy.h
index d43b4646696..3dc905397a8 100644
--- a/cpp/include/Ice/Proxy.h
+++ b/cpp/include/Ice/Proxy.h
@@ -147,6 +147,7 @@ public:
void __handleException(const ::Ice::LocalException&, int&);
void __rethrowException(const ::Ice::LocalException&);
void __checkTwowayOnly(const char*) const;
+ void __checkTwowayOnly(const ::std::string&) const;
::IceInternal::Handle< ::IceDelegate::Ice::Object> __getDelegate();
diff --git a/cpp/src/Ice/OutgoingAsync.cpp b/cpp/src/Ice/OutgoingAsync.cpp
index 736d4b4f28b..fca226a66be 100644
--- a/cpp/src/Ice/OutgoingAsync.cpp
+++ b/cpp/src/Ice/OutgoingAsync.cpp
@@ -284,6 +284,11 @@ IceInternal::OutgoingAsync::__prepare(const ObjectPrx& prx, const string& operat
_monitor.wait();
}
+ //
+ // Can't call async via a oneway proxy.
+ //
+ prx->__checkTwowayOnly(operation);
+
_reference = prx->__reference();
assert(!_connection);
_connection = _reference->getConnection(_compress);
diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp
index 61577f7351d..6524a4ce9c3 100644
--- a/cpp/src/Ice/Proxy.cpp
+++ b/cpp/src/Ice/Proxy.cpp
@@ -320,7 +320,6 @@ IceProxy::Ice::Object::ice_invoke_async(const AMI_Object_ice_invokePtr& cb,
const vector<Byte>& inParams,
const Context& context)
{
- __checkTwowayOnly("ice_invoke_async");
cb->__invoke(this, operation, mode, inParams, context);
}
@@ -766,6 +765,12 @@ IceProxy::Ice::Object::__rethrowException(const LocalException& ex)
ex.ice_throw();
}
+//
+// Overloaded for const char* and const string& because, most of time,
+// we call this with a const char* and we want to avoid the overhead
+// of constructing a string.
+//
+
void
IceProxy::Ice::Object::__checkTwowayOnly(const char* name) const
{
@@ -782,6 +787,22 @@ IceProxy::Ice::Object::__checkTwowayOnly(const char* name) const
}
}
+void
+IceProxy::Ice::Object::__checkTwowayOnly(const string& name) const
+{
+ //
+ // No mutex lock necessary, there is nothing mutable in this
+ // operation.
+ //
+
+ if(!ice_isTwoway())
+ {
+ TwowayOnlyException ex(__FILE__, __LINE__);
+ ex.operation = name;
+ throw ex;
+ }
+}
+
ostream&
operator<<(ostream& os, const ::IceProxy::Ice::Object& p)
{
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 8ac6d2f6ba1..c5649df1a49 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -4177,15 +4177,6 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p)
C << sb;
C << nl << "static const ::std::string __operation(\"" << name << "\");";
C << nl << "__prepare(__prx, " << flatName << ", " << operationModeToString(p->mode()) << ", __ctx);";
- if(p->returnsData())
- {
- C << nl << "if(!__prx->ice_isTwoway())";
- C << sb;
- C << nl << "::Ice::TwowayOnlyException ex(__FILE__, __LINE__);";
- C << nl << "ex.operation = __operation;";
- C << nl << "throw ex;";
- C << eb;
- }
writeMarshalCode(C, inParams, 0);
if(p->sendsClasses())
{
diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp
index 478ab219b86..ac459e16e77 100755
--- a/cpp/src/slice2cs/Gen.cpp
+++ b/cpp/src/slice2cs/Gen.cpp
@@ -4344,15 +4344,6 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p)
_out << nl << "try";
_out << sb;
_out << nl << "prepare__(prx__, \"" << name << "\", " << sliceModeToIceMode(p) << ", ctx__);";
- if(p->returnsData())
- {
- _out << nl << "if(!prx__.ice_isTwoway())";
- _out << sb;
- _out << nl << "Ice.TwowayOnlyException ex = new Ice.TwowayOnlyException();";
- _out << nl << "ex.operation = \"" << name << "\";";
- _out << nl << "throw ex;";
- _out << eb;
- }
for(q = inParams.begin(); q != inParams.end(); ++q)
{
string typeS = typeToString(q->first);
diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp
index 0e8418cf660..648dd82c3b8 100644
--- a/cpp/src/slice2java/Gen.cpp
+++ b/cpp/src/slice2java/Gen.cpp
@@ -4551,13 +4551,6 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p)
out << nl << "try";
out << sb;
out << nl << "__prepare(__prx, \"" << p->name() << "\", " << sliceModeToIceMode(p) << ", __ctx);";
- if(p->returnsData())
- {
- out << nl << "if(!__prx.ice_isTwoway())";
- out << sb;
- out << nl << "throw new Ice.TwowayOnlyException(\"" << p->name() << "\");";
- out << eb;
- }
iter = 0;
for(pli = inParams.begin(); pli != inParams.end(); ++pli)
{
diff --git a/cpp/src/slice2vb/Gen.cpp b/cpp/src/slice2vb/Gen.cpp
index bc5e5f1dba1..e0c1b5bf525 100755
--- a/cpp/src/slice2vb/Gen.cpp
+++ b/cpp/src/slice2vb/Gen.cpp
@@ -4829,15 +4829,6 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p)
_out.inc();
_out << nl << "prepare__(prx__, \"" << p->name() << "\", " << sliceModeToIceMode(p) << ", ctx__)";
if(p->returnsData())
- {
- _out << nl << "If Not prx__.ice_isTwoway() Then";
- _out.inc();
- _out << nl << "Dim ex As Ice.TwowayOnlyException = New Ice.TwowayOnlyException()";
- _out << nl << "ex.operation = \"" << p->name() << "\"";
- _out << nl << "Throw ex";
- _out.dec();
- _out << nl << "End If";
- }
for(q = inParams.begin(); q != inParams.end(); ++q)
{
string typeS = typeToString(q->first);
diff --git a/cpp/test/Ice/operations/TwowaysAMI.cpp b/cpp/test/Ice/operations/TwowaysAMI.cpp
index 59f58e47aad..456ed9e5e80 100644
--- a/cpp/test/Ice/operations/TwowaysAMI.cpp
+++ b/cpp/test/Ice/operations/TwowaysAMI.cpp
@@ -83,6 +83,24 @@ public:
typedef IceUtil::Handle<AMI_MyClass_opVoidI> AMI_MyClass_opVoidIPtr;
+class AMI_MyClass_opVoidExI : public Test::AMI_MyClass_opVoid, public CallbackBase
+{
+public:
+
+ virtual void ice_response()
+ {
+ test(false);
+ }
+
+ virtual void ice_exception(const ::Ice::Exception& ex)
+ {
+ test(dynamic_cast<const ::Ice::TwowayOnlyException*>(&ex));
+ called();
+ }
+};
+
+typedef IceUtil::Handle<AMI_MyClass_opVoidExI> AMI_MyClass_opVoidExIPtr;
+
class AMI_MyClass_opByteI : public Test::AMI_MyClass_opByte, public CallbackBase
{
public:
@@ -113,7 +131,7 @@ public:
virtual void ice_exception(const ::Ice::Exception& ex)
{
- test(dynamic_cast<const ::Ice::Exception*>(&ex));
+ test(dynamic_cast<const ::Ice::TwowayOnlyException*>(&ex));
called();
}
};
@@ -822,10 +840,17 @@ void
twowaysAMI(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrx& p)
{
{
- // Check that we can invoke a void operation via a oneway proxy.
+ // Check that a call to a void operation raises TwowayOnlyException
+ // in the ice_exception() callback instead of at the point of call.
Test::MyClassPrx oneway = Test::MyClassPrx::uncheckedCast(p->ice_oneway());
- AMI_MyClass_opVoidIPtr cb = new AMI_MyClass_opVoidI;
- oneway->opVoid_async(cb);
+ AMI_MyClass_opVoidExIPtr cb = new AMI_MyClass_opVoidExI;
+ try {
+ oneway->opVoid_async(cb);
+ }
+ catch(const Ice::Exception&)
+ {
+ test(false);
+ }
test(cb->check());
}