mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 10:46:58 +01:00
plugin: Get rid of redundant stdin and stdout members
Suggested-by: Rusty Russell <@rustyrussell> Signed-off-by: Christian Decker <@cdecker>
This commit is contained in:
parent
e6ef675ea1
commit
775e4b784d
1 changed files with 21 additions and 21 deletions
|
@ -10,7 +10,6 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
struct plugin {
|
struct plugin {
|
||||||
int stdin, stdout;
|
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
char *cmd;
|
char *cmd;
|
||||||
struct io_conn *stdin_conn, *stdout_conn;
|
struct io_conn *stdin_conn, *stdout_conn;
|
||||||
|
@ -261,24 +260,23 @@ static void plugin_request_send_(
|
||||||
const struct plugin_request *), \
|
const struct plugin_request *), \
|
||||||
(arg))
|
(arg))
|
||||||
|
|
||||||
static struct io_plan *plugin_conn_init(struct io_conn *conn,
|
static struct io_plan *plugin_stdin_conn_init(struct io_conn *conn,
|
||||||
struct plugin *plugin)
|
struct plugin *plugin)
|
||||||
{
|
{
|
||||||
plugin->stop = false;
|
/* We write to their stdin */
|
||||||
if (plugin->stdout == io_conn_fd(conn)) {
|
/* We don't have anything queued yet, wait for notification */
|
||||||
/* We read from their stdout */
|
plugin->stdin_conn = conn;
|
||||||
plugin->stdout_conn = conn;
|
return io_wait(plugin->stdin_conn, plugin, plugin_write_json, plugin);
|
||||||
return io_read_partial(plugin->stdout_conn, plugin->buffer,
|
}
|
||||||
tal_bytelen(plugin->buffer),
|
|
||||||
&plugin->len_read, plugin_read_json,
|
static struct io_plan *plugin_stdout_conn_init(struct io_conn *conn,
|
||||||
plugin);
|
struct plugin *plugin)
|
||||||
} else {
|
{
|
||||||
/* We write to their stdin */
|
/* We read from their stdout */
|
||||||
plugin->stdin_conn = conn;
|
plugin->stdout_conn = conn;
|
||||||
/* We don't have anything queued yet, wait for notification */
|
return io_read_partial(plugin->stdout_conn, plugin->buffer,
|
||||||
return io_wait(plugin->stdin_conn, plugin, plugin_write_json,
|
tal_bytelen(plugin->buffer), &plugin->len_read,
|
||||||
plugin);
|
plugin_read_json, plugin);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callback called when parsing options. It just stores the value in
|
/* Callback called when parsing options. It just stores the value in
|
||||||
|
@ -388,6 +386,7 @@ void plugins_init(struct plugins *plugins)
|
||||||
{
|
{
|
||||||
struct plugin *p;
|
struct plugin *p;
|
||||||
char **cmd;
|
char **cmd;
|
||||||
|
int stdin, stdout;
|
||||||
plugins->pending_init = tal_count(plugins->plugins);
|
plugins->pending_init = tal_count(plugins->plugins);
|
||||||
uintmap_init(&plugins->pending_requests);
|
uintmap_init(&plugins->pending_requests);
|
||||||
|
|
||||||
|
@ -397,16 +396,17 @@ void plugins_init(struct plugins *plugins)
|
||||||
cmd = tal_arr(p, char *, 2);
|
cmd = tal_arr(p, char *, 2);
|
||||||
cmd[0] = p->cmd;
|
cmd[0] = p->cmd;
|
||||||
cmd[1] = NULL;
|
cmd[1] = NULL;
|
||||||
p->pid = pipecmdarr(&p->stdout, &p->stdin, NULL, cmd);
|
p->pid = pipecmdarr(&stdout, &stdin, NULL, cmd);
|
||||||
|
|
||||||
list_head_init(&p->output);
|
list_head_init(&p->output);
|
||||||
p->buffer = tal_arr(p, char, 64);
|
p->buffer = tal_arr(p, char, 64);
|
||||||
p->used = 0;
|
p->used = 0;
|
||||||
|
p->stop = false;
|
||||||
|
|
||||||
/* Create two connections, one read-only on top of p->stdin, and one
|
/* Create two connections, one read-only on top of p->stdin, and one
|
||||||
* write-only on p->stdout */
|
* write-only on p->stdout */
|
||||||
io_new_conn(p, p->stdout, plugin_conn_init, p);
|
io_new_conn(p, stdout, plugin_stdout_conn_init, p);
|
||||||
io_new_conn(p, p->stdin, plugin_conn_init, p);
|
io_new_conn(p, stdin, plugin_stdin_conn_init, p);
|
||||||
plugin_request_send(p, "init", "[]", plugin_init_cb, p);
|
plugin_request_send(p, "init", "[]", plugin_init_cb, p);
|
||||||
}
|
}
|
||||||
if (plugins->pending_init > 0)
|
if (plugins->pending_init > 0)
|
||||||
|
|
Loading…
Add table
Reference in a new issue