void NetTester::sendData(){ QByteArray block; QDataStream out(&block, QIODevice::WriteOnly); out.setVersion(QDataStream::Qt_4_0);#define S 110000 //49148 char data[S]; for (int i=0; i<S; ++i) data[i]=i; out.writeBytes(data, S); QTcpSocket *clientConnection = tcpServer->nextPendingConnection(); connect(clientConnection, SIGNAL(disconnected()), clientConnection, SLOT(deleteLater())); clientConnection->write(block); clientConnection->disconnectFromHost();}
void NetTester::getData(){ QDataStream in(tcpSocket); in.setVersion(QDataStream::Qt_4_0); char *block; quint32 size; in.readBytes(block, size); delete [] block;}
// don't send more than 49152 per call to WSASendTo to avoid getting a WSAENOBUFS
A::readBytes(){ QDataStream ds( socket_ ); if ( packet_size_ == 0 ) { if ( socket_->bytesAvailable() < PacketSizeBytes ) return; ds >> packet_size_; } if ( socket_->bytesAvailable() < packet_size_ ) return; Packet packet; ds >> packet; if ( ds.status() != QDataStream::Ok ) { qWarning( "Packet corrupted!" ); socket_->deleteLater(); return; } packet_size_ = 0; process_packet( packet );}