You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.1 KiB
35 lines
1.1 KiB
// stcp.c — shared stcp_conn lifecycle |
|
#include "stcp.h" |
|
#include "../lib/ll_queue.h" |
|
#include "../lib/mem.h" |
|
#include "../lib/debug_config.h" |
|
#include <stdlib.h> |
|
#include <string.h> |
|
|
|
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); |
|
}
|
|
|