Memory optimization in network remote.

This commit is contained in:
Andreas 2013-07-16 17:47:49 +02:00
parent 150345f2a6
commit 6c19acdf48
2 changed files with 13 additions and 11 deletions

View File

@ -556,8 +556,6 @@ void OutgoingDataCreator::SendSongs(const pb::remote::RequestDownloadSongs &requ
default:
break;
}
client->DisconnectClient(pb::remote::Server_Shutdown);
}
void OutgoingDataCreator::SendSingleSong(RemoteClient* client, const Song &song,
@ -574,8 +572,10 @@ void OutgoingDataCreator::SendSingleSong(RemoteClient* client, const Song &song,
QFile file(song.url().toLocalFile());
file.open(QIODevice::ReadOnly);
QByteArray data;
while (!file.atEnd()) {
QByteArray data = file.read(kFileChunkSize);
data = file.read(kFileChunkSize);
pb::remote::Message msg;
msg.set_type(pb::remote::SONG_FILE_CHUNK);
@ -586,7 +586,7 @@ void OutgoingDataCreator::SendSingleSong(RemoteClient* client, const Song &song,
chunk->set_file_count(song_count);
chunk->set_file_number(song_no);
chunk->set_size(file.size());
chunk->set_data(data.constData(), data.size());
chunk->set_data(data.data(), data.size());
if (chunk_number == 1) {
int i = app_->playlist_manager()->active()->current_row();
CreateSong(
@ -596,9 +596,11 @@ void OutgoingDataCreator::SendSingleSong(RemoteClient* client, const Song &song,
msg.set_version(msg.default_instance().version());
client->SendData(&msg);
data.clear();
chunk_number++;
}
file.close();
}

View File

@ -112,6 +112,11 @@ void RemoteClient::ParseMessage(const QByteArray &data) {
}
}
if (msg.type() == pb::remote::CONNECT) {
setDownloader(msg.request_connect().downloader());
qDebug() << "Downloader" << downloader_;
}
// Check if downloads are allowed
if (msg.type() == pb::remote::DOWNLOAD_SONGS && !allow_downloads_) {
DisconnectClient(pb::remote::Download_Forbidden);
@ -119,17 +124,12 @@ void RemoteClient::ParseMessage(const QByteArray &data) {
}
if (msg.type() == pb::remote::DISCONNECT) {
client_->flush();
client_->close();
qDebug() << client_->state();
client_->abort();
qDebug() << "Client disconnected";
return;
}
if (msg.type() == pb::remote::DOWNLOAD_SONGS) {
qDebug() << "Downloader";
setDownloader(true);
}
// Check if the client has sent the correct auth code
if (!authenticated_) {
DisconnectClient(pb::remote::Not_Authenticated);