summaryrefslogtreecommitdiffstats
path: root/osdep/subprocess.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-08-16 02:54:44 +0200
committerwm4 <wm4@nowhere>2020-08-16 02:54:44 +0200
commite27c523a10708b7265c33a4bae631663df4bb297 (patch)
tree34bdcd1bc48a5311ec24181dec913768180ad851 /osdep/subprocess.h
parentd6bf3880d74459103a39426275837ec0a1d48e54 (diff)
downloadmpv-e27c523a10708b7265c33a4bae631663df4bb297.tar.bz2
mpv-e27c523a10708b7265c33a4bae631663df4bb297.tar.xz
command: extend subprocess command stdin, change behavior
Make it possible to feed a string to stdin of a subprocess. Out of laziness, it can't be an arbitrary byte string. (Would require adding an option type that takes in a Lua byte string.) Do not set stdin of a subprocess to fd 0 (i.e. mpv's stdin) anymore, because it makes things more consistent. Enabling stdin didn't make too much sense in the first place, so this behavior change seems justifiable. win32 support missing. Fixes: #8003
Diffstat (limited to 'osdep/subprocess.h')
-rw-r--r--osdep/subprocess.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/osdep/subprocess.h b/osdep/subprocess.h
index 14d4896c58..4bf2dc32dd 100644
--- a/osdep/subprocess.h
+++ b/osdep/subprocess.h
@@ -22,9 +22,18 @@
#include <stddef.h>
#include <stdint.h>
+#include "misc/bstr.h"
+
struct mp_cancel;
+// Incrementally called with data that was read. Buffer valid only during call.
+// size==0 means EOF.
typedef void (*subprocess_read_cb)(void *ctx, char *data, size_t size);
+// Incrementally called to refill *mp_subprocess_fd.write_buf, whenever write_buf
+// has length 0 and the pipe is writable. While writing, *write_buf is adjusted
+// to contain only the not yet written data.
+// Not filling the buffer means EOF.
+typedef void (*subprocess_write_cb)(void *ctx);
void mp_devnull(void *ctx, char *data, size_t size);
@@ -37,6 +46,9 @@ struct mp_subprocess_fd {
// Note: "neutral" initialization requires setting src_fd=-1.
subprocess_read_cb on_read; // if not NULL, serve reads
void *on_read_ctx; // for on_read(on_read_ctx, ...)
+ subprocess_write_cb on_write; // if not NULL, serve writes
+ void *on_write_ctx; // for on_write(on_write_ctx, ...)
+ bstr *write_buf; // must be !=NULL if on_write is set
int src_fd; // if >=0, dup this FD to target FD
};