summaryrefslogtreecommitdiff
path: root/core/src/xmake
diff options
context:
space:
mode:
authorruki <[email protected]>2022-04-15 00:45:16 +0800
committerruki <[email protected]>2022-04-15 00:45:16 +0800
commit55f541667ccd31e67e61d7eeeeff412552336903 (patch)
tree63397ffb88713b8ee28522305c9cc8386b86246e /core/src/xmake
parenta61b2aa25af04eb75c6628fbb4f867c9a82ae72a (diff)
improve pipe mode
Diffstat (limited to 'core/src/xmake')
-rw-r--r--core/src/xmake/io/pipe_open.c3
-rw-r--r--core/src/xmake/io/pipe_openpair.c15
2 files changed, 15 insertions, 3 deletions
diff --git a/core/src/xmake/io/pipe_open.c b/core/src/xmake/io/pipe_open.c
index e40451641..599c3f53d 100644
--- a/core/src/xmake/io/pipe_open.c
+++ b/core/src/xmake/io/pipe_open.c
@@ -51,6 +51,9 @@ tb_int_t xm_io_pipe_open(lua_State* lua)
tb_size_t mode = TB_PIPE_MODE_RO;
if (modestr[0] == 'w') mode = TB_PIPE_MODE_WO;
+ // set block mode
+ if (modestr[1] == 'B') mode |= TB_PIPE_MODE_BLOCK;
+
// get buffer size
tb_size_t buffsize = (tb_size_t)luaL_checknumber(lua, 3);
diff --git a/core/src/xmake/io/pipe_openpair.c b/core/src/xmake/io/pipe_openpair.c
index 3e76c94e7..cb7d2c761 100644
--- a/core/src/xmake/io/pipe_openpair.c
+++ b/core/src/xmake/io/pipe_openpair.c
@@ -35,19 +35,28 @@
*/
/*
- * io.pipe_openpair(buffsize)
+ * io.pipe_openpair(mode, buffsize)
*/
tb_int_t xm_io_pipe_openpair(lua_State* lua)
{
// check
tb_assert_and_check_return_val(lua, 0);
+ // get pipe mode
+ tb_char_t const* modestr = luaL_optstring(lua, 1, "AA");
+ tb_assert_and_check_return_val(modestr, 0);
+
+ // init mode
+ tb_size_t mode[2] = {0};
+ if (modestr[0] == 'B') mode[0] |= TB_PIPE_MODE_BLOCK;
+ if (modestr[1] == 'B') mode[1] |= TB_PIPE_MODE_BLOCK;
+
// get buffer size
- tb_size_t buffsize = (tb_size_t)luaL_checknumber(lua, 1);
+ tb_size_t buffsize = (tb_size_t)luaL_checknumber(lua, 2);
// init pipe
tb_pipe_file_ref_t pipefile[2];
- if (tb_pipe_file_init_pair(pipefile, tb_null, buffsize))
+ if (tb_pipe_file_init_pair(pipefile, mode, buffsize))
{
xm_lua_pushpointer(lua, (tb_pointer_t)pipefile[0]);
xm_lua_pushpointer(lua, (tb_pointer_t)pipefile[1]);