{
if (frame.isControlFrame())
{
- Q_EMIT frameReceived(frame.getOpCode(), frame.getPayload(), true);
+ Q_EMIT controlFrameReceived(frame.getOpCode(), frame.getPayload());
isDone = true; //exit the loop after a control frame, so we can get a chance to close the socket if necessary
}
- else //we have a dataframe
+ else //we have a dataframe; opcode can be OC_CONTINUE, OC_TEXT or OC_BINARY
{
if (!m_isFragmented && frame.isContinuationFrame())
{
if (m_isFragmented && frame.isDataFrame() && !frame.isContinuationFrame())
{
clear();
- Q_EMIT errorEncountered(WebSocketProtocol::CC_PROTOCOL_ERROR, "All data frames after the initial data frame must have opcode 0");
+ Q_EMIT errorEncountered(WebSocketProtocol::CC_PROTOCOL_ERROR, "All data frames after the initial data frame must have opcode 0 (continuation).");
return;
}
if (!frame.isContinuationFrame())
else
{
m_textMessage.append(frameTxt);
+ Q_EMIT textFrameReceived(frameTxt, frame.isFinalFrame());
}
}
else
{
m_binaryMessage.append(frame.getPayload());
+ Q_EMIT binaryFrameReceived(frame.getPayload(), frame.isFinalFrame());
}
- Q_EMIT frameReceived(m_opCode, frame.getPayload(), frame.isFinalFrame());
if (frame.isFinalFrame())
{
connect(pTcpSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(processStateChanged(QAbstractSocket::SocketState)));
connect(pTcpSocket, SIGNAL(readyRead()), this, SLOT(processData()));
- connect(&m_dataProcessor, SIGNAL(frameReceived(WebSocketProtocol::OpCode, QByteArray, bool)), this, SLOT(processFrame(WebSocketProtocol::OpCode, QByteArray, bool)));
+ connect(&m_dataProcessor, SIGNAL(controlFrameReceived(WebSocketProtocol::OpCode, QByteArray)), this, SLOT(processControlFrame(WebSocketProtocol::OpCode, QByteArray)));
+ connect(&m_dataProcessor, SIGNAL(textFrameReceived(QString,bool)), this, SIGNAL(textFrameReceived(QString,bool)));
+ connect(&m_dataProcessor, SIGNAL(binaryFrameReceived(QByteArray,bool)), this, SIGNAL(binaryFrameReceived(QByteArray,bool)));
connect(&m_dataProcessor, SIGNAL(binaryMessageReceived(QByteArray)), this, SIGNAL(binaryMessageReceived(QByteArray)));
connect(&m_dataProcessor, SIGNAL(textMessageReceived(QString)), this, SIGNAL(textMessageReceived(QString)));
connect(&m_dataProcessor, SIGNAL(errorEncountered(WebSocketProtocol::CloseCode,QString)), this, SLOT(close(WebSocketProtocol::CloseCode,QString)));
disconnect(pTcpSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(processStateChanged(QAbstractSocket::SocketState)));
disconnect(pTcpSocket, SIGNAL(readyRead()), this, SLOT(processData()));
}
- disconnect(&m_dataProcessor, SIGNAL(frameReceived(WebSocketProtocol::OpCode,QByteArray,bool)), this, SLOT(processFrame(WebSocketProtocol::OpCode,QByteArray,bool)));
+ disconnect(&m_dataProcessor, SIGNAL(controlFrameReceived(WebSocketProtocol::OpCode,QByteArray)), this, SLOT(processControlFrame(WebSocketProtocol::OpCode,QByteArray)));
+ disconnect(&m_dataProcessor, SIGNAL(textFrameReceived(QString,bool)), this, SIGNAL(textFrameReceived(QString,bool)));
+ disconnect(&m_dataProcessor, SIGNAL(binaryFrameReceived(QByteArray,bool)), this, SIGNAL(binaryFrameReceived(QByteArray,bool)));
disconnect(&m_dataProcessor, SIGNAL(binaryMessageReceived(QByteArray)), this, SIGNAL(binaryMessageReceived(QByteArray)));
disconnect(&m_dataProcessor, SIGNAL(textMessageReceived(QString)), this, SIGNAL(textMessageReceived(QString)));
disconnect(&m_dataProcessor, SIGNAL(errorEncountered(WebSocketProtocol::CloseCode,QString)), this, SLOT(close(WebSocketProtocol::CloseCode,QString)));
}
}
-//TODO: implement separate signals for textframereceived and binaryframereceived in dataprocessor
-//in that way the UTF8 can be sent as is from within the dataprocessor
/*!
\internal
*/
-void WebSocket::processFrame(WebSocketProtocol::OpCode opCode, QByteArray frame, bool isLastFrame)
+void WebSocket::processControlFrame(WebSocketProtocol::OpCode opCode, QByteArray frame)
{
switch (opCode)
{
- case WebSocketProtocol::OC_BINARY:
- {
- Q_EMIT binaryFrameReceived(frame, isLastFrame);
- break;
- }
- case WebSocketProtocol::OC_TEXT:
- {
- Q_EMIT textFrameReceived(QString::fromUtf8(frame.constData(), frame.length()), isLastFrame);
- break;
- }
case WebSocketProtocol::OC_PING:
{
quint32 maskingKey = 0;
break;
}
case WebSocketProtocol::OC_CONTINUE:
+ case WebSocketProtocol::OC_BINARY:
+ case WebSocketProtocol::OC_TEXT:
case WebSocketProtocol::OC_RESERVED_3:
case WebSocketProtocol::OC_RESERVED_4:
case WebSocketProtocol::OC_RESERVED_5: