mirror of
https://github.com/zhaojh329/rtty.git
synced 2026-02-27 09:53:17 +08:00
Bug: Failed to upload file which size is 0
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
This commit is contained in:
+15
-10
@@ -270,12 +270,6 @@ void parse_file_msg(struct file_context *ctx, int type, struct buffer *data, int
|
||||
start_download_file(ctx, data, len);
|
||||
break;
|
||||
case RTTY_FILE_MSG_DATA:
|
||||
if (len == 0) {
|
||||
close(ctx->fd);
|
||||
ctx->fd = -1;
|
||||
ctx->busy = false;
|
||||
return;
|
||||
}
|
||||
if (ctx->fd > -1) {
|
||||
buffer_pull_to_fd(data, ctx->fd, len);
|
||||
ctx->remain_size -= len;
|
||||
@@ -283,6 +277,12 @@ void parse_file_msg(struct file_context *ctx, int type, struct buffer *data, int
|
||||
} else {
|
||||
buffer_pull(data, NULL, len);
|
||||
}
|
||||
|
||||
if (len == 0 && ctx->fd > -1) {
|
||||
close(ctx->fd);
|
||||
ctx->fd = -1;
|
||||
ctx->busy = false;
|
||||
}
|
||||
break;
|
||||
case RTTY_FILE_MSG_CANCELED:
|
||||
if (ctx->fd > -1)
|
||||
@@ -374,15 +374,20 @@ void update_progress(struct ev_loop *loop, ev_tstamp start_time, struct buffer *
|
||||
uint32_t remain = buffer_pull_u32(info);
|
||||
uint32_t total = buffer_pull_u32(info);
|
||||
|
||||
if (total == 0)
|
||||
goto done;
|
||||
|
||||
printf("%100c\r", ' ');
|
||||
printf(" %lu%% %s %.3lfs\r", (total - remain) * 100UL / total,
|
||||
format_size(total - remain), ev_now(loop) - start_time);
|
||||
fflush(stdout);
|
||||
|
||||
if (remain == 0) {
|
||||
ev_break(loop, EVBREAK_ALL);
|
||||
puts("");
|
||||
}
|
||||
if (remain == 0)
|
||||
goto done;
|
||||
|
||||
done:
|
||||
ev_break(loop, EVBREAK_ALL);
|
||||
puts("");
|
||||
}
|
||||
|
||||
void cancel_file_operation(struct ev_loop *loop, int sock)
|
||||
|
||||
Reference in New Issue
Block a user