本文整理汇总了C++中MessagePtr::serialize方法的典型用法代码示例。如果您正苦于以下问题:C++ MessagePtr::serialize方法的具体用法?C++ MessagePtr::serialize怎么用?C++ MessagePtr::serialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessagePtr
的用法示例。
在下文中一共展示了MessagePtr::serialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeData
void MessageQueue::writeData() {
if(_sendbuflen==0) {
// If send buffer is empty, serialize the next message in the queue.
// The snapshot upload queue has lower priority than the normal queue.
if(!_sendqueue.isEmpty()) {
// There are messages in the higher priority queue, send one
MessagePtr msg = _sendqueue.dequeue();
_sendbuflen = msg->serialize(_sendbuffer);
if(msg->type() == protocol::MSG_DISCONNECT) {
// Automatically disconnect after Disconnect notification is sent
_closeWhenReady = true;
_sendqueue.clear();
}
} else if(!_snapshot_send.isEmpty()) {
// When the main send queue is empty, messages from the snapshot queue are sent
SnapshotMode mode(SnapshotMode::SNAPSHOT);
_sendbuflen = mode.serialize(_sendbuffer);
_sendbuflen += _snapshot_send.takeFirst()->serialize(_sendbuffer + _sendbuflen);
}
}
if(_sentcount < _sendbuflen) {
int sent = _socket->write(_sendbuffer+_sentcount, _sendbuflen-_sentcount);
if(sent<0) {
// Error
emit socketError(_socket->errorString());
return;
}
_sentcount += sent;
if(_sentcount == _sendbuflen) {
_sendbuflen=0;
_sentcount=0;
if(_closeWhenReady) {
_socket->disconnectFromHost();
} else {
writeData();
}
}
}
}