summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_socket_msg.c
diff options
context:
space:
mode:
authorAndrei Belov <defan@nginx.com>2021-11-18 17:04:04 +0300
committerAndrei Belov <defan@nginx.com>2021-11-18 17:04:04 +0300
commitb400ccd1aa8eeb6a5de1707e0bb8c3d417fe69b7 (patch)
tree60ff49ffc16ef7cb3aad1beb2d78f051a8794cdf /src/nxt_socket_msg.c
parentfafd44166d9e835e91a4c5668048308ce99a62bd (diff)
parentb77895d1c7d6cd4826ac7427c91baa95b998a912 (diff)
downloadunit-b400ccd1aa8eeb6a5de1707e0bb8c3d417fe69b7.tar.gz
unit-b400ccd1aa8eeb6a5de1707e0bb8c3d417fe69b7.tar.bz2
Merged with the default branch.1.26.0-1
Diffstat (limited to 'src/nxt_socket_msg.c')
-rw-r--r--src/nxt_socket_msg.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/nxt_socket_msg.c b/src/nxt_socket_msg.c
new file mode 100644
index 00000000..3b35ab29
--- /dev/null
+++ b/src/nxt_socket_msg.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) Igor Sysoev
+ * Copyright (C) NGINX, Inc.
+ */
+
+#include <nxt_main.h>
+#include <nxt_socket_msg.h>
+
+
+ssize_t
+nxt_sendmsg(nxt_socket_t s, nxt_iobuf_t *iob, nxt_uint_t niob,
+ const nxt_send_oob_t *oob)
+{
+ struct msghdr msg;
+
+ msg.msg_name = NULL;
+ msg.msg_namelen = 0;
+ msg.msg_iov = iob;
+ msg.msg_iovlen = niob;
+ /* Flags are cleared just to suppress valgrind warning. */
+ msg.msg_flags = 0;
+
+ if (oob != NULL && oob->size != 0) {
+ msg.msg_control = (void *) oob->buf;
+ msg.msg_controllen = oob->size;
+
+ } else {
+ msg.msg_control = NULL;
+ msg.msg_controllen = 0;
+ }
+
+ return sendmsg(s, &msg, 0);
+}
+
+
+ssize_t
+nxt_recvmsg(nxt_socket_t s, nxt_iobuf_t *iob, nxt_uint_t niob,
+ nxt_recv_oob_t *oob)
+{
+ ssize_t n;
+ struct msghdr msg;
+
+ msg.msg_name = NULL;
+ msg.msg_namelen = 0;
+ msg.msg_iov = iob;
+ msg.msg_iovlen = niob;
+ msg.msg_control = oob->buf;
+ msg.msg_controllen = sizeof(oob->buf);
+
+ n = recvmsg(s, &msg, 0);
+
+ if (nxt_fast_path(n != -1)) {
+ oob->size = msg.msg_controllen;
+ }
+
+ return n;
+}