tevent: add tevent_common_fd_str() helper
authorStefan Metzmacher <metze@samba.org>
Fri, 11 Nov 2022 21:25:34 +0000 (22:25 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 19 Jul 2023 08:02:33 +0000 (08:02 +0000)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
lib/tevent/tevent_fd.c
lib/tevent/tevent_internal.h

index 0e55cf1871dc6a15fd5a2739c5443185ff93de89..ca1330651f5cb2160d58273799444ed31508db2a 100644 (file)
 #include "tevent_internal.h"
 #include "tevent_util.h"
 
+_PRIVATE_
+const char *tevent_common_fd_str(struct tevent_common_fd_buf *buf,
+                                const char *description,
+                                const struct tevent_fd *fde)
+{
+       snprintf(buf->buf, sizeof(buf->buf),
+                "%s[fde=%p,"
+                "fd=%d,flags=0x%x(%s%s),%s]",
+                description, fde, fde->fd,
+                fde->flags,
+                (fde->flags & TEVENT_FD_READ) ? "R" : "",
+                (fde->flags & TEVENT_FD_WRITE) ? "W" : "",
+                fde->handler_name);
+       return buf->buf;
+}
+
 int tevent_common_fd_destructor(struct tevent_fd *fde)
 {
        if (fde->destroyed) {
index 7bb9bd67de9253fd5f27b4120fbb9e2192dcf81a..e3321deab793a70b1c69ef5cb8392e8056476db1 100644 (file)
@@ -419,6 +419,14 @@ int tevent_common_context_destructor(struct tevent_context *ev);
 int tevent_common_loop_wait(struct tevent_context *ev,
                            const char *location);
 
+struct tevent_common_fd_buf {
+       char buf[128];
+};
+
+const char *tevent_common_fd_str(struct tevent_common_fd_buf *buf,
+                                const char *description,
+                                const struct tevent_fd *fde);
+
 int tevent_common_fd_destructor(struct tevent_fd *fde);
 struct tevent_fd *tevent_common_add_fd(struct tevent_context *ev,
                                       TALLOC_CTX *mem_ctx,