From 88d085b7252643ceec0c9ac646b6d6f680157617 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 11 Oct 2015 16:25:31 +0200 Subject: [PATCH] Allow changing the accept callbacks. This is used in the test, in order to stop accepting new connections after the first one. --- test.c | 1 + utcp.c | 7 +++++++ utcp.h | 1 + 3 files changed, 9 insertions(+) diff --git a/test.c b/test.c index 8ad46c6..a37f856 100644 --- a/test.c +++ b/test.c @@ -39,6 +39,7 @@ ssize_t do_recv(struct utcp_connection *c, const void *data, size_t len) { void do_accept(struct utcp_connection *nc, uint16_t port) { utcp_accept(nc, do_recv, NULL); c = nc; + utcp_set_accept_cb(c->utcp, NULL, NULL); } ssize_t do_send(struct utcp *utcp, const void *data, size_t len) { diff --git a/utcp.c b/utcp.c index e8755ed..062cc5a 100644 --- a/utcp.c +++ b/utcp.c @@ -1256,3 +1256,10 @@ void utcp_set_poll_cb(struct utcp_connection *c, utcp_poll_t poll) { if(c) c->poll = poll; } + +void utcp_set_accept_cb(struct utcp *utcp, utcp_accept_t accept, utcp_pre_accept_t pre_accept) { + if(utcp) { + utcp->accept = accept; + utcp->pre_accept = pre_accept; + } +} diff --git a/utcp.h b/utcp.h index 7ebca73..8d3874f 100644 --- a/utcp.h +++ b/utcp.h @@ -61,6 +61,7 @@ extern int utcp_shutdown(struct utcp_connection *connection, int how); extern struct timeval utcp_timeout(struct utcp *utcp); extern void utcp_set_recv_cb(struct utcp_connection *connection, utcp_recv_t recv); extern void utcp_set_poll_cb(struct utcp_connection *connection, utcp_poll_t poll); +extern void utcp_set_accept_cb(struct utcp *utcp, utcp_accept_t accept, utcp_pre_accept_t pre_accept); // Global socket options -- 2.39.5