void ServerConnection::queueFrame(quint32 frameNumber, QByteArray frameData)
{
    Frame f(frameNumber, frameData);

    // append to queue of this connection
    m_frameQueue.append(f);

    if( m_frameNumbersInFlight.size() < MAX_FRAMES_IN_FLIGHT )
    {
        sendData();
    }

    // we start dropping frames when the queue is at MAX_FRAME_QUEUE
    // unless we are set to lossless, then we
    // give the server a signal to throttle
    if(m_frameQueue.size() > MAX_FRAME_QUEUE)
    {
        if( m_lossless )
        {
            if( !m_waiting )
            {
                m_waiting = true;
                emit waitingOnClient(this, m_waiting);
            }
        }
        else
        {
            // drop the oldest frame
            Frame f = m_frameQueue.takeFirst();
            qDebug() << "Connection " << m_tcpSocket->peerAddress().toString() << ":"
                     << m_tcpSocket->peerPort() << " dropped frame " << f.serial;
        }
    }
    emit scheduleSend();
}
void ServerConnection::queueFrame(quint32 frameNumber, QByteArray frameData)
{
    if( m_tcpSocket == 0 )
        return;

    Frame f(frameNumber, frameData);

    // append to queue of this connection
    m_frameQueue.append(f);

    if( m_frameNumbersInFlight.size() < m_maxFramesInFlight )
    {
        sendData();
    }

    // we start dropping frames when the queue is at m_maxFramesInQueue
    // unless we are set to lossless, then we
    // give the server a signal to throttle

        // check if they are too old
        /*if(m_frameQueue.size() > m_maxFramesInQueue)
        {
            while( m_frameQueue.size() > 0 )
            {
                const Frame& f = m_frameQueue.first();

                if( f.time.elapsed() < 5000 )
                        break;

                qWarning() << tr("Frame %1 timed out after %2 msecs.").arg(f.serial).arg(f.time.elapsed());
                m_frameQueue.removeFirst();
            }
        }*/

    if(m_frameQueue.size() > m_maxFramesInQueue)
    {
        if( m_lossless )
        {
            if( !m_waiting )
            {
                m_waiting = true;
                emit waitingOnClient(this, m_waiting);
            }
        }
        else
        {
            // drop the oldest frame
            Frame f = m_frameQueue.takeFirst();
			if (getAcknowledgeNeeded())
            {
				qDebug() << "Connection " << m_tcpSocket->peerAddress().toString() << ":"
                     << m_tcpSocket->peerPort() << " dropped frame " << f.serial;
			}
        }
    }
    emit scheduleSend();
}
ServerConnection::ServerConnection(int socketDescriptor) :
    QObject(0),
    m_tcpSocket(0),
    m_socketDescriptor(socketDescriptor),
    m_errorString("No error string set"),
    m_waiting(false),
    m_lossless(false),
    m_blockSize(0)
{
    connect( this, SIGNAL( scheduleSend()), this, SLOT(sendData()), Qt::QueuedConnection );
}
ServerConnection::ServerConnection(int socketDescriptor, bool lossless, int maxFrameQueue, int maxFramesInFlight) :
    QObject(0),
    m_tcpSocket(0),
    m_socketDescriptor(socketDescriptor),
    m_errorString("no error"),
    m_waiting(false),
    m_lossless(lossless),
    m_maxFramesInQueue(maxFrameQueue),
    m_maxFramesInFlight(maxFramesInFlight),
    m_blockSize(0)
{
    connect( this, SIGNAL( scheduleSend()), this, SLOT(sendData()), Qt::QueuedConnection );
}
Exemple #5
0
int TCPConnectionHandler::open (void * )
{
  int result = inherited::open ();

  if (!serverSide_)
    {
      ACE_Message_Block *buffer = new ACE_Message_Block (TCPBytesToSend);
      char *bufferData = buffer->wr_ptr ();
      int i;

      for (i = buffer->size () - 1; i >= 0; --i)
        bufferData[ i ] = static_cast< char > (i);
      buffer->wr_ptr (buffer->size ());
      if (0 != (scheduleSend (buffer)))
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Cannot schedule initial send\n")),
                          -1);
    }

  return result;
}
Exemple #6
0
int TCPConnectionHandler::handle_input (ACE_HANDLE handle)
{
  ACE_UNUSED_ARG (handle);
  ACE_Message_Block *buffer = new ACE_Message_Block (TCPBytesToSend);
  int bytesReceived = peer_.recv (buffer->wr_ptr (), buffer->space ());

  if (bytesReceived > 0)
    {
      totalReceived_ += bytesReceived;
      if (serverSide_ || --pingsNo_ > 0) // echo received buffer
        {
          buffer->wr_ptr (bytesReceived);
          int result = scheduleSend (buffer);
          if (0 > result)
            ACE_ERROR_RETURN ((LM_ERROR,
                               ACE_TEXT (" (%P) %p\n"),
                               ACE_TEXT ("Cannot schedule TCP reply")),
                              -1);
        }
      else
        buffer->release ();

      return 0;
    }

  if (errno != EWOULDBLOCK)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" (%P:%p (%d)\n"),
                       ACE_TEXT ("TCPConnectionHandler::handle_input call with no data on handle "), handle),
                      -1);

  ACE_ERROR ((LM_WARNING,
              ACE_TEXT (" (%P:%p (%d)\n"),
              ACE_TEXT ("TCPConnectionHandler::handle_input call with no data on handle "), handle));

  return 0;
}