Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Responsive pipe #131

Merged
merged 2 commits into from
Aug 5, 2016
Merged

Responsive pipe #131

merged 2 commits into from
Aug 5, 2016

Conversation

abensj
Copy link
Contributor

@abensj abensj commented Jul 21, 2016

When xdotool commands were read from pipe, they were executed only when the pipe was closed, thus if external process wanted to make more than one call to xdotool it had to create new process per each call as a result spending more system resources than could be spent. Other drawback with that approach is that xdotool can read from pipe as many commands as it can address in RAM in one run.

This fixes both of those issues. Each command from pipe is executed exactly after the newline is reached and all tokens in that line are parsed.

Dynamic memory is allocated only as much as the longest token-line requires, plus each size of each token. This is not the most efficient approach, but it is simple and in overall for this use-case should be fine.

Most of the parsing algorithm ideas were taken from the existing code, thus there should be no implications of the way xdotool functions with pipes. The only thing that i can think of now is that in the old algorithm all tokens were arranged in one huge token queue when reading from pipe, now pipe is parsed/executed line by line, thus commands must have all the required arguments in the same line. I don't see a reason why should it be otherwise, but to mention an implication, i state it here.

Other thing which i don't not know to handle correctly is a TODO comment after "script_argv = realloc(script_argv, (script_argc+1) * sizeof(char *));" line in function script_main. What this TODO was meant for? The only thing there i could see as a little bug was that when memory was reallocated, the expected NULL pointer was not added at the end. AFAIK newly allocated portion by realloc is indeterminate, thus there was no guarantee that the token list would end with NULL.

@jordansissel
Copy link
Owner

What this TODO was meant for?

I believe this todo was to remind me where I stopped working on the code ... I guess I never came back to this part of the code or maybe I forgot to remove it -- haha. oops :\

@jordansissel
Copy link
Owner

I tested this briefly and it looks ok to me. Script execution now occurs by line of input instead of at pipe close.

@jordansissel jordansissel merged commit e65ffcd into jordansissel:master Aug 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants