Ejemplo n.º 1
0
void SIPTCPListener::handleAccept(const boost::system::error_code& e, OSS_HANDLE userData)
{
  if (!e)
  {
    OSS_LOG_DEBUG("SIPTCPListener::handleAccept STARTING new connection");
    _pNewConnection->setExternalAddress(_externalAddress);
    _connectionManager.start(_pNewConnection);

    if (_acceptor.is_open())
    {
      OSS_LOG_DEBUG("SIPTCPListener::handleAccept RESTARTING async accept loop");
      _pNewConnection.reset(new SIPTCPConnection(*_pIoService, _connectionManager));
      _acceptor.async_accept(dynamic_cast<SIPTCPConnection*>(_pNewConnection.get())->socket(),
        boost::bind(&SIPTCPListener::handleAccept, this,
          boost::asio::placeholders::error, userData));
    }
    else
    {
      OSS_LOG_DEBUG("SIPTCPListener::handleAccept ABORTING async accept loop");
    }
  }
  else
  {
    OSS_LOG_DEBUG("SIPTCPListener::handleAccept INVOKED with exception " << e.message());
  }
}
Ejemplo n.º 2
0
void SIPWebSocketConnection::ServerReadWriteHandler::on_error(websocketpp::server::connection_ptr pConnection)
{
    //TODO: do proper error check here
    OSS_LOG_DEBUG("SIPWebSocketConnection::ServerReadWriteHandler::on_error reason:" << pConnection->get_fail_reason());

    std::string empty;
    _rConnection.handleRead(boost::asio::error::connection_aborted, 0, &empty);
}
Ejemplo n.º 3
0
FramedTcpListener::FramedTcpListener() :
  _ioService(),
  _acceptor(_ioService),
  _resolver(_ioService),
  _inactivityThreashold(180)
{
  OSS_LOG_DEBUG( "FramedTcpListener CREATED");
}
Ejemplo n.º 4
0
void EndpointListener::monitorEvents()
{
  OSS_LOG_NOTICE("EndpointListener::monitorEvents( " << _endpointName << " ) - STARTED processing events");
  handleStart();
  while(!_isTerminating)
  {
    SIPMessage::Ptr pRequest;
    _eventQueue.dequeue(pRequest);
    if (pRequest)
    {
      OSS_LOG_DEBUG(pRequest->createContextId(true) << "EndpointListener::monitorEvents( " << _endpointName << " ) - processing event " << pRequest->startLine());
      onHandleEvent(pRequest);
    }
    else
    {
      OSS_LOG_DEBUG("EndpointListener::monitorEvents( " << _endpointName << " ) - dropping NULL event");
    }
  }
  handleStop();
  OSS_LOG_NOTICE("EndpointListener::monitorEvents( " << _endpointName << " ) TERMINATED");
}
Ejemplo n.º 5
0
void EndpointListener::dispatchMessage(const SIPMessage::Ptr& pRequest)
{
  if (_dispatch)
  {
    OSS_LOG_DEBUG(pRequest->createContextId(true) << "EndpointListener::dispatchMessage( " << pRequest->startLine() << " )");
    pRequest->setProperty(OSS::PropertyMap::PROP_EndpointName, _endpointName);
    pRequest->commitData();
    _dispatch(pRequest, _pConnection);
  }
  else
  {
    OSS_LOG_ERROR(pRequest->createContextId(true) << "EndpointListener::dispatchMessage( NULL )");
  }
}
Ejemplo n.º 6
0
void SIPWebSocketConnection::ServerReadWriteHandler::on_pong_timeout(websocketpp::server::connection_ptr pConnection,std::string)
{
    OSS_LOG_DEBUG("SIPWebSocketConnection::ServerReadWriteHandler::on_pong_timeout INVOKED");
}
Ejemplo n.º 7
0
void SIPWebSocketConnection::ServerReadWriteHandler::on_pong(websocketpp::server::connection_ptr pConnection)
{
    OSS_LOG_DEBUG("SIPWebSocketConnection::ServerReadWriteHandler::on_pong INVOKED");
}
Ejemplo n.º 8
0
bool SIPWebSocketConnection::ServerReadWriteHandler::on_ping(websocketpp::server::connection_ptr pConnection)
{
    OSS_LOG_DEBUG("SIPWebSocketConnection::ServerReadWriteHandler::on_ping INVOKED");
    return true;
}
Ejemplo n.º 9
0
void SIPWebSocketConnection::handleRead(const boost::system::error_code& e, std::size_t bytes_transferred, OSS_HANDLE userData)
/// Handle completion of a read operation.
{
    if (e || bytes_transferred <=0)
    {
        OSS_LOG_DEBUG("SIPWebSocketConnection::handleRead Exception " << e.message());

        if (++_readExceptionCount >= 5)
        {
            OSS_LOG_ERROR("SIPWebSocketConnection::handleRead has reached maximum exception count.  Bailing out.");
            boost::system::error_code ignored_ec;

            _connectionManager.stop(shared_from_this());
        }
    }

    OSS_LOG_DEBUG("SIPWebSocketConnection::handleRead STARTING new connection");
    std::string* buffer = reinterpret_cast<std::string*>(userData);

    //
    // set the last read address
    //
    if (!_lastReadAddress.isValid())
    {
        boost::system::error_code ec;

        EndPoint ep = _pServerConnection->get_raw_socket().remote_endpoint(ec);
        if (!ec)
        {
            boost::asio::ip::address ip = ep.address();
            _lastReadAddress = OSS::IPAddress(ip.to_string(), ep.port());
        }
        else
        {
            OSS_LOG_WARNING("SIPWebSocketConnection::handleRead() Exception " << ec.message());
        }
    }

    //
    // Reset the read exception count
    //
    _readExceptionCount = 0;

    _bytesRead =  bytes_transferred;
    if (!_pRequest)
    {
        _pRequest = SIPMessage::Ptr(new SIPMessage());
    }

    boost::tribool result;
    const char* begin = buffer->data();
    const char* end = buffer->data() + bytes_transferred;

    boost::tuple<boost::tribool, const char*> ret =  _pRequest->consume(begin, end);
    result = ret.get<0>();
    const char* tail = ret.get<1>();

    if (result)
    {
        //
        // Message has been read in full
        //
        _pDispatch->onReceivedMessage(_pRequest->shared_from_this(), shared_from_this());
        if (tail >= end)
        {
            //
            // The end of the SIPMessage is reached so we can simply reset the
            // request buffer and start the read operation all over again
            //
            _pRequest.reset();

            //
            // We are done
            //
            return;
        }
        else
        {
            //
            // This should not happen as there is one full message per read.
            // The tail is within the range of the end of the read buffer.
            //
            OSS_ASSERT(false);
        }
    }
    else if (!result)
    {
        _pRequest.reset();
    }
    else
    {
        //
        // This should not happen as there is one full message per read.
        // Partial message?
        //
        OSS_ASSERT(false);
    }
}
Ejemplo n.º 10
0
FramedTcpListener::~FramedTcpListener()
{
  OSS_LOG_DEBUG( "FramedTcpListener DESTROYED");
}