Ejemplo n.º 1
0
void LocalNode::_removeConnection( ConnectionPtr connection )
{
    EQASSERT( connection.isValid( ));

    _incoming.removeConnection( connection );

    void* buffer( 0 );
    uint64_t bytes( 0 );
    connection->getRecvData( &buffer, &bytes );
    EQASSERTINFO( !connection->isConnected() || buffer, *connection );
    EQASSERT( !buffer || bytes == sizeof( uint64_t ));

    if( !connection->isClosed( ))
        connection->close(); // cancels pending IO's
    delete reinterpret_cast< uint64_t* >( buffer );
}
Ejemplo n.º 2
0
RouterIPtr
SessionRouterI::getRouterImpl(const ConnectionPtr& connection, const Ice::Identity& id, bool close) const
{
    if(_destroy)
    {
        throw ObjectNotExistException(__FILE__, __LINE__);
    }

    map<ConnectionPtr, RouterIPtr>& routers = const_cast<map<ConnectionPtr, RouterIPtr>&>(_routersByConnection);

    if(_routersByConnectionHint != routers.end() && _routersByConnectionHint->first == connection)
    {
        _routersByConnectionHint->second->updateTimestamp();
        return _routersByConnectionHint->second;
    }

    map<ConnectionPtr, RouterIPtr>::iterator p = routers.find(connection);

    if(p != routers.end())
    {
        _routersByConnectionHint = p;
        p->second->updateTimestamp();
        return p->second;
    }
    else if(close)
    {
        if(_rejectTraceLevel >= 1)
        {
            Trace out(_instance->logger(), "Glacier2");
            out << "rejecting request, no session is associated with the connection.\n";
            out << "identity: " << identityToString(id);
        }
        connection->close(ICE_SCOPED_ENUM(ConnectionClose, Forcefully));
        throw ObjectNotExistException(__FILE__, __LINE__);
    }
    return 0;
}
Ejemplo n.º 3
0
void WtReply::send(const std::string& text, CallbackFunction callBack,
		   bool responseComplete)
{
  ConnectionPtr connection = getConnection();

  if (!connection)
    return;

  fetchMoreDataCallback_ = callBack;

  bool webSocket = request().webSocketVersion >= 0;

  if (webSocket) {
    if (!sendingMessages_) {
      /*
       * This finishes the server handshake. For 00-protocol, we copy
       * the computed handshake nonce in the output.
       */
      nextCout_.assign(cin_mem_.str());

      sendingMessages_ = true;
    } else {
      /*
       * This should be sent as a websocket message.
       */
      if (text.empty()) {
	LOG_DEBUG("ws: closed by app");

	/*
	 * FIXME: send a close frame
	 */
	connection->close();
	return;
      }

      LOG_DEBUG("ws: sending a message, length = " << (long long)text.length());

      nextCout_.clear();

      switch (request().webSocketVersion) {
      case 0:
	nextCout_ += (char)0;
	nextCout_ += text;
	nextCout_ += (char)0xFF;

	break;
      case 7:
      case 8:
      case 13:
	{
	  nextCout_ += (char)0x81;

	  std::size_t payloadLength = text.length();

	  if (payloadLength < 126)
	    nextCout_ += (char)payloadLength;
	  else if (payloadLength < (1 << 16)) {
	    nextCout_ += (char)126;
	    nextCout_ += (char)(payloadLength >> 8);
	    nextCout_ += (char)(payloadLength);
	  } else {
	    nextCout_ += (char)127;
	    for (unsigned i = 0; i < 8; ++i)
	      nextCout_ += (char)(payloadLength >> ((7-i) * 8));
	  }

	  nextCout_ += text;
	}
	break;
      default:
	LOG_ERROR("ws: encoding for version " <<
		  request().webSocketVersion << " is not implemented");
	connection->close();
	return;
      }
    }