-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce eventmux callback function for linenoise
In the previous version of console implementation, we tried to integrate tiny-web-server to enable the ability of processing commands from web requests. As the result, the package linenoise which is responsible for command-line auto-complete needs to be disabled during the running time of tiny-web-server. Because the main loop in "line_edit()" function in linenoise doesn't have the ability to handle web requests correctly. When we start the web server, we use "cmd_select" in console.c and use "select" function to monitor web socket file descriptor and stdin_fd at the same time. I re-design the control flow of web request and command-line input by implement the function "web_eventmux()", and register it as a hook function of type "line_eventmux_callback_t" inside linenoise package. As the result, we can utilize function inside the main loop of linenoise which is located inside the function "line_edit()". "web_eventmux()" is a function which use the function "select()" to monitor both input file descriptor and web file descriptor and modify "line_edit()" to use "eventmux_callback()" so we can process command-line input as normal and provide the command-line auto-complete feature alongside with the abitlity to deal with inputs from different input sources, such as web request. One may wonder why don't we simply modify the function "line_edit()", the reason is that linenoise is an upstream package so we only want to do the miminal changes to this package.
- Loading branch information
Showing
5 changed files
with
79 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters