Work on refactoring send kitten to fix various issues

This commit is contained in:
Kovid Goyal
2023-08-08 06:28:43 +05:30
parent 0971e8c630
commit 0e87e0c7de
8 changed files with 69 additions and 72 deletions

View File

@@ -97,7 +97,7 @@ func do_chunked_io(io_data *rc_io_data) (serialized_response []byte, err error)
return "", nil
}
lp.OnWriteComplete = func(completed_write_id loop.IdType) error {
lp.OnWriteComplete = func(completed_write_id loop.IdType, has_pending_writes bool) error {
if state == WAITING_FOR_STREAMING_RESPONSE || state == WAITING_FOR_RESPONSE {
return nil
}
@@ -151,7 +151,7 @@ func do_chunked_io(io_data *rc_io_data) (serialized_response []byte, err error)
lp.OnRCResponse = func(raw []byte) error {
if state == WAITING_FOR_STREAMING_RESPONSE && is_stream_response(raw) {
state = SENDING
return lp.OnWriteComplete(0)
return lp.OnWriteComplete(0, false)
}
serialized_response = raw
lp.Quit(0)

View File

@@ -83,7 +83,7 @@ type Loop struct {
OnResize func(old_size ScreenSize, new_size ScreenSize) error
// Called when writing is done
OnWriteComplete func(msg_id IdType) error
OnWriteComplete func(msg_id IdType, has_pending_writes bool) error
// Called when a response to an rc command is received
OnRCResponse func(data []byte) error

View File

@@ -285,6 +285,7 @@ func (self *Loop) run() (err error) {
// queueing and startup of writer thread and also as a performance
// optimization to avoid copying unnecessarily to pending_writes
self.tty_write_channel = make(chan write_msg, 512)
self.write_msg_id_counter = 0
write_done_channel := make(chan IdType)
self.wakeup_channel = make(chan byte, 256)
self.pending_writes = make([]write_msg, 0, 256)
@@ -452,7 +453,7 @@ func (self *Loop) run() (err error) {
case msg_id := <-write_done_channel:
self.flush_pending_writes(self.tty_write_channel)
if self.OnWriteComplete != nil {
err = self.OnWriteComplete(msg_id)
err = self.OnWriteComplete(msg_id, msg_id < self.write_msg_id_counter)
if err != nil {
return err
}

View File

@@ -75,15 +75,15 @@ func (self *Loop) wait_for_write_to_complete(sentinel IdType, tty_write_channel
case tty_write_channel <- self.pending_writes[0]:
self.pending_writes = self.pending_writes[1:]
case write_id, more := <-write_done_channel:
if write_id == sentinel {
return nil
}
if self.OnWriteComplete != nil {
err := self.OnWriteComplete(write_id)
err := self.OnWriteComplete(write_id, write_id < self.write_msg_id_counter)
if err != nil {
return err
}
}
if write_id == sentinel {
return nil
}
if !more {
return fmt.Errorf("The write_done_channel was unexpectedly closed")
}