@@ -340,12 +340,10 @@ func (self *manager) request_files() transmit_iterator {
340340 read_signature = false
341341 }
342342 }
343- queue_write (self .prefix )
344- queue_write (FileTransmissionCommand {
343+ last_write_id = self .send (FileTransmissionCommand {
345344 Action : Action_file , Name : f .remote_path , File_id : f .file_id , Ttype : utils .IfElse (
346345 read_signature , TransmissionType_rsync , TransmissionType_simple ), Compression : f .compression_type ,
347- }.Serialize (false ))
348- last_write_id = queue_write (self .suffix )
346+ }, queue_write )
349347 if read_signature {
350348 fsf , err := os .Open (f .expanded_local_path )
351349 if err != nil {
@@ -365,9 +363,7 @@ func (self *manager) request_files() transmit_iterator {
365363 }
366364 }
367365 f .sent_bytes += output .amt
368- queue_write (self .prefix )
369- queue_write (FileTransmissionCommand {Action : Action_end_data , File_id : f .file_id }.Serialize (false ))
370- last_write_id = queue_write (self .suffix )
366+ last_write_id = self .send (FileTransmissionCommand {Action : Action_end_data , File_id : f .file_id }, queue_write )
371367 }
372368 return
373369 }
@@ -389,15 +385,16 @@ type handler struct {
389385 last_data_write_id loop.IdType
390386}
391387
388+ func (self * manager ) send (c FileTransmissionCommand , send func (string ) loop.IdType ) loop.IdType {
389+ send (self .prefix )
390+ send (c .Serialize (false ))
391+ return send (self .suffix )
392+ }
393+
392394func (self * manager ) start_transfer (send func (string ) loop.IdType ) {
393- s := func (c FileTransmissionCommand ) {
394- send (self .prefix )
395- send (c .Serialize (false ))
396- send (self .suffix )
397- }
398- s (FileTransmissionCommand {Action : Action_receive , Bypass : self .bypass , Size : int64 (len (self .spec ))})
395+ self .send (FileTransmissionCommand {Action : Action_receive , Bypass : self .bypass , Size : int64 (len (self .spec ))}, send )
399396 for i , x := range self .spec {
400- s (FileTransmissionCommand {Action : Action_file , File_id : strconv .Itoa (i ), Name : x })
397+ self . send (FileTransmissionCommand {Action : Action_file , File_id : strconv .Itoa (i ), Name : x }, send )
401398 }
402399 self .progress_tracker .start_transfer ()
403400}
@@ -415,9 +412,7 @@ func (self *handler) abort_transfer(delay time.Duration) {
415412 if delay <= 0 {
416413 delay = time .Second * 5
417414 }
418- self .lp .QueueWriteString (self .manager .prefix )
419- self .lp .QueueWriteString (FileTransmissionCommand {Action : Action_cancel }.Serialize (false ))
420- self .lp .QueueWriteString (self .manager .suffix )
415+ self .manager .send (FileTransmissionCommand {Action : Action_cancel }, self .lp .QueueWriteString )
421416 self .manager .state = state_canceled
422417 self .lp .AddTimer (delay , false , self .do_error_quit )
423418}
@@ -796,9 +791,7 @@ func (self *handler) on_file_transfer_response(ftc *FileTransmissionCommand) (er
796791 }
797792 }
798793 if self .manager .transfer_done {
799- self .lp .QueueWriteString (self .manager .prefix )
800- self .lp .QueueWriteString (FileTransmissionCommand {Action : Action_finish }.Serialize (false ))
801- self .lp .QueueWriteString (self .manager .suffix )
794+ self .manager .send (FileTransmissionCommand {Action : Action_finish }, self .lp .QueueWriteString )
802795 self .quit_after_write_code = 0
803796 self .refresh_progress (0 )
804797 } else if self .transmit_started {
0 commit comments