diff --git a/include/re_tcp.h b/include/re_tcp.h index 01ebeb0..f3fe799 100644 --- a/include/re_tcp.h +++ b/include/re_tcp.h @@ -66,6 +66,8 @@ int tcp_conn_bind(struct tcp_conn *tc, const struct sa *local); int tcp_conn_connect(struct tcp_conn *tc, const struct sa *peer); int tcp_send(struct tcp_conn *tc, struct mbuf *mb); int tcp_set_send(struct tcp_conn *tc, tcp_send_h *sendh); +void tcp_set_handlers(struct tcp_conn *tc, tcp_estab_h *eh, tcp_recv_h *rh, + tcp_close_h *ch, void *arg); void tcp_conn_rxsz_set(struct tcp_conn *tc, size_t rxsz); int tcp_conn_local_get(const struct tcp_conn *tc, struct sa *local); int tcp_conn_peer_get(const struct tcp_conn *tc, struct sa *peer); diff --git a/src/tcp/tcp.c b/src/tcp/tcp.c index 2f14829..8f04ddf 100644 --- a/src/tcp/tcp.c +++ b/src/tcp/tcp.c @@ -1106,6 +1106,28 @@ int tcp_set_send(struct tcp_conn *tc, tcp_send_h *sendh) } +/** + * Set handlers on a TCP Connection + * + * @param tc TCP Connection + * @param eh TCP Connection Established handler + * @param rh TCP Connection Receive data handler + * @param ch TCP Connection Close handler + * @param arg Handler argument + */ +void tcp_set_handlers(struct tcp_conn *tc, tcp_estab_h *eh, tcp_recv_h *rh, + tcp_close_h *ch, void *arg) +{ + if (!tc) + return; + + tc->estabh = eh; + tc->recvh = rh; + tc->closeh = ch; + tc->arg = arg; +} + + /** * Get local network address of TCP Socket *