ETCH-216 Small improvement in TcpConnection
Avoiding QNX Sockets to fail while setting properties
Fixed small bugs in code generation
Change-Id: I2fe3a9dcae70525544f774f7ffc07facae9234fb
git-svn-id: https://svn.apache.org/repos/asf/incubator/etch/trunk@1376589 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/helper_cpp.vm b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/helper_cpp.vm
index 8b35c5b..1a47997 100644
--- a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/helper_cpp.vm
+++ b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/helper_cpp.vm
@@ -182,6 +182,7 @@
//create valuefactory instance
ValueFactory${i}* vf = new ValueFactory${i}(uri);
+ stack->setValueFactory(vf);
EtchObject* vfobj = (EtchObject*) vf;
EtchObject* resobj = NULL;
res->put(EtchTransport<ValueFactory${i}>::VALUE_FACTORY(), vfobj, resobj);
diff --git a/binding-cpp/runtime/src/main/support/EtchStack.cpp b/binding-cpp/runtime/src/main/support/EtchStack.cpp
index 8674e87..0841cf0 100644
--- a/binding-cpp/runtime/src/main/support/EtchStack.cpp
+++ b/binding-cpp/runtime/src/main/support/EtchStack.cpp
@@ -33,6 +33,7 @@
, mTransportPacket(NULL)
, mTransportMessage(NULL)
, mResources(NULL)
+ , mValueFactory(NULL)
, mMailboxManager(NULL)
, mDeliveryService(NULL)
, mStub(NULL)
diff --git a/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp b/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
index a486520..fb68710 100644
--- a/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
+++ b/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
@@ -257,46 +257,49 @@
void EtchTcpConnection::run() {
+ status_t status;
capu::bool_t first = true;
while (mIsStarted) {
- if (openSocket(!first) != ETCH_OK) {
+ status = openSocket(!first);
+ if (status != ETCH_OK) {
CAPU_LOG_ERROR(mRuntime->getLogger(), "EtchTcpConnection", "%s : %d => Socket has not been successfully opened", mHost.c_str(), mPort);
break;
}
- status_t res = setupSocket();
- if (res != ETCH_OK) {
+ status = setupSocket();
+ if (status != ETCH_OK) {
close();
break;
}
CAPU_LOG_DEBUG(mRuntime->getLogger(), "EtchTcpConnection", "%s : %d => Socket has been opened and connection has been successfully established and start reading", mHost.c_str(), mPort);
fireUp();
CAPU_LOG_DEBUG(mRuntime->getLogger(), "EtchTcpConnection", "%s : %d => FireUp was send to the Stack", mHost.c_str(), mPort);
- if (readSocket() != ETCH_OK) {
- close();
- CAPU_LOG_TRACE(mRuntime->getLogger(), "EtchTcpConnection", "%s : %d => Connection closing", mHost.c_str(), mPort);
- break;
- }
+ status = readSocket();
CAPU_LOG_TRACE(mRuntime->getLogger(), "EtchTcpConnection", "%s : %d => Connection closing", mHost.c_str(), mPort);
fireDown();
CAPU_LOG_DEBUG(mRuntime->getLogger(), "EtchTcpConnection", "%s : %d => FireDown was send to the Stack", mHost.c_str(), mPort);
close();
first = false;
}
- mIsStarted = false;
}
status_t EtchTcpConnection::setupSocket() {
- if (mSocket->setBufferSize(mOptions.getBufferSize()) != ETCH_OK)
+ if (mOptions.getBufferSize() != 0) {
+ if (mSocket->setBufferSize(mOptions.getBufferSize()) != ETCH_OK) {
+ return ETCH_ERROR;
+ }
+ }
+ if (mSocket->setKeepAlive((mOptions.getKeepAlive() != 0)) != ETCH_OK) {
return ETCH_ERROR;
- if (mSocket->setKeepAlive((mOptions.getKeepAlive() != 0)) != ETCH_OK)
+ }
+ if (mSocket->setLingerOption((mOptions.getLingerTime() >= 0), mOptions.getLingerTime()) != ETCH_OK) {
return ETCH_ERROR;
- if (mSocket->setLingerOption((mOptions.getLingerTime() >= 0), mOptions.getLingerTime()) != ETCH_OK)
+ }
+ if (mSocket->setNoDelay((mOptions.getNoDelay() != 0)) != ETCH_OK) {
return ETCH_ERROR;
- if (mSocket->setNoDelay((mOptions.getNoDelay() != 0)) != ETCH_OK)
- return ETCH_ERROR;
+ }
CAPU_LOG_TRACE(mRuntime->getLogger(), "EtchTcpConnection", "%s : %d => Settings for socket has been successfully configured", mHost.c_str(), mPort);
return ETCH_OK;
}
diff --git a/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp b/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp
index 16641e2..8277ffa 100644
--- a/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp
+++ b/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp
@@ -65,7 +65,7 @@
return ETCH_EUNIMPL;
} else {
// TODO add runtime
- c = new EtchTcpConnection(NULL, (EtchSocket*) socket, &u);
+ c = new EtchTcpConnection(mRuntime, (EtchSocket*) socket, &u);
}
stack->setTransportData(c);
diff --git a/binding-cpp/runtime/src/test/transport/EtchTcpConnectionTest.cpp b/binding-cpp/runtime/src/test/transport/EtchTcpConnectionTest.cpp
index 79a2927..a2eb9bc 100644
--- a/binding-cpp/runtime/src/test/transport/EtchTcpConnectionTest.cpp
+++ b/binding-cpp/runtime/src/test/transport/EtchTcpConnectionTest.cpp
@@ -50,18 +50,22 @@
class MockListener : public virtual EtchSessionListener<EtchSocket> {
public:
+ MockListener() : socket(NULL) {}
- //Communication Test Between Peers
+ ~MockListener() {
+ delete socket;
+ }
EtchResources resources;
+ EtchSocket* socket;
+ //Communication Test Between Peers
status_t sessionAccepted(EtchSocket* connection) {
EtchString _socket("socket");
EtchObject *tmp;
resources.put(_socket, connection, tmp);
connection->send((unsigned char *) "mock", 4);
- capu::Thread::Sleep(1000);
- delete connection;
+ socket = connection;
return ETCH_OK;
}
@@ -113,15 +117,15 @@
EtchSessionData* mPacketizer = new MockPacketizer();
//START THE LISTENER
listener->setSession(mSessionListener);
- listener->transportControl(new EtchString(EtchTcpListener::START_AND_WAIT_UP()), new EtchInt32(2000));
+ EXPECT_EQ(ETCH_OK, listener->transportControl(new EtchString(EtchTcpListener::START_AND_WAIT_UP()), new EtchInt32(400000)));
//START THE TRANSPORT
conn->setSession(mPacketizer);
- conn->transportControl(new EtchString(EtchTcpConnection::START_AND_WAIT_UP()), new EtchInt32(2000));
+ EXPECT_EQ(ETCH_OK, conn->transportControl(new EtchString(EtchTcpConnection::START_AND_WAIT_UP()), new EtchInt32(400000)));
EXPECT_TRUE(conn->isStarted());
//STOP THE TRANSPORT
- conn->transportControl(new EtchString(EtchTcpConnection::STOP_AND_WAIT_DOWN()), new EtchInt32(2000));
+ EXPECT_EQ(ETCH_OK, conn->transportControl(new EtchString(EtchTcpConnection::STOP_AND_WAIT_DOWN()), new EtchInt32(400000)));
//STOP THE LISTENER
- listener->transportControl(new EtchString(EtchTcpListener::STOP_AND_WAIT_DOWN()), new EtchInt32(2000));
+ EXPECT_EQ(ETCH_OK, listener->transportControl(new EtchString(EtchTcpListener::STOP_AND_WAIT_DOWN()), new EtchInt32(400000)));
EXPECT_FALSE(conn->isStarted());
conn->setSession(NULL);
diff --git a/examples/helloworld/cpp/build.xml b/examples/helloworld/cpp/build.xml
index 7f8f053..2378ec9 100644
--- a/examples/helloworld/cpp/build.xml
+++ b/examples/helloworld/cpp/build.xml
@@ -95,7 +95,7 @@
<target name="build-cpp" depends="generate-sources" if="USE.cmake">
<cmake srcdir="${basedir}" bindir="${basedir}/target" buildtype="Debug" >
- <generator name="Visual Studio 8 2005" platform="windows" />
+ <!-- <generator name="Visual Studio 8 2005" platform="windows" />-->
<variable name="ETCH_INCLUDE_CAPU_DIR" type="PATH" value="${Etch.basedir}/binding-cpp/runtime/lib/capu/deliverable/capu/include/capu" />
<variable name="ETCH_HOME" type="PATH" value="${etch.home}" />
</cmake>
@@ -103,14 +103,10 @@
<fileset dir="${target}" >
<include name="helloworld-client" />
<include name="helloworld-server" />
- <include name="debug/helloworld-client.exe" />
- <include name="debug/helloworld-server.exe" />
+ <include name="Debug/helloworld-client.exe" />
+ <include name="Debug/helloworld-server.exe" />
</fileset>
</copy>
- <delete file="${target}/helloworld-client" quiet="true" />
- <delete file="${target}/helloworld-server" quiet="true" />
- <delete file="${target}/debug/helloworld-client.exe" quiet="true" />
- <delete file="${target}/debug/helloworld-server.exe" quiet="true" />
<chmod perm="+x">
<fileset dir="${bin}">
<include name="helloworld-client" />