summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2024-11-21 12:54:11 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2024-11-21 12:54:11 +0000
commit2c347f26a71390d97a0b58ae937f8601a38166e4 (patch)
tree29f3f1d66d3ca2fcf2a68d512fa43c59ab438aab
parent9377718f6b7573c4639dea9f884645040677fa1f (diff)
Introduce imsgbuf_queuelen() which returns the number
of messages ready for transmission. Returns 0 if nothing is pending. OK tb@
-rw-r--r--lib/libutil/Symbols.map1
-rw-r--r--lib/libutil/imsg.c8
-rw-r--r--lib/libutil/imsg.h3
-rw-r--r--lib/libutil/imsg_init.39
4 files changed, 18 insertions, 3 deletions
diff --git a/lib/libutil/Symbols.map b/lib/libutil/Symbols.map
index 0f82b56c190..4d459dbc60d 100644
--- a/lib/libutil/Symbols.map
+++ b/lib/libutil/Symbols.map
@@ -84,6 +84,7 @@
imsgbuf_clear;
imsgbuf_flush;
imsgbuf_init;
+ imsgbuf_queuelen;
imsgbuf_read;
imsgbuf_write;
isduid;
diff --git a/lib/libutil/imsg.c b/lib/libutil/imsg.c
index 80b20f7d1b7..fbe001e4341 100644
--- a/lib/libutil/imsg.c
+++ b/lib/libutil/imsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.c,v 1.29 2024/11/21 12:53:11 claudio Exp $ */
+/* $OpenBSD: imsg.c,v 1.30 2024/11/21 12:54:10 claudio Exp $ */
/*
* Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org>
@@ -151,6 +151,12 @@ imsgbuf_clear(struct imsgbuf *imsgbuf)
close(fd);
}
+uint32_t
+imsgbuf_queuelen(struct imsgbuf *imsgbuf)
+{
+ return msgbuf_queuelen(&imsgbuf->w);
+}
+
ssize_t
imsg_get(struct imsgbuf *imsgbuf, struct imsg *imsg)
{
diff --git a/lib/libutil/imsg.h b/lib/libutil/imsg.h
index 55db4be45cd..6e9ec6eaf47 100644
--- a/lib/libutil/imsg.h
+++ b/lib/libutil/imsg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.h,v 1.12 2024/11/21 12:53:11 claudio Exp $ */
+/* $OpenBSD: imsg.h,v 1.13 2024/11/21 12:54:10 claudio Exp $ */
/*
* Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org>
@@ -136,6 +136,7 @@ ssize_t imsgbuf_read(struct imsgbuf *);
int imsgbuf_write(struct imsgbuf *);
int imsgbuf_flush(struct imsgbuf *);
void imsgbuf_clear(struct imsgbuf *);
+uint32_t imsgbuf_queuelen(struct imsgbuf *);
ssize_t imsg_get(struct imsgbuf *, struct imsg *);
int imsg_get_ibuf(struct imsg *, struct ibuf *);
int imsg_get_data(struct imsg *, void *, size_t);
diff --git a/lib/libutil/imsg_init.3 b/lib/libutil/imsg_init.3
index eed5b015c42..59a35e9941b 100644
--- a/lib/libutil/imsg_init.3
+++ b/lib/libutil/imsg_init.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: imsg_init.3,v 1.37 2024/11/21 12:53:11 claudio Exp $
+.\" $OpenBSD: imsg_init.3,v 1.38 2024/11/21 12:54:10 claudio Exp $
.\"
.\" Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org>
.\" Copyright (c) 2010 Nicholas Marriott <nicm@openbsd.org>
@@ -39,6 +39,7 @@
.Nm imsgbuf_clear ,
.Nm imsgbuf_flush ,
.Nm imsgbuf_init ,
+.Nm imsgbuf_queuelen ,
.Nm imsgbuf_read ,
.Nm imsgbuf_write
.Nd IPC messaging functions
@@ -84,6 +85,8 @@
.Fn imsgbuf_flush "struct imsgbuf *imsgbuf"
.Ft void
.Fn imsgbuf_init "struct imsgbuf *imsgbuf" "int fd"
+.Ft uint32_t
+.Fn imsgbuf_queuelen "struct imsgbuf *imsgbuf"
.Ft ssize_t
.Fn imsgbuf_read "struct imsgbuf *imsgbuf"
.Ft int
@@ -159,6 +162,10 @@ is set to indicate the error.
should not be called on non-blocking sockets since it will busy loop if the
socket is not available.
.Pp
+.Fn imsgbuf_queuelen
+returns the number of messages ready to be sent.
+This function returns 0 if no messages are pending for transmission.
+.Pp
.Fn imsg_create ,
.Fn imsg_add
and