On 08/22, Bram Moolenaar wrote:
Matteo Landi wrote:
On 08/22, Bram Moolenaar wrote:
>
>> ch_sendraw seems to fail when sending large chunks of data to a job
>> started in non-blocking mode. Is this expected?
>>
>> Steps to reproduce:
>>
>> - Copy the following into a file, and source it from vim
>>
>> let args = ['cat']
>> let opts = {
>> \ 'noblock': 1
>> \}
>>
>> let job = job_start(args, opts)
>> let data = repeat('X', 65537)
>>
>> call ch_sendraw(job, data)
>> call ch_close_in(job)
>>
>> Expected behavior:
>>
>> - Nothing much (i.e. no errors)
>>
>> Actual bevarior:
>>
>> - E630: channel_write_input(): write while not connected
>>
>> If on the other hand, I initialized data with 65536 bytes instead of
>> 65537, then no error would be thrown.
>
>You are using "noblock", which means the write may happen a bit later,
>but then you use ch_close_in(), closing the channel before all the
>writes are done. If you put a sleep there it works.
Oh, I thought ch_close_in() would wait for any pending write to
complete, but I guess that _special mode_ on `:help channel-close-in`
did refer to non blocking channels in the end, didn't it?! My bad!
Then the next question is, how could I wait for any pending write
operation to complete before calling ch_close_in()? Should I include a
EOF in the last message, instead of calling ch_close_in()?
I don't think we have a mechanism for that. There are callbacks for
reading from input and error, but not for writing. I suppose it would
be possible to add an in_cb function, called after the write buffer is
empty. Or just after every finished write.
I like the idea of letting users know when the buffer is empty; do you
want me to file a bug/enhancement request on Github?
Just to give you a bit more context about what I am trying to do. I am
trying to integrate with a small utility I created, `cb`, which acts as
*remote* `pbcopy`: you pipe some text into it while inside a ssh session
on a remote host, and it would send that back on the local host and copy
on the OS clipboard. Sometimes, copying big selections of text is not
always as fast as one would hope, so I decided to run this using Vim
jobs:
- Create a job where I invoke `cb`
- Write text selection into it -- stdin
- Close the job stdin -- `cb` would terminate on its own after all the
data has been sent over to the next end of the session
I hope this gives you a better understanding of what I am trying to
achieve, and why. Anyway, let me know what do you want me to do with
this request.
Thanks in advance.
--
Matteo Landi
https://matteolandi.net
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20190824151811.GA65581%40hairstyle.local.