Fix transmission of async rc commands

This commit is contained in:
Kovid Goyal 2022-08-25 18:16:03 +05:30
parent ff2ff9c04f
commit 03705cbec0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
7 changed files with 25 additions and 5 deletions

View File

@ -177,6 +177,7 @@ def build_go_code(name: str, cmd: RemoteCommand, seq: OptionSpecSeq, template: s
CMD_NAME=name, __FILE__=__file__, CLI_NAME=name.replace('_', '-'), CMD_NAME=name, __FILE__=__file__, CLI_NAME=name.replace('_', '-'),
SHORT_DESC=serialize_as_go_string(cmd.short_desc), SHORT_DESC=serialize_as_go_string(cmd.short_desc),
LONG_DESC=serialize_as_go_string(cmd.desc.strip()), LONG_DESC=serialize_as_go_string(cmd.desc.strip()),
IS_ASYNC='true' if cmd.is_asynchronous else 'false',
NO_RESPONSE_BASE=NO_RESPONSE_BASE, ADD_FLAGS_CODE='\n'.join(af), NO_RESPONSE_BASE=NO_RESPONSE_BASE, ADD_FLAGS_CODE='\n'.join(af),
WAIT_TIMEOUT=str(cmd.response_timeout), WAIT_TIMEOUT=str(cmd.response_timeout),
ALIAS_NORMALIZE_CODE=render_alias_map(alias_map), ALIAS_NORMALIZE_CODE=render_alias_map(alias_map),

2
go.mod
View File

@ -3,6 +3,8 @@ module kitty
go 1.19 go 1.19
require ( require (
github.com/ALTree/bigfloat v0.0.0-20220102081255-38c8b72a9924
github.com/google/uuid v1.3.0
github.com/jamesruan/go-rfc1924 v0.0.0-20170108144916-2767ca7c638f github.com/jamesruan/go-rfc1924 v0.0.0-20170108144916-2767ca7c638f
github.com/seancfoley/ipaddress-go v1.2.1 github.com/seancfoley/ipaddress-go v1.2.1
github.com/spf13/cobra v1.5.0 github.com/spf13/cobra v1.5.0

4
go.sum
View File

@ -1,4 +1,8 @@
github.com/ALTree/bigfloat v0.0.0-20220102081255-38c8b72a9924 h1:DG4UyTVIujioxwJc8Zj8Nabz1L1wTgQ/xNBSQDfdP3I=
github.com/ALTree/bigfloat v0.0.0-20220102081255-38c8b72a9924/go.mod h1:+NaH2gLeY6RPBPPQf4aRotPPStg+eXc8f9ZaE4vRfD4=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jamesruan/go-rfc1924 v0.0.0-20170108144916-2767ca7c638f h1:Ko4+g6K16vSyUrtd/pPXuQnWsiHe5BYptEtTxfwYwCc= github.com/jamesruan/go-rfc1924 v0.0.0-20170108144916-2767ca7c638f h1:Ko4+g6K16vSyUrtd/pPXuQnWsiHe5BYptEtTxfwYwCc=

View File

@ -191,12 +191,13 @@ func single_rc_sender(rc *utils.RemoteControlCmd, serializer serializer_func) ([
func get_response(do_io func(io_data *rc_io_data) ([]byte, error), io_data *rc_io_data) (ans *Response, err error) { func get_response(do_io func(io_data *rc_io_data) ([]byte, error), io_data *rc_io_data) (ans *Response, err error) {
serialized_response, err := do_io(io_data) serialized_response, err := do_io(io_data)
if err != nil { if err != nil {
if err == os.ErrDeadlineExceeded { if errors.Is(err, os.ErrDeadlineExceeded) {
io_data.rc.Payload = nil io_data.rc.Payload = nil
io_data.rc.CancelAsync = true io_data.rc.CancelAsync = true
io_data.rc.NoResponse = true io_data.rc.NoResponse = true
io_data.next_block = single_rc_sender io_data.rc.ResetSingleSent()
_, err = do_io(io_data) do_io(io_data)
err = fmt.Errorf("Timed out waiting for a response from kitty")
} }
return return
} }

View File

@ -38,6 +38,13 @@ func create_rc_CMD_NAME(args []string) (*utils.RemoteControlCmd, error) {
Version: ProtocolVersion, Version: ProtocolVersion,
NoResponse: NO_RESPONSE_BASE, NoResponse: NO_RESPONSE_BASE,
} }
if IS_ASYNC {
async_id, err := utils.HumanUUID4()
if err != nil {
return nil, err
}
rc.Async = async_id
}
return &rc, nil return &rc, nil
} }

View File

@ -86,6 +86,9 @@ func (self *ShortUUID) Uuid4() (string, error) {
var HumanUUID *ShortUUID var HumanUUID *ShortUUID
func init() { func HumanUUID4() (string, error) {
if HumanUUID == nil {
HumanUUID = CreateShortUUID(HUMAN_ALPHABET) HumanUUID = CreateShortUUID(HUMAN_ALPHABET)
}
return HumanUUID.Uuid4()
} }

View File

@ -9,6 +9,7 @@ type RemoteControlCmd struct {
Payload *interface{} `json:"payload,omitempty"` Payload *interface{} `json:"payload,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"` Timestamp int64 `json:"timestamp,omitempty"`
Password string `json:"password,omitempty"` Password string `json:"password,omitempty"`
Async string `json:"async,omitempty"`
CancelAsync bool `json:"cancel_async,omitempty"` CancelAsync bool `json:"cancel_async,omitempty"`
single_sent bool single_sent bool
@ -16,6 +17,7 @@ type RemoteControlCmd struct {
func (self *RemoteControlCmd) SingleSent() bool { return self.single_sent } func (self *RemoteControlCmd) SingleSent() bool { return self.single_sent }
func (self *RemoteControlCmd) SetSingleSent() { self.single_sent = true } func (self *RemoteControlCmd) SetSingleSent() { self.single_sent = true }
func (self *RemoteControlCmd) ResetSingleSent() { self.single_sent = false }
type EncryptedRemoteControlCmd struct { type EncryptedRemoteControlCmd struct {
Version [3]int `json:"version"` Version [3]int `json:"version"`