当前位置: 首页>>代码示例>>C++>>正文


C++ QTcpSocket::peek方法代码示例

本文整理汇总了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();
			}
		}
	}
}
开发者ID:obrpasha,项目名称:votlis_krizh_gaz_nas,代码行数:34,代码来源:graph.cpp

示例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 );
         }
      }
   }
}
开发者ID:SvOlli,项目名称:SLART,代码行数:45,代码来源:SatelliteServer.cpp


注:本文中的QTcpSocket::peek方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。