summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-10-29 13:27:38 +0800
committerruki <[email protected]>2023-10-29 13:27:38 +0800
commita6e3484b55c7af9c26b8cfab3e4a79051f2a8819 (patch)
tree537fa790345e0816768debf01a65ffb670098a40
parent567411537499c5a3557580d44b36fe0be6cf5ef7 (diff)
add kill socket
-rw-r--r--core/src/xmake/engine.c2
-rw-r--r--core/src/xmake/io/socket_kill.c55
-rw-r--r--xmake/core/base/socket.lua14
-rw-r--r--xmake/modules/async/runjobs.lua7
4 files changed, 73 insertions, 5 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c
index 6992b6443..f1b0b381b 100644
--- a/core/src/xmake/engine.c
+++ b/core/src/xmake/engine.c
@@ -162,6 +162,7 @@ tb_int_t xm_io_socket_sendto(lua_State* lua);
tb_int_t xm_io_socket_sendfile(lua_State* lua);
tb_int_t xm_io_socket_recv(lua_State* lua);
tb_int_t xm_io_socket_recvfrom(lua_State* lua);
+tb_int_t xm_io_socket_kill(lua_State* lua);
tb_int_t xm_io_socket_close(lua_State* lua);
// the io/pipe functions
@@ -401,6 +402,7 @@ static luaL_Reg const g_io_functions[] =
, { "socket_sendfile", xm_io_socket_sendfile }
, { "socket_recv", xm_io_socket_recv }
, { "socket_recvfrom", xm_io_socket_recvfrom }
+, { "socket_kill" , xm_io_socket_kill }
, { "socket_close", xm_io_socket_close }
, { "pipe_open", xm_io_pipe_open }
, { "pipe_openpair", xm_io_pipe_openpair }
diff --git a/core/src/xmake/io/socket_kill.c b/core/src/xmake/io/socket_kill.c
new file mode 100644
index 000000000..46cddf5cf
--- /dev/null
+++ b/core/src/xmake/io/socket_kill.c
@@ -0,0 +1,55 @@
+/*!A cross-platform build utility based on Lua
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Copyright (C) 2015-present, TBOOX Open Source Group.
+ *
+ * @author ruki
+ * @file socket_kill.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "socket_kill"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * interfaces
+ */
+
+// local sock = io.socket_kill(sock)
+tb_int_t xm_io_socket_kill(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // is pointer?
+ if (!xm_lua_ispointer(lua, 1))
+ return 0;
+
+ // get socket
+ tb_socket_ref_t sock = (tb_socket_ref_t)xm_lua_topointer(lua, 1);
+ tb_check_return_val(sock, 0);
+
+ // kill socket
+ tb_socket_kill(sock, TB_SOCKET_KILL_RW);
+ return 0;
+}
+
diff --git a/xmake/core/base/socket.lua b/xmake/core/base/socket.lua
index 12b3661f5..8976faed5 100644
--- a/xmake/core/base/socket.lua
+++ b/xmake/core/base/socket.lua
@@ -641,6 +641,20 @@ function _instance:wait(events, timeout)
return result, errors
end
+-- kill socket
+function _instance:kill()
+
+ -- ensure opened
+ local ok, errors = self:_ensure_opened()
+ if not ok then
+ return false, errors
+ end
+
+ -- kill it
+ io.socket_kill(self:cdata())
+ return true
+end
+
-- close socket
function _instance:close()
diff --git a/xmake/modules/async/runjobs.lua b/xmake/modules/async/runjobs.lua
index f4c7f38bb..8812251ac 100644
--- a/xmake/modules/async/runjobs.lua
+++ b/xmake/modules/async/runjobs.lua
@@ -262,12 +262,9 @@ function main(name, jobs, opt)
local waitobjs = scheduler.co_group_waitobjs(group_name)
if waitobjs:size() > 0 then
for _, obj in waitobjs:keys() do
- if obj:otype() == scheduler.OT_PROC then
+ -- TODO, kill pipe is not supported now
+ if obj.kill then
obj:kill()
- elseif obj:otype() == scheduler.OT_SOCK then
- -- TODO
- elseif obj:otype() == scheduler.OT_PIPE then
- -- TODO
end
end
end