From ddaebf9f20b85dd9f680d9e56f6bf24540e12781 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 2 Jul 2023 12:08:37 +0530 Subject: [PATCH] More misc send fixes --- kittens/transfer/ftc.go | 10 +++++----- kittens/transfer/send.go | 6 ++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/kittens/transfer/ftc.go b/kittens/transfer/ftc.go index 40163df6e0e..c7a8ab9bb9d 100644 --- a/kittens/transfer/ftc.go +++ b/kittens/transfer/ftc.go @@ -330,15 +330,15 @@ func NewFileTransmissionCommand(serialized string) (ans *FileTransmissionCommand func split_for_transfer(data []byte, file_id string, mark_last bool, callback func(*FileTransmissionCommand)) { const chunk_size = 4096 for len(data) > 0 { - ac := Action_data - if mark_last && len(data) <= chunk_size { - ac = Action_end_data - } chunk := data if len(chunk) > chunk_size { chunk = data[:chunk_size] } - callback(&FileTransmissionCommand{Action: ac, File_id: file_id, Data: chunk}) data = data[len(chunk):] + ac := Action_data + if mark_last && len(data) == 0 { + ac = Action_end_data + } + callback(&FileTransmissionCommand{Action: ac, File_id: file_id, Data: chunk}) } } diff --git a/kittens/transfer/send.go b/kittens/transfer/send.go index 0953e7894f6..6884ee68055 100644 --- a/kittens/transfer/send.go +++ b/kittens/transfer/send.go @@ -70,6 +70,7 @@ func (self *ZlibCompressor) Compress(data []byte) []byte { if err != nil { panic(err) } + defer self.b.Reset() return utils.UnsafeStringToBytes(self.b.String()) } @@ -979,7 +980,12 @@ func (self *SendManager) next_chunks(callback func(string)) error { split_for_transfer(utils.UnsafeStringToBytes(chunk), af.file_id, is_last, func(ftc *FileTransmissionCommand) { callback(ftc.Serialize()) }) } else if is_last { callback(FileTransmissionCommand{Action: Action_end_data, File_id: af.file_id}.Serialize()) + } + if is_last { self.activate_next_ready_file() + if self.active_file() == nil { + return nil + } } } }