You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by ve...@apache.org on 2012/08/02 17:29:33 UTC

svn commit: r1368538 - in /incubator/etch/trunk/binding-cpp/runtime: include/common/EtchConfig.h include/transport/EtchTcpOption.h src/main/transport/EtchTcpConnection.cpp src/main/transport/EtchTcpOption.cpp

Author: veithm
Date: Thu Aug  2 15:29:33 2012
New Revision: 1368538

URL: http://svn.apache.org/viewvc?rev=1368538&view=rev
Log:
ETCH-173 Added getter in TcpOption

Change-Id: Ifcb991cb3e855d63de6da63de72b5990ce670797

Modified:
    incubator/etch/trunk/binding-cpp/runtime/include/common/EtchConfig.h
    incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpOption.h
    incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
    incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpOption.cpp

Modified: incubator/etch/trunk/binding-cpp/runtime/include/common/EtchConfig.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/common/EtchConfig.h?rev=1368538&r1=1368537&r2=1368538&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchConfig.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchConfig.h Thu Aug  2 15:29:33 2012
@@ -24,6 +24,11 @@
 #include "string.h"
 
 #include "capu/Config.h"
+
+//Hash table size
 #define ETCH_DEFAULT_HASH_TABLE_SIZE 1000
 
+//Socket input buffer size (bytes)
+#define ETCH_DEFAULT_SOCKET_INPUT_BUFFER_SIZE 8192
+
 #endif

Modified: incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpOption.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpOption.h?rev=1368538&r1=1368537&r2=1368538&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpOption.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpOption.h Thu Aug  2 15:29:33 2012
@@ -80,15 +80,13 @@ public:
 private:
 
   capu::bool_t isValidNumber(const char * str, capu::int32_t len);
-  
+
   capu::bool_t checkBufferSize(capu::int32_t size);
 
   capu::bool_t checkLingerTime(capu::int32_t lingertime);
 
   capu::bool_t checkReconnectDelay(capu::int32_t delay);
 
-public:
-
   capu::int32_t mBufferSize;
 
   capu::int32_t mLingerTime;
@@ -99,6 +97,19 @@ public:
 
   capu::int32_t mNoDelay;
 
+public:
+  capu::int32_t getBufferSize();
+
+  capu::int32_t getLingerTime();
+
+  capu::int32_t getReconnectDelay();
+
+  capu::int32_t getKeepAlive();
+
+  capu::int32_t getNoDelay();
+
+
+
 };
 
 #endif /* ETCHTCPOPTION_H */

Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp?rev=1368538&r1=1368537&r2=1368538&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp Thu Aug  2 15:29:33 2012
@@ -33,19 +33,12 @@ EtchTcpConnection::EtchTcpConnection(Etc
 }
 
 EtchTcpConnection::~EtchTcpConnection() {
-
-
+  mIsStarted = false;
+  close();
   if (mThread != NULL) {
     mThread->join();
     delete mThread;
   }
-
-  if (mSocket != NULL) {
-    mSocket->close();
-    delete mSocket;
-    mSocket = NULL;
-    mIsStarted = false;
-  }
 }
 
 status_t EtchTcpConnection::send(capu::int8_t* buf, capu::uint32_t off, capu::uint32_t len) {
@@ -55,7 +48,7 @@ status_t EtchTcpConnection::send(capu::i
 }
 
 status_t EtchTcpConnection::readSocket() {
-  capu::SmartPointer<EtchFlexBuffer> buf = new EtchFlexBuffer(new capu::int8_t[8192], 8192);
+  capu::SmartPointer<EtchFlexBuffer> buf = new EtchFlexBuffer(new capu::int8_t[ETCH_DEFAULT_SOCKET_INPUT_BUFFER_SIZE], ETCH_DEFAULT_SOCKET_INPUT_BUFFER_SIZE);
 
   while (mIsStarted) {
     capu::int32_t n;
@@ -75,19 +68,19 @@ status_t EtchTcpConnection::readSocket()
 status_t EtchTcpConnection::openSocket(capu::bool_t reconnect) {
 
   mMutexConnection.lock();
-  // if a one time connection from a server socket listener, just
-  // return the existing socket.
+  // if a one time connection from a socket listener, just
+  // keep the existing socket.
   if (!reconnect && (mSocket != NULL)) {
     mMutexConnection.unlock();
     return ETCH_OK;
   }
   //temporary socket in a listener
-  if ((reconnect == false) && (mPort == 0) && (mHost.length() == 0)) {
+  if ((!reconnect) && (mPort == 0) && (mHost.length() == 0)) {
     mMutexConnection.unlock();
     return ETCH_ERROR;
   }
-  // if a reconnect but no retries allowed, then bail.
-  if (reconnect && (mOptions.mReconnectDelay == 0)) {
+  // if a reconnect but no retries allowed, then fail.
+  if (reconnect && (mOptions.getReconnectDelay() == 0)) {
     mMutexConnection.unlock();
     return ETCH_ERROR;
   }
@@ -100,11 +93,11 @@ status_t EtchTcpConnection::openSocket(c
     // have already failed at least once.
 
     if (reconnect || !first) {
-      if (mOptions.mReconnectDelay == 0) {
+      if (mOptions.getReconnectDelay() == 0) {
         mMutexConnection.unlock();
         return ETCH_ERROR;
       }
-      capu::Thread::Sleep(mOptions.mReconnectDelay);
+      capu::Thread::Sleep(mOptions.getReconnectDelay());
 
       if (!mIsStarted) {
         mMutexConnection.unlock();
@@ -126,7 +119,7 @@ status_t EtchTcpConnection::openSocket(c
   }
 
   mMutexConnection.unlock();
-  return ETCH_ERROR;
+  return ETCH_SOCKET_ECONNECT;
 }
 
 status_t EtchTcpConnection::transportData(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchFlexBuffer> buf) {
@@ -145,13 +138,17 @@ status_t EtchTcpConnection::transportQue
 status_t EtchTcpConnection::transportControl(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value) {
 
   if (control->equals(&EtchTcpConnection::START)) {
-    if (mIsStarted)
-      return ETCH_OK;
     mMutex.lock();
+    if (mIsStarted) {
+      mMutex.unlock();
+      return ETCH_OK;
+    }
     mIsStarted = true;
     mMutex.unlock();
+
     mThread = new capu::Thread(this);
     mThread->start();
+
     return ETCH_OK;
   }
 
@@ -159,19 +156,25 @@ status_t EtchTcpConnection::transportCon
     if (mIsStarted)
       return ETCH_OK;
     mMutex.lock();
+    if (mIsStarted) {
+      mMutex.unlock();
+      return ETCH_OK;
+    }
     mIsStarted = true;
     mMutex.unlock();
     mThread = new capu::Thread(this);
     mThread->start();
-    waitUp(((EtchInt32*) value.get())->get());
-    //TODO: Wait handling in one of the next releases
-    return ETCH_OK;
+    
+
+    return waitUp(((EtchInt32*) value.get())->get());
   }
 
   if (control->equals(&EtchTcpConnection::STOP)) {
-    if (!mIsStarted)
-      return ETCH_OK;
     mMutex.lock();
+    if (!mIsStarted) {
+      mMutex.unlock();
+      return ETCH_OK;
+    }
     mIsStarted = false;
     mMutex.unlock();
     close();
@@ -179,23 +182,27 @@ status_t EtchTcpConnection::transportCon
   }
 
   if (control->equals(&EtchTcpConnection::STOP_AND_WAIT_DOWN)) {
-    if (!mIsStarted)
-      return ETCH_OK;
     mMutex.lock();
+    if (!mIsStarted) {
+      mMutex.unlock();
+      return ETCH_OK;
+    }
     mIsStarted = false;
     mMutex.unlock();
+
     close();
-    waitDown(((EtchInt32*) value.get())->get());
-    //TODO: Wait handling in one of the next releases
-    return ETCH_OK;
+    return waitDown(((EtchInt32*) value.get())->get());
   }
 
   if (control->equals(&EtchTcpConnection::RESET)) {
-    if (!mIsStarted)
-      return ETCH_OK;
     mMutex.lock();
+    if (!mIsStarted) {
+      mMutex.unlock();
+      return ETCH_OK;
+    }
     mIsStarted = false;
     mMutex.unlock();
+
     close();
     return ETCH_OK;
   }
@@ -211,10 +218,11 @@ void EtchTcpConnection::setSession(EtchS
 }
 
 status_t EtchTcpConnection::close() {
-  if (mSocket != NULL)
+  if (mSocket != NULL) {
     return mSocket->close();
-  else
+  } else {
     return ETCH_ERROR;
+  }
 }
 
 capu::bool_t EtchTcpConnection::isStarted() {
@@ -249,13 +257,13 @@ void EtchTcpConnection::run() {
 }
 
 status_t EtchTcpConnection::setupSocket() {
-  if (mSocket->setBufferSize(mOptions.mBufferSize) != ETCH_OK)
+  if (mSocket->setBufferSize(mOptions.getBufferSize()) != ETCH_OK)
     return ETCH_ERROR;
-  if (mSocket->setKeepAlive((mOptions.mKeepAlive != 0)) != ETCH_OK)
+  if (mSocket->setKeepAlive((mOptions.getKeepAlive() != 0)) != ETCH_OK)
     return ETCH_ERROR;
-  if (mSocket->setLingerOption((mOptions.mLingerTime >= 0), mOptions.mLingerTime) != ETCH_OK)
+  if (mSocket->setLingerOption((mOptions.getLingerTime() >= 0), mOptions.getLingerTime()) != ETCH_OK)
     return ETCH_ERROR;
-  if (mSocket->setNoDelay((mOptions.mNoDelay != 0)) != ETCH_OK)
+  if (mSocket->setNoDelay((mOptions.getNoDelay() != 0)) != ETCH_OK)
     return ETCH_ERROR;
   return ETCH_OK;
 }

Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpOption.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpOption.cpp?rev=1368538&r1=1368537&r2=1368538&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpOption.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpOption.cpp Thu Aug  2 15:29:33 2012
@@ -126,4 +126,25 @@ capu::bool_t EtchTcpOption::isValidNumbe
     }
   }
   return true;
-}
\ No newline at end of file
+}
+
+
+capu::int32_t EtchTcpOption::getBufferSize() {
+  return mBufferSize;
+}
+
+capu::int32_t EtchTcpOption::getLingerTime() {
+  return mLingerTime;
+}
+
+capu::int32_t EtchTcpOption::getReconnectDelay()  {
+  return mReconnectDelay;
+}
+
+capu::int32_t EtchTcpOption::getKeepAlive() {
+  return mKeepAlive;
+}
+
+capu::int32_t EtchTcpOption::getNoDelay() {
+  return mNoDelay;
+}