forked from aksenoff/quelea-im
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage.cpp
More file actions
42 lines (36 loc) · 971 Bytes
/
message.cpp
File metadata and controls
42 lines (36 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "message.h"
Message::operator int() const
{
return code;
}
const QString& Message::getText() const
{
return text;
}
Message::Message(unsigned char c, QString s)
: code(c), text(s)
{
}
Message::Message(QTcpSocket* clientSocket)
{
QDataStream incomingStream(clientSocket);
incomingStream.setVersion(QDataStream::Qt_4_6);
quint64 fullSize = 0;
incomingStream >> fullSize;
while(quint64(clientSocket->bytesAvailable()) < fullSize)
clientSocket->waitForReadyRead(500);
incomingStream >> code >> text;
}
void Message::send(QTcpSocket* socket) const
{
QByteArray arrBlock;
QDataStream out(&arrBlock, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_6);
out << quint64(0) << code << text;
out.device()->seek(0);
out << quint64(arrBlock.size() - sizeof(quint64));
socket->write(arrBlock);
}
void Message::sendFile(QTcpSocket* socket) const
{
}