Remove dynamic exceptions
[anna.git] / source / comm / ClientSocket.cpp
index 0e18cdf..c910a1e 100644 (file)
@@ -1,37 +1,9 @@
-// ANNA - Anna is Not 'N' Anymore
-//
-// (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
-//
-// https://bitbucket.org/testillano/anna
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-//     * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-//     * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-//     * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Authors: eduardo.ramos.testillano@gmail.com
-//          cisco.tierra@gmail.com
+// ANNA - Anna is Not Nothingness Anymore                                                         //
+//                                                                                                //
+// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
+//                                                                                                //
+// See project site at http://redmine.teslayout.com/projects/anna-suite                           //
+// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
 
 
 #include <sys/ioctl.h>
@@ -75,7 +47,7 @@ const Millisecond comm::ClientSocket::DefaultMaxWriteDelay(500);
 
 
 void comm::ClientSocket::initialize()
-throw() {
+{
    a_status = Status::None;
    a_transport = NULL;
    a_expectedSize = -1;
@@ -92,7 +64,7 @@ throw() {
  * porque ya está protegido por éste.
  */
 void comm::ClientSocket::setfd(const int fd)
-throw(RuntimeException) {
+noexcept(false) {
    Socket::a_fd = fd;
    Socket::a_isBound = true;
    activate(Status::Connected);
@@ -128,7 +100,7 @@ throw(RuntimeException) {
  * invocar al metodo comm::Receiver::initialize.
  */
 void comm::ClientSocket::setReceiver(comm::Receiver* receiver)
-throw(RuntimeException) {
+noexcept(false) {
    if (a_receiver && Socket::a_receiverFactory)
       Socket::a_receiverFactory->release(a_receiver);
 
@@ -140,7 +112,7 @@ throw(RuntimeException) {
 
 // Protegido desde el Socket::close
 void comm::ClientSocket::do_close()
-throw() {
+{
    Socket::do_close();
 
    if (a_transport != NULL) {
@@ -165,7 +137,7 @@ throw() {
 }
 
 comm::Server* comm::ClientSocket::getServer()
-throw(RuntimeException) {
+noexcept(false) {
    Guard guard(*this, "comm::ClientSocket (getServer)");
    const INetAddress& remoteAddress = getRemoteAccessPoint().getINetAddress();
    const Device* device = remoteAddress.getDevice(false);
@@ -202,7 +174,7 @@ throw(RuntimeException) {
 // la conexión.
 //_________________________________________________________________________________
 void comm::ClientSocket::connect()
-throw(RuntimeException) {
+noexcept(false) {
    Guard guard(*this, "comm::ClientSocket (connect)");
    anna_socket_assert(isConnected() == true, "Already connected");
 
@@ -280,13 +252,13 @@ throw(RuntimeException) {
 }
 
 void comm::ClientSocket::send(comm::Message& message)
-throw(RuntimeException) {
+noexcept(false) {
    Guard guard(*this, "comm::ClientSocket (send)");
    do_write(getTransport()->code(message));
 }
 
 void comm::ClientSocket::send(comm::Message* message)
-throw(RuntimeException) {
+noexcept(false) {
    if (message == NULL)
       throw RuntimeException("comm::ClientSocket::send | Cannot send a NULL message", ANNA_FILE_LOCATION);
 
@@ -300,7 +272,7 @@ throw(RuntimeException) {
 // su buffer, se cerrará.
 //_______________________________________________________________________
 void comm::ClientSocket::requestClose()
-throw() {
+{
    Communicator* communicator = app::functions::component <Communicator> (ANNA_FILE_LOCATION);
    a_status |= Status::ClosePending;
    // Sólo tiene efecto real en modo ST
@@ -323,9 +295,8 @@ throw() {
 // Se invoca desde un entorno protegido, por lo que no hace falta SSCC.
 //---------------------------------------------------------------------------------------
 comm::Socket::Notify::_v comm::ClientSocket::receive()
-throw(RuntimeException) {
+noexcept(false) {
    Notify::_v result;
-   int queueLength = 0;
 
    if (a_reader.getMaxSize() == 0) {
       string msg(asString());
@@ -398,7 +369,7 @@ throw(RuntimeException) {
 }
 
 comm::Socket::Notify::_v comm::ClientSocket::wait(const Millisecond &timeout, const bool _receive)
-throw(RuntimeException) {
+noexcept(false) {
    Guard guard(*this, "comm::ClientSocket (wait)");
 
    if (Socket::isOpened() == false) {
@@ -439,7 +410,7 @@ throw(RuntimeException) {
 // la longitud esperada => prepara el a_data para recibir el siguiente bloque.
 //---------------------------------------------------------------------------------------
 const DataBlock* comm::ClientSocket::fetch()
-throw(RuntimeException) {
+noexcept(false) {
    if (a_status & Status::ClosePending)
       return NULL;
 
@@ -498,7 +469,7 @@ throw(RuntimeException) {
 }
 
 void comm::ClientSocket::calculeExpectedSize(const DataBlock& data)
-throw() {
+{
    try {
       if ((a_expectedSize = getTransport()->calculeSize(data)) != -1) {
          LOGDEBUG(
@@ -521,7 +492,7 @@ throw() {
 }
 
 comm::Transport* comm::ClientSocket::reserveTransport()
-throw(RuntimeException) {
+noexcept(false) {
    if (a_transport == NULL) {
       if (Socket::a_transportFactory == NULL) {
          string msg(asString());
@@ -542,7 +513,7 @@ throw(RuntimeException) {
 }
 
 comm::Transport* comm::ClientSocket::unsafe_reserveTransport()
-throw(RuntimeException) {
+noexcept(false) {
    if (a_transport == NULL) {
       if (Socket::a_transportFactory == NULL) {
          string msg(asString());
@@ -558,7 +529,7 @@ throw(RuntimeException) {
 }
 
 comm::Receiver* comm::ClientSocket::reserveReceiver()
-throw(RuntimeException) {
+noexcept(false) {
    if (a_receiver == NULL && Socket::a_receiverFactory != NULL) {
       Guard guard(this, "comm::ClientSocket::reserveReceiver");
 
@@ -573,7 +544,7 @@ throw(RuntimeException) {
 // Este metodo se sobre-escribira en commsec::ClientSocket para establecer la conexion mediante las
 // funciones SSH
 int comm::ClientSocket::do_connect(const sockaddr* s, const  int len)
-throw(RuntimeException) {
+noexcept(false) {
    int r;
    anna_signal_shield(r, ::connect(a_fd, s, len));
    return r;
@@ -592,7 +563,7 @@ throw(RuntimeException) {
 //     problemas de interpretación en el extremo remoto.
 //----------------------------------------------------------------------------------------------------
 void comm::ClientSocket::do_write(const DataBlock& message)
-throw(RuntimeException) {
+noexcept(false) {
    int size = message.getSize();
    const char* data =  message.getData();
    int r(0);
@@ -664,7 +635,7 @@ throw(RuntimeException) {
 // Devuelve 0 para indicar que el Socket se ha cerrado en el extremo remoto
 //----------------------------------------------------------------------------
 int comm::ClientSocket::do_read(const char* data, const int maxSize)
-throw(RuntimeException) {
+noexcept(false) {
    int result;
 
    do {
@@ -687,7 +658,7 @@ throw(RuntimeException) {
 }
 
 void comm::ClientSocket::forgot()
-throw() {
+{
    if (a_transport != NULL)
       a_transport->clear();
 
@@ -701,7 +672,7 @@ throw() {
 // (1) Recupera el tamano para verificar que se ha podido establecer la solicitud.
 //--------------------------------------------------------------------------------------
 void comm::ClientSocket::getSocketOptions()
-throw(RuntimeException) {
+noexcept(false) {
    if ((a_rcvBufferSize = comm::Communicator::getReceivingChunkSize()) == -1) {
       socklen_t l = sizeof(int);
       int fd = Socket::getfd();
@@ -715,7 +686,7 @@ throw(RuntimeException) {
 }
 
 int comm::ClientSocket::getTotalPendingBytes() const
-throw() {
+{
    // El nº de bytes pendientes de procesar será lo que queda en la cola I/O + los bytes que tenemos cargados en memoria
    // los bytes pendientes se obtiene al leer el chunk
    return a_pendingBytes.bytesToRead + getBufferSize();
@@ -723,12 +694,9 @@ throw() {
 
 
 string comm::ClientSocket::asString() const
-throw() {
+{
    string msg("comm::ClientSocket { ");
 
-   if (this == NULL)
-      return msg += " <freed> }";
-
    msg += Socket::asString();
    msg += functions::asText(" | RcvBufferSize: ", a_rcvBufferSize);
    msg += " bytes | Status: ";
@@ -745,14 +713,9 @@ throw() {
 }
 
 xml::Node* comm::ClientSocket::asXML(xml::Node* parent) const
-throw(RuntimeException) {
+noexcept(false) {
    xml::Node* clientSocket = parent->createChild("comm.ClientSocket");
 
-   if (this == NULL) {
-      clientSocket->createAttribute("Freed", "yes");
-      return clientSocket;
-   }
-
    Socket::asXML(clientSocket);
    clientSocket->createAttribute("Status", Status::asString(a_status));
    clientSocket->createAttribute("RcvBufferSize", a_rcvBufferSize);
@@ -774,7 +737,7 @@ throw(RuntimeException) {
 }
 
 string comm::ClientSocket::Status::asString(const int status)
-throw() {
+{
    string result;
 
    if (status == 0)