Skip to content

Commit 4eaf096

Browse files
Updated to size transfer from 1kb to 256kb
1 parent fa5a848 commit 4eaf096

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

mainwindow.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ MainWindow::MainWindow(QWidget *parent)
309309
break;
310310
}
311311
case 2: { // receiving raw file bytes
312-
const qint64 MAX_CHUNK = 1024;
312+
const qint64 MAX_CHUNK = CHUNK_SIZE;
313313
while (socket->bytesAvailable() > 0 && current_file_size < current_total_file_size) {
314314
qint64 remaining = current_total_file_size - current_file_size;
315315
qint64 toRead = qMin(MAX_CHUNK, remaining);
@@ -326,7 +326,7 @@ MainWindow::MainWindow(QWidget *parent)
326326
}
327327
// flush occasionally
328328
flushIndex++;
329-
if (flushIndex >= 25) {
329+
if (flushIndex >= 125) {
330330
current_file->flush();
331331
flushIndex = 0;
332332
}
@@ -579,9 +579,14 @@ void MainWindow::sendFile()
579579
}
580580
else
581581
{
582+
ui->sendButton->setEnabled(false);
583+
ui->pairButton->setEnabled(false);
584+
ui->MessageInput->setEnabled(false);
585+
scrollToBottom();
586+
582587
while (!current_file->atEnd())
583588
{
584-
QByteArray bytes = current_file->read(1024);
589+
QByteArray bytes = current_file->read(CHUNK_SIZE);
585590
current_file_size += bytes.size();
586591
bytesReceivedThisSecond += bytes.size();
587592
qint64 written = socket->write(bytes);
@@ -622,14 +627,18 @@ void MainWindow::sendFile()
622627
currentFileMessage->setStatus("File Transferred");
623628
currentFileMessage->setProgress(100);
624629

630+
ui->sendButton->setEnabled(true);
631+
ui->pairButton->setEnabled(true);
632+
ui->MessageInput->setEnabled(true);
633+
625634
}
626635
}
627636

628637
void MainWindow::sendFileChunk()
629638
{
630639
if (!sendingFile || !current_file) return;
631640

632-
const int chunkSize = 1024;
641+
const int chunkSize = CHUNK_SIZE;
633642
QByteArray bytes = current_file->read(chunkSize);
634643

635644
if (bytes.isEmpty()) {

mainwindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class MainWindow : public QMainWindow
4949

5050
bool hardSend = false;
5151

52+
qint64 CHUNK_SIZE = 1024*256;
53+
5254
private slots:
5355
void on_fileDialogButton_clicked();
5456
void on_connectButton_clicked();

0 commit comments

Comments
 (0)