本文整理汇总了C++中QTcpSocket::bytesToWrite方法的典型用法代码示例。如果您正苦于以下问题:C++ QTcpSocket::bytesToWrite方法的具体用法?C++ QTcpSocket::bytesToWrite怎么用?C++ QTcpSocket::bytesToWrite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTcpSocket
的用法示例。
在下文中一共展示了QTcpSocket::bytesToWrite方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void FileTransfertUpload::onSocketWritten()
{
QTcpSocket *socket = dynamic_cast<QTcpSocket*>(sender());
if (socket->bytesToWrite() == 0) {
socket->close();
socket->deleteLater();
_completed++;
check_nbr();
}
}
示例2: setEclipseProperty
void setEclipseProperty(const Matrix& propertyFrames, const QString &hostName, quint16 port,
const qint64& caseId, QString propertyName, const int32NDArray& requestedTimeSteps, QString porosityModel)
{
QTcpSocket socket;
socket.connectToHost(hostName, port);
if (!socket.waitForConnected(riOctavePlugin::connectTimeOutMilliSecs))
{
error((("Connection: ") + socket.errorString()).toLatin1().data());
return;
}
QDataStream socketStream(&socket);
socketStream.setVersion(riOctavePlugin::qtDataStreamVersion);
// Create command as a string with arguments , and send it:
QString command;
command += "SetActiveCellProperty " + QString::number(caseId) + " " + propertyName + " " + porosityModel;
for (int i = 0; i < requestedTimeSteps.numel(); ++i)
{
if (i == 0) command += " ";
command += QString::number(static_cast<int>(requestedTimeSteps.elem(i)) - 1); // To make the index 0-based
if (i != requestedTimeSteps.numel() -1) command += " ";
}
QByteArray cmdBytes = command.toLatin1();
socketStream << (qint64)(cmdBytes.size());
socket.write(cmdBytes);
// Write property data header
dim_vector mxDims = propertyFrames.dims();
qint64 cellCount = mxDims.elem(0);
qint64 timeStepCount = mxDims.elem(1);
qint64 timeStepByteCount = cellCount * sizeof(double);
socketStream << (qint64)(timeStepCount);
socketStream << (qint64)timeStepByteCount;
const double* internalData = propertyFrames.fortran_vec();
QStringList errorMessages;
if (!RiaSocketDataTransfer::writeBlockDataToSocket(&socket, (const char *)internalData, timeStepByteCount*timeStepCount, errorMessages))
{
for (int i = 0; i < errorMessages.size(); i++)
{
octave_stdout << errorMessages[i].toStdString();
}
return;
}
QString tmp = QString("riSetActiveCellProperty : Wrote %1").arg(propertyName);
if (caseId == -1)
{
tmp += QString(" to current case.");
}
else
{
tmp += QString(" to case with Id = %1.").arg(caseId);
}
octave_stdout << tmp.toStdString() << " Active Cells : " << cellCount << " Time steps : " << timeStepCount << std::endl;
while(socket.bytesToWrite() && socket.state() == QAbstractSocket::ConnectedState)
{
// octave_stdout << "Bytes to write: " << socket.bytesToWrite() << std::endl;
socket.waitForBytesWritten(riOctavePlugin::shortTimeOutMilliSecs);
OCTAVE_QUIT;
}
//octave_stdout << " Socket write completed" << std::endl;
if (socket.bytesToWrite() && socket.state() != QAbstractSocket::ConnectedState)
{
error("riSetActiveCellProperty : ResInsight refused to accept the data. Maybe the dimensions or porosity model is wrong");
}
#ifdef WIN32
// TODO: Due to synchronization issues seen on Windows 10, it is required to do a sleep here to be able to catch disconnect
// signals from the socket. No sleep causes the server to hang.
Sleep(100);
#endif //WIN32
return;
}
示例3: run
void FileServerThread::run() //TODO: use mutexes
{
QString filename;
QString ID;
QFile file;
QTcpSocket socket;
socket.setSocketDescriptor (m_descriptor);
while (!m_doQuit) {
m_status = Waiting;
while (!socket.bytesAvailable() && !m_doQuit) {
socket.waitForReadyRead();
}
if (m_doQuit)
break;
QString data (socket.readAll());
if (!Kapotah::TransferManager::instance()->pathForId (data).isEmpty()) {
setStatus(PreparingToSend);
ID = data;
filename = Kapotah::TransferManager::instance()->pathForId (data);
file.setFileName (filename);
if (!file.open (QIODevice::ReadOnly)) {
setStatus(ErrorFileNotFound);
break;
}
socket.write ("OK");
socket.waitForBytesWritten();
emit startedTransfer (ID);
setStatus(Sending);
while (!file.atEnd() && !m_doQuit) {
if (socket.state() != QTcpSocket::ConnectedState) {
emit finishedTransfer (ID);
setStatus(Finished);
break;
}
socket.write (file.read (s_bytesPerBlock));
socket.waitForBytesWritten();
while (socket.bytesToWrite())
socket.flush();
emit transferProgress (ID, file.pos() / file.size() *100);
}
file.close();
if (m_doQuit) {
setStatus(Canceled);
emit canceledTransfer(ID);
socket.disconnectFromHost();
} else {
setStatus(Finished);
emit finishedTransfer (ID);
}
socket.waitForDisconnected ();
break;
} else {
setStatus(ErrorIDNotFound);
emit transferNotFound(ID);
break;
}
deleteLater();
}
}