From 5da465b0831ece53fa64900f8069d60e93a1de98 Mon Sep 17 00:00:00 2001 From: "Dmitriy A. Gerasimov" <dmitriy.gerasimov@demlabs.net> Date: Sun, 23 Aug 2020 01:41:12 +0700 Subject: [PATCH] [*] Rework because of SDK changes --- CellFrame/python-cellframe.c | 2 +- .../core/include/libdap-server-core-python.h | 3 +-- .../dap-sdk/net/core/src/dap_events_python.c | 2 +- .../net/core/src/dap_events_socket_python.c | 12 ++++++------ .../net/core/src/libdap-server-core-python.c | 19 ++++--------------- 5 files changed, 13 insertions(+), 25 deletions(-) diff --git a/CellFrame/python-cellframe.c b/CellFrame/python-cellframe.c index 78217fe0..0d2666ff 100644 --- a/CellFrame/python-cellframe.c +++ b/CellFrame/python-cellframe.c @@ -41,7 +41,7 @@ BOOL WINAPI consoleHandler(DWORD dwType){ void sigfunc(int sig){ if (sig == SIGINT){ log_it(L_NOTICE, "Handler Ctrl+C"); - dap_server_loop_stop(); + dap_events_stop_all(); deinit_modules(); } } diff --git a/modules/dap-sdk/net/core/include/libdap-server-core-python.h b/modules/dap-sdk/net/core/include/libdap-server-core-python.h index a6d44efd..bb14b5b6 100644 --- a/modules/dap-sdk/net/core/include/libdap-server-core-python.h +++ b/modules/dap-sdk/net/core/include/libdap-server-core-python.h @@ -1,8 +1,8 @@ +#pragma once #define PY_SSIZE_T_CLEAN #include "Python.h" #include "dap_server_python.h" #include "dap_server.h" -#include "dap_client_remote.h" #include "dap_events.h" #include "dap_common.h" #include "dap_events_python.h" @@ -24,7 +24,6 @@ PyObject *dap_server_core_loop(PyObject *self, PyObject *args); PyObject *dap_server_core_listen(PyObject *self, PyObject *args); static PyMethodDef ServerCorePythonMethods[] = { - {"loop", dap_server_core_loop, METH_VARARGS | METH_STATIC, ""}, {"listen", dap_server_core_listen, METH_VARARGS | METH_STATIC, ""}, {NULL, NULL, 0, NULL} }; diff --git a/modules/dap-sdk/net/core/src/dap_events_python.c b/modules/dap-sdk/net/core/src/dap_events_python.c index 3edcf3bd..f9c02d58 100644 --- a/modules/dap-sdk/net/core/src/dap_events_python.c +++ b/modules/dap-sdk/net/core/src/dap_events_python.c @@ -29,7 +29,7 @@ PyObject *dap_events_socket_kill_socket_py(PyDapEventsObject *self, PyObject *ar if (!PyArg_ParseTuple(args, "O", &in_obj)){ return NULL; } - dap_events_socket_kill_socket(((PyDapEventsSocketObject*)in_obj)->t_events_socket); + dap_events_socket_queue_remove_and_delete(((PyDapEventsSocketObject*)in_obj)->t_events_socket); return PyLong_FromLong(0); } diff --git a/modules/dap-sdk/net/core/src/dap_events_socket_python.c b/modules/dap-sdk/net/core/src/dap_events_socket_python.c index 2c2badfc..a77eadc2 100644 --- a/modules/dap-sdk/net/core/src/dap_events_socket_python.c +++ b/modules/dap-sdk/net/core/src/dap_events_socket_python.c @@ -33,7 +33,7 @@ PyObject *dap_events_socket_set_readable_py(PyDapEventsSocketObject *self, PyObj bool is_ready = true; if (l_is_ready == Py_False) is_ready = false; - dap_events_socket_set_readable(self->t_events_socket, is_ready); + dap_events_socket_set_readable_unsafe(self->t_events_socket, is_ready); return PyLong_FromLong(0); } PyObject *dap_events_socket_set_writable_py(PyDapEventsSocketObject *self, PyObject *args){ @@ -47,7 +47,7 @@ PyObject *dap_events_socket_set_writable_py(PyDapEventsSocketObject *self, PyObj bool is_ready = true; if (l_is_ready == Py_False) is_ready = false; - dap_events_socket_set_writable(self->t_events_socket, is_ready); + dap_events_socket_set_writable_unsafe(self->t_events_socket, is_ready); return PyLong_FromLong(0); } @@ -61,7 +61,7 @@ PyObject *dap_events_socket_write_py(PyDapEventsSocketObject *self, PyObject *ar return NULL; } char *in_v_bytes = PyBytes_AsString((PyObject*)in_bytes); - size_t res_size = dap_events_socket_write(self->t_events_socket, + size_t res_size = dap_events_socket_write_unsafe(self->t_events_socket, in_v_bytes, in_size); return Py_BuildValue("n", res_size); } @@ -78,7 +78,7 @@ PyObject *dap_events_socket_write_f_py(PyDapEventsSocketObject *self, PyObject * if (!PyArg_VaParse(args, format, ap)){ return NULL; } - size_t res_size = dap_events_socket_write_f(self->t_events_socket, format, ap); + size_t res_size = dap_events_socket_write_f_unsafe(self->t_events_socket, format, ap); return Py_BuildValue("n", res_size); } PyObject *dap_events_socket_read_py(PyDapEventsSocketObject *self, PyObject *args){ @@ -90,7 +90,7 @@ PyObject *dap_events_socket_read_py(PyDapEventsSocketObject *self, PyObject *arg return NULL; } void *res = DAP_NEW_SIZE(void*, in_size); - size_t res_size = dap_events_socket_read(self->t_events_socket, res, in_size); + size_t res_size = dap_events_socket_pop_from_buf_in(self->t_events_socket, res, in_size); PyBytesObject *res_obj = (PyBytesObject*)PyBytes_FromString(res); return Py_BuildValue("nS", res_size, res_obj); } @@ -106,7 +106,7 @@ PyObject *dap_events_socket_delete_py(PyDapEventsSocketObject *self, PyObject *a bool boolean = true; if (in_bool == Py_False) boolean = false; - dap_events_socket_delete(self->t_events_socket, boolean); + dap_events_socket_queue_remove_and_delete( self->t_events_socket); return PyLong_FromLong(0); } diff --git a/modules/dap-sdk/net/core/src/libdap-server-core-python.c b/modules/dap-sdk/net/core/src/libdap-server-core-python.c index e38c6e62..bb2825f6 100644 --- a/modules/dap-sdk/net/core/src/libdap-server-core-python.c +++ b/modules/dap-sdk/net/core/src/libdap-server-core-python.c @@ -3,41 +3,30 @@ #define LOG_TAG "libdap-server-core-python" int dap_server_core_init(uint32_t l_thread_cnt, size_t conn_t){ - int result = dap_server_init(l_thread_cnt); + int result = dap_server_init(); if ( result != 0 ) { log_it( L_CRITICAL, "Can't init socket server module" ); } dap_events_init(l_thread_cnt, conn_t); - dap_client_remote_init(); return result; } void dap_server_core_deinit(void){ - dap_client_remote_deinit(); dap_server_deinit(); dap_events_deinit(); } -PyObject *dap_server_core_loop(PyObject *self, PyObject *args){ - PyObject *obj_server; - if (!PyArg_ParseTuple(args, "O", &obj_server)){ - return NULL; - } - int32_t result = dap_server_loop(((PyDapServerObject*)obj_server)->t_server); - log_it( result ? L_CRITICAL : L_NOTICE, "Server loop stopped with return code %d", ((PyDapServerObject*)obj_server)->t_server ); - return PyLong_FromLong(result); -} - PyObject *dap_server_core_listen(PyObject *self, PyObject *args){ const char *addr; uint16_t port; uint16_t type; - if (!PyArg_ParseTuple(args, "s|H|H", &addr, &port, &type)){ + PyObject *events; + if (!PyArg_ParseTuple(args, "O|s|H|H", &events, &addr, &port, &type)){ return NULL; } if (type > 1) return NULL; PyObject *obj = _PyObject_New(&dapServer_dapServerType); - ((PyDapServerObject*)obj)->t_server = dap_server_listen(addr, port, type); + ((PyDapServerObject*)obj)->t_server = dap_server_new(((PyDapEventsObject*)events)->t_events, addr, port, type); return Py_BuildValue("O", obj); } -- GitLab