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/02/08 10:15:01 UTC

svn commit: r1241828 - in /incubator/etch/trunk/binding-cpp/runtime: include/common/EtchObject.h include/common/EtchServerSocket.h include/common/EtchSocket.h src/main/CMakeLists.txt src/main/common/EtchServerSocket.cpp src/main/common/EtchSocket.cpp

Author: veithm
Date: Wed Feb  8 09:15:01 2012
New Revision: 1241828

URL: http://svn.apache.org/viewvc?rev=1241828&view=rev
Log:
ETCH-145 EtchSocket Wrapper

capu socket wrapper for etch project

Change-Id: I320fd828903d5cf69a97e4dd0fbea130d36d645f

Added:
    incubator/etch/trunk/binding-cpp/runtime/include/common/EtchServerSocket.h
    incubator/etch/trunk/binding-cpp/runtime/include/common/EtchSocket.h
    incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchServerSocket.cpp
    incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchSocket.cpp
Modified:
    incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObject.h
    incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt

Modified: incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObject.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObject.h?rev=1241828&r1=1241827&r2=1241828&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObject.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObject.h Wed Feb  8 09:15:01 2012
@@ -37,6 +37,7 @@ enum EtchObjectTypeIds {
   EOTID_HASHTABLE,
   EOTID_SET,
   EOTID_SOCKET,
+  EOTID_SERVER_SOCKET,
 
   EOTID_NATIVE_INT8,
   EOTID_NATIVE_INT16,

Added: incubator/etch/trunk/binding-cpp/runtime/include/common/EtchServerSocket.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/common/EtchServerSocket.h?rev=1241828&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchServerSocket.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchServerSocket.h Wed Feb  8 09:15:01 2012
@@ -0,0 +1,86 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __ETCHSERVERSOCKET_H__
+#define __ETCHSERVERSOCKET_H__
+#include "capu/os/ServerSocket.h"
+#include "capu/os/Socket.h"
+#include "capu/util/SmartPointer.h"
+#include "common/EtchSocket.h"
+
+class EtchServerSocket : public EtchObject {
+public:
+
+  /**
+   * TypeID
+   */
+  static const capu::int32_t TYPE_ID = EOTID_SERVER_SOCKET;
+
+  /**
+   * Default Constructor
+   */
+  EtchServerSocket();
+
+  /**
+   * Destructor
+   */
+  virtual ~EtchServerSocket();
+
+  /**
+   * The program flow will be blocked until a connection arrives
+   * Programmer is responsible for deallocating memory of returning socket.
+   * @return Socket if a connection is accepted
+   *         NULL otherwise
+   */
+  EtchSocket* accept();
+
+  /**
+   * Close the socket which is used for accepting connection
+   * @return ETCH_OK if the socket is successfully closed
+   *         ETCH_SOCKET_ESOCKET if the socket is not created
+   */
+  status_t close();
+
+  /**
+   *
+   * @param port indicates port number
+   * @param address to bind if it is not given it accepts all connection from any address
+   * @return ETCH_OK  if the server socket is successfully bound
+   *         ETCH_SOCKET_EADDR if the addr is faulty
+   *         ETCH_ERROR  if the socket is already bound
+   *         ETCH_EINVAL if the addr is NULL or port is equal to 0
+   *         ETCH_SOCKET_ESOCKET if the socket is not created
+   */
+  status_t bind(capu::uint16_t port, const char * addr = NULL);
+
+  /**
+   *
+   * @param backlog (maximum length of the queue of pending connections)
+   * @return ETCH_OK if the listen is successful
+   *         ETCH_SOCKET_ESOCKET if the socket is not created
+   *         ETCH_ERROR otherwise
+   */
+  status_t listen(capu::uint8_t backlog);
+
+private:
+  capu::ServerSocket mServerSocket;
+
+};
+
+#endif /* ETCHSERVERSOCKET_H */
+

Added: incubator/etch/trunk/binding-cpp/runtime/include/common/EtchSocket.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/common/EtchSocket.h?rev=1241828&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchSocket.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchSocket.h Wed Feb  8 09:15:01 2012
@@ -0,0 +1,188 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __ETCHSOCKET_H__
+#define __ETCHSOCKET_H__
+#include "capu/os/Socket.h"
+#include "common/EtchError.h"
+#include "common/EtchObject.h"
+
+class EtchSocket : public EtchObject {
+public:
+
+  /**
+   * TypeID
+   */
+  static const capu::int32_t TYPE_ID = EOTID_SOCKET;
+
+  /**
+   * Default Constructor
+   */
+  EtchSocket();
+
+  /**
+   * Destructor
+   */
+  ~EtchSocket();
+
+  /**
+   * Send the messages
+   * @param buffer    the content of message that will be sent to destination
+   * @param length    the length of message that will be sent to destination
+   * @return ETCH_OK if the sent is successful
+   *         ETCH_EINVAL if the buffer is NULL
+   *         ETCH_SOCKET_ESOCKET if the socket is not created
+   *         ETCH_ERROR otherwise
+   */
+  status_t send(unsigned char * buffer, capu::int32_t length);
+
+  /**
+   * Receive message
+   * @param buffer    buffer that will be used to store incoming message
+   * @param length    buffer size
+   * @param numBytes  number of bytes on socket
+   * @return ETCH_OK if the receive is successfully executed
+   *         ETCH_TIMEOUT if there has been a timeout
+   *         ETCH_SOCKET_ESOCKET if the socket is not created
+   *         ETCH_ERROR otherwise
+   */
+  status_t receive(unsigned char * buffer, capu::int32_t length, capu::int32_t& numBytes);
+
+  /**
+   * close the socket
+   * @return ETCH_OK if the socket is correctly closed
+   *         ETCH_SOCKET_ESOCKET if the socket is not created
+   *         ETCH_ERROR otherwise
+   */
+  status_t close();
+
+  /**
+   * connect to the given address
+   * @param dest_addr destination address of server
+   * @param port      port number of service
+   * @return  ETCH_OK if correctly connects to specified address
+   *          ETCH_SOCKET_ECONNECT if the connection is not successful
+   *          ETCH_SOCKET_EADDR if the given address is not resolved.
+   *          ETCH_EINVAL if the dest_addr is NULL
+   *          ETCH_SOCKET_ESOCKET if the socket is not created
+   */
+  status_t connect(unsigned char * dest_addr, capu::uint16_t port);
+
+  /**
+   * Sets the maximum socket buffer in bytes. The kernel doubles this value (to allow space for bookkeeping overhead)
+   * Set the receive buffer size
+   * Sets buffer size information.
+   * @return ETCH_OK if the buffer is successfully set for both receive and send operations
+   *         ETCH_SOCKET_ESOCKET if the socket is not created
+   *         ETCH_ERROR otherwise
+   */
+  status_t setBufferSize(capu::int32_t bufferSize);
+
+  /**
+   * Set the linger option for socket
+   * Specifies whether the socket lingers on close() if data is present.
+   * @return ETCH_OK if the LingerOption is successfully set
+   *         ETCH_SOCKET_ESOCKET if the socket is not created
+   *         ETCH_ERROR otherwise
+   */
+  status_t setLingerOption(capu::bool_t isLinger, capu::int32_t linger);
+
+
+  /**
+   * Set no delay option
+   * Specifies whether the Nagle algorithm used by TCP for send coalescing is to be disabled.
+   * @return ETCH_OK if the NoDelay is successfully set
+   *         ETCH_SOCKET_ESOCKET if the socket is not created
+   *         ETCH_ERROR otherwise
+   */
+  status_t setNoDelay(capu::bool_t noDelay);
+
+  /**
+   * Set Keep Alive option
+   * Keeps connections active by enabling periodic transmission of messages, if this is supported by the protocol.
+   * @return ETCH_OK if the KeepAlive is successfully set
+   *         ETCH_SOCKET_ESOCKET if the socket is not created
+   *         ETCH_ERROR otherwise
+   */
+  status_t setKeepAlive(capu::bool_t keepAlive);
+
+  /**
+   * Set Timeout
+   * Sets the timeout value that specifies the maximum amount of time an input function waits until it completes
+   * @return ETCH_OK if the Timeout for receive operation is successfully set
+   *         ETCH_SOCKET_ESOCKET if the socket is not created
+   *         ETCH_ERROR otherwise
+   */
+  status_t setTimeout(capu::int32_t timeout);
+
+  /**
+   * get the send and receive buffer size
+   * gets buffer size information.
+   * @return ETCH_OK if the buffer is successfully set for both receive and send operations
+   *         ETCH_SOCKET_ESOCKET if the socket is not created
+   *         ETCH_ERROR otherwise
+   */
+  status_t getBufferSize(capu::int32_t& bufferSize);
+
+  /**
+   * get the linger option for socket
+   * @return ETCH_OK if the LingerOption is successfully set
+   *         ETCH_SOCKET_ESOCKET if the socket is not created
+   *         ETCH_ERROR otherwise
+   */
+  status_t getLingerOption(capu::bool_t& isLinger, capu::int32_t& linger);
+
+  /**
+   * Get no delay option
+   * @return ETCH_OK if the NoDelay is successfully set
+   *         ETCH_SOCKET_ESOCKET if the socket is not created
+   *         ETCH_ERROR otherwise
+   */
+  status_t getNoDelay(capu::bool_t& noDelay);
+
+  /**
+   * Get Keep Alive option
+   * @return ETCH_OK if the KeepAlive is successfully set
+   *         ETCH_SOCKET_ESOCKET if the socket is not created
+   *         ETCH_ERROR otherwise
+   */
+  status_t getKeepAlive(capu::bool_t& keepAlive);
+
+
+  /**
+   * Get Timeout
+   * @return ETCH_OK if the Timeout for receive operation is successfully set
+   *         ETCH_SOCKET_ESOCKET if the socket is not created
+   *         ETCH_ERROR otherwise
+   */
+  status_t getTimeout(capu::int32_t& timeout);
+
+  friend class EtchServerSocket;
+
+private:
+  capu::Socket *mSocket;
+
+  /**
+   * Constructor
+   */
+  EtchSocket(capu::Socket* soc);
+
+};
+
+#endif /* ETCHSOCKET_H */
+

Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt?rev=1241828&r1=1241827&r2=1241828&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt Wed Feb  8 09:15:01 2012
@@ -40,6 +40,8 @@ SET(MAIN_INCLUDES
 	${PROJECT_SOURCE_DIR}/include/common/EtchList.h
     ${PROJECT_SOURCE_DIR}/include/common/EtchNative.h
     ${PROJECT_SOURCE_DIR}/include/common/EtchNativeArray.h
+    ${PROJECT_SOURCE_DIR}/include/common/EtchSocket.h
+    ${PROJECT_SOURCE_DIR}/include/common/EtchServerSocket.h
     ${PROJECT_SOURCE_DIR}/include/util/EtchUtil.h
     )
 
@@ -54,6 +56,8 @@ SET(MAIN_SOURCES
     common/EtchLong.cpp
     common/EtchFloat.cpp
     common/EtchDouble.cpp
+    common/EtchSocket.cpp
+    common/EtchServerSocket.cpp
     util/EtchUtil.cpp
     )
 

Added: incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchServerSocket.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchServerSocket.cpp?rev=1241828&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchServerSocket.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchServerSocket.cpp Wed Feb  8 09:15:01 2012
@@ -0,0 +1,49 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "common/EtchServerSocket.h"
+#include "common/EtchObject.h"
+#include "capu/util/SmartPointer.h"
+#include "common/EtchSocket.h"
+
+EtchServerSocket::EtchServerSocket()
+: EtchObject(EtchServerSocket::TYPE_ID) {
+
+}
+
+EtchServerSocket::~EtchServerSocket() {
+  this->close();
+}
+
+status_t EtchServerSocket::listen(capu::uint8_t backlog) {
+  return mServerSocket.listen(backlog);
+}
+
+status_t EtchServerSocket::close() {
+  return mServerSocket.close();
+}
+
+EtchSocket* EtchServerSocket::accept() {
+  capu::Socket *capu_soc = mServerSocket.accept();
+  EtchSocket *sock = new EtchSocket(capu_soc);
+  return sock;
+}
+
+status_t EtchServerSocket::bind(capu::uint16_t port, const char* addr)
+{
+  return mServerSocket.bind(port,addr);
+}
\ No newline at end of file

Added: incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchSocket.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchSocket.cpp?rev=1241828&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchSocket.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchSocket.cpp Wed Feb  8 09:15:01 2012
@@ -0,0 +1,92 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "common/EtchSocket.h"
+
+EtchSocket::EtchSocket()
+: EtchObject(EtchSocket::TYPE_ID) {
+  mSocket = new capu::Socket();
+}
+
+EtchSocket::EtchSocket(capu::Socket* soc)
+: EtchObject(EtchSocket::TYPE_ID) {
+  if (soc == NULL)
+    mSocket = new capu::Socket();
+  else
+    mSocket = soc;
+}
+
+EtchSocket::~EtchSocket() {
+  delete mSocket;
+}
+
+status_t EtchSocket::close() {
+  return mSocket->close();
+}
+
+status_t EtchSocket::connect(unsigned char* dest_addr, capu::uint16_t port) {
+  return mSocket->connect(dest_addr, port);
+}
+
+status_t EtchSocket::receive(unsigned char * buffer, capu::int32_t length, capu::int32_t& numBytes) {
+  return mSocket->receive(buffer, length, numBytes);
+}
+
+status_t EtchSocket::send(unsigned char* buffer, capu::int32_t length) {
+  return mSocket->send(buffer, length);
+}
+
+status_t EtchSocket::setBufferSize(capu::int32_t bufferSize) {
+  return mSocket->setBufferSize(bufferSize);
+}
+
+status_t EtchSocket::setKeepAlive(capu::bool_t keepAlive) {
+  return mSocket->setKeepAlive(keepAlive);
+}
+
+status_t EtchSocket::setLingerOption(capu::bool_t isLinger, capu::int32_t linger) {
+  return mSocket->setLingerOption(isLinger, linger);
+}
+
+status_t EtchSocket::setNoDelay(capu::bool_t noDelay) {
+  return mSocket->setNoDelay(noDelay);
+}
+
+status_t EtchSocket::setTimeout(capu::int32_t timeout) {
+  return mSocket->setTimeout(timeout);
+}
+
+status_t EtchSocket::getBufferSize(capu::int32_t& bufferSize) {
+  return mSocket->getBufferSize(bufferSize);
+}
+
+status_t EtchSocket::getKeepAlive(capu::bool_t& keepAlive) {
+  return mSocket->getKeepAlive(keepAlive);
+}
+
+status_t EtchSocket::getLingerOption(capu::bool_t& isLinger, capu::int32_t& linger) {
+  return mSocket->getLingerOption(isLinger, linger);
+}
+
+status_t EtchSocket::getNoDelay(capu::bool_t& noDelay) {
+  return mSocket->getNoDelay(noDelay);
+}
+
+status_t EtchSocket::getTimeout(capu::int32_t& timeout) {
+  return mSocket->getTimeout(timeout);
+}