From 2908c3ca4168f963958e4a97e54800667ff34ccf Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 4 Apr 2017 06:28:14 +0300 Subject: [PATCH] zephyr/modusocket: Factor out socket_new() function. It will be reused e.g. for accept() implementation. --- zephyr/modusocket.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/zephyr/modusocket.c b/zephyr/modusocket.c index 025cb0c92d..155ed69b80 100644 --- a/zephyr/modusocket.c +++ b/zephyr/modusocket.c @@ -128,6 +128,15 @@ static void sock_received_cb(struct net_context *context, struct net_buf *net_bu k_fifo_put(&socket->recv_q, net_buf); } +socket_obj_t *socket_new(void) { + socket_obj_t *socket = m_new_obj_with_finaliser(socket_obj_t); + socket->base.type = (mp_obj_t)&socket_type; + k_fifo_init(&socket->recv_q); + socket->cur_buf = NULL; + socket->state = STATE_NEW; + return socket; +} + // Methods STATIC void socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { @@ -143,11 +152,7 @@ STATIC void socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kin STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 4, false); - socket_obj_t *socket = m_new_obj_with_finaliser(socket_obj_t); - socket->base.type = type; - k_fifo_init(&socket->recv_q); - socket->cur_buf = NULL; - socket->state = STATE_NEW; + socket_obj_t *socket = socket_new(); int family = AF_INET; int socktype = SOCK_STREAM;