本文整理汇总了C++中QTcpSocket::peek方法的典型用法代码示例。如果您正苦于以下问题:C++ QTcpSocket::peek方法的具体用法?C++ QTcpSocket::peek怎么用?C++ QTcpSocket::peek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTcpSocket
的用法示例。
在下文中一共展示了QTcpSocket::peek方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onReadyRead
void Graph::onReadyRead()
{
qDebug() << "Graph::readPriborData()";
QTcpSocket *socket = (QTcpSocket *)sender();
const size_t header_size = sizeof(ident_t) + sizeof(int);
while(socket->bytesAvailable() >= header_size)
{
char buf[header_size];
socket->peek(buf, sizeof(buf));
ident_t id = *reinterpret_cast<ident_t *>(buf);
int nvals = *(int *)((ident_t *)buf + 1);
qDebug() << " " << id << nvals << socket->bytesAvailable();
if(socket->bytesAvailable() < nvals*sizeof(Value) + sizeof(id) + sizeof(nvals)) break;
socket->read((char *)&id, sizeof(id));
socket->read((char *)&nvals, sizeof(nvals));
QByteArray data = socket->read(nvals*sizeof(Value));
if((size_t)data.size() < nvals*sizeof(Value)) break;
const Value *v = (const Value *)data.constData();
QVector<Value> vals(nvals);
qCopy(v, v + nvals, vals.begin());
for(Stats::iterator s = stats.begin(); s != stats.end(); ++s)
{
Sourcer *sourcer = s.key();
if(sourcer->ident() == id)
{
if(sourcer->getReliability() == 1)
vals.append(Value(QDateTime::currentDateTime().toTime_t(), sourcer->value()));
s->resize(w, Stat());
fillStats(*s, currentInterval(), vals);
update();
}
}
}
}
示例2: incomingData
void SatelliteServer::incomingData( QObject *client )
{
QTcpSocket *socket = static_cast<QTcpSocket*>(client);
while( socket->bytesAvailable() > SATELLITE_PKGINFO_HEADER_SIZE )
{
SATELLITE_PKGINFO_HEADER_TYPE header( 0 );
socket->peek( (char*)(&header), SATELLITE_PKGINFO_HEADER_SIZE );
header = qFromBigEndian( header );
if( (header >> 32) != SATELLITE_PKGINFO_MAGIC_VALUE )
{
/* invalid data, flush */
socket->readAll();
#if SATELLITESERVER_DEBUG
emit debug( "s:got bad data, flushing" );
#endif
break;
}
qint64 datasize = (header & 0xFFFFFFFF) +
SATELLITE_PKGINFO_CHECKSUM_SIZE + SATELLITE_PKGINFO_HEADER_SIZE;
if( socket->bytesAvailable() < datasize )
{
/* buffer incomplete, let the try at next signal */
#if SATELLITESERVER_DEBUG
emit debug( "s:got incomplete data" );
#endif
break;
}
QByteArray msg( socket->read( datasize ) );
#if SATELLITESERVER_DEBUG
/* for debugging show raw message as hex dump */
emit debug( QByteArray("s:from client: ") + msg.toHex() );
#endif
for( int i = 0; i < mClientConnections.count(); i++ )
{
QTcpSocket *current = mClientConnections.at(i);
if( current && (client != current) )
{
current->write( msg );
}
}
}
}