aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/include/server.h1
-rw-r--r--lib/libostp/server.c24
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/include/server.h b/lib/include/server.h
index 9e09f78..52f92ce 100644
--- a/lib/include/server.h
+++ b/lib/include/server.h
@@ -59,5 +59,6 @@ int listener_bind(struct ostp_listener *lp);
int listener_poll(struct ostp_listener *lp);
void listener_cleanup(struct ostp_listener *lp);
void listener_close(struct ostp_listener *lp, struct ostp_client *c);
+int listener_clients(struct ostp_listener *lp, struct ostp_client **res);
#endif /* !LIBOSTP_SERVER_H_ */
diff --git a/lib/libostp/server.c b/lib/libostp/server.c
index c8f164b..aad91e6 100644
--- a/lib/libostp/server.c
+++ b/lib/libostp/server.c
@@ -199,3 +199,27 @@ listener_close(struct ostp_listener *lp, struct ostp_client *c)
memset(&c->session, 0, sizeof(c->session));
--lp->client_count;
}
+
+/*
+ * Get a list of clients from a listener.
+ *
+ * Returns the number of clients on success,
+ * on failure this function returns a less than
+ * zero value.
+ *
+ * @lp: Listener.
+ * @res: An array of clients to be set.
+ */
+int
+listener_clients(struct ostp_listener *lp, struct ostp_client **res)
+{
+ if (lp->client_count == 0 || lp->client_count > MAX_CLIENTS) {
+ return -1;
+ }
+
+ for (int i = 0; i < lp->client_count + 1; ++i) {
+ res[i] = &lp->clients[i];
+ }
+
+ return lp->client_count;
+}