예제 #1
0
파일: Server.cpp 프로젝트: ghostec/White2
void Server::readyRead()
{
  QTcpSocket* socket = static_cast<QTcpSocket*>(sender());
  QByteArray* buffer = buffers.value(socket);
  qint32* s = sizes.value(socket);
  qint32 size = *s;
  while(socket->bytesAvailable() > 0) {
    buffer->append(socket->readAll());
    while((size == 0 && buffer->size() >= 4) || (size > 0 && buffer->size() >= size))
    {
      if(size == 0 && buffer->size() >= 4)
      {
        size = ArrayToInt(buffer->mid(0, 4));
        *s = size;
        buffer->remove(0, 4);
      }
      if(size > 0 && buffer->size() >= size)
      {
        QByteArray data = buffer->mid(0, size);
        buffer->remove(0, size);
        size = 0;
        *s = size;
        emit dataReceived(socket, data);
      }
    }
  }
}
예제 #2
0
void SCIpcClient::readIDEData() {
    mIpcData.append(mSocket->readAll());

    // After we have put the data in the buffer, process it    
    int avail = mIpcData.length();
    do {
        if (mReadSize == 0 && avail > 4){
            mReadSize = ArrayToInt(mIpcData.left(4));
            mIpcData.remove(0, 4);
            avail -= 4;
        }

        if (mReadSize > 0 && avail >= mReadSize){
            QByteArray baReceived(mIpcData.left(mReadSize));
            mIpcData.remove(0, mReadSize);
            mReadSize = 0;
            avail -= mReadSize;

            QDataStream in(baReceived);
            in.setVersion(QDataStream::Qt_4_6);
            QString selector;
            QVariantList argList;
            in >> selector;
            if (in.status() != QDataStream::Ok)
                return;

            in >> argList;
            if (in.status() != QDataStream::Ok)
                return;

            onResponse(selector, argList);
        }
    } while ((mReadSize == 0 && avail > 4) || (mReadSize > 0 && avail > mReadSize));
}
예제 #3
0
파일: Message.cpp 프로젝트: ghostec/White2
QByteArray readMessage(QTcpSocket* socket, QByteArray* buffer, qint32* s) {
  qint32 size = *s;
  while(socket->bytesAvailable() > 0) {
    buffer->append(socket->readAll());
    while((size == 0 && buffer->size() >= 4) || (size > 0 && buffer->size() >= size)) //While can process data, process it
    {
      if(size == 0 && buffer->size() >= 4) //if size of data has received completely, then store it on our global variable
      {
        size = ArrayToInt(buffer->mid(0, 4));
        *s = size;
        buffer->remove(0, 4);
      }
      if(size > 0 && buffer->size() >= size) // If data has received completely, then emit our SIGNAL with the data
      {
        QByteArray data = buffer->mid(0, size);
        buffer->remove(0, size);
        size = 0;
        *s = size;
        return data;
      }
    }
  }
  return QByteArray();
}
예제 #4
0
void ServerNetwork::readyRead() {
	QTcpSocket *socket = static_cast<QTcpSocket*>(sender());
	u32 clientId = clientManager->GetClient(socket);
	QByteArray *buffer = buffers.value(socket);
	qint32 size = socket->bytesAvailable();

	while (socket->bytesAvailable() > 0) {
		buffer->append(socket->readAll());

		while ((size == 0 && buffer->size() >= 4) || (size > 0 && buffer->size() >= size)) {
			if (size == 0 && buffer->size() >= 4) {
				size = ArrayToInt(buffer->mid(0, 4));
				buffer->remove(0, 4);
			}
			if (size > 0 && buffer->size() >= size) {
				QByteArray data = buffer->mid(0, size);
				buffer->remove(0, size);
				size = 0;

				emit DataReceived(data, clientId);
			}
		}
	}
}