// stcp.c — shared stcp_conn lifecycle #include "stcp.h" #include "../lib/ll_queue.h" #include "../lib/mem.h" #include "../lib/debug_config.h" #include #include void stcp_conn_set_tx_queue(struct stcp_conn *c, struct ll_queue *q) { if (!c || !q) return; c->tx_queue = q; if (c->tx_cb) queue_set_callback(q, c->tx_cb, c); } void stcp_conn_set_rx_queue(struct stcp_conn *c, struct ll_queue *q) { if (!c || !q) return; c->rx_queue = q; } void stcp_conn_set_on_close(struct stcp_conn *c, void (*cb)(struct stcp_conn *conn, int err, void *arg), void *arg) { if (!c || !cb) return; c->on_close = cb; c->close_arg = arg; } void stcp_conn_free(struct stcp_conn *c) { if (!c) return; if (c->socket_id) { uasync_remove_socket_t(c->ua, c->sock); c->socket_id = NULL; } if (c->sock != SOCKET_INVALID) { socket_close_wrapper(c->sock); c->sock = SOCKET_INVALID; } if (c->recv_buf) { u_free(c->recv_buf); c->recv_buf = NULL; } if (c->send_buf) { u_free(c->send_buf); c->send_buf = NULL; } sc_stream_cleanup(&c->stream_send); sc_stream_cleanup(&c->stream_recv); if (c->allocated) u_free(c); }