1 /*
2 * Copyright (C) Igor Sysoev
3 * Copyright (C) NGINX, Inc.
4 */
5
6 #include <nxt_main.h>
7 #include <nxt_socket_msg.h>
8
9
10 ssize_t
nxt_sendmsg(nxt_socket_t s,nxt_iobuf_t * iob,nxt_uint_t niob,const nxt_send_oob_t * oob)11 nxt_sendmsg(nxt_socket_t s, nxt_iobuf_t *iob, nxt_uint_t niob,
12 const nxt_send_oob_t *oob)
13 {
14 struct msghdr msg;
15
16 msg.msg_name = NULL;
17 msg.msg_namelen = 0;
18 msg.msg_iov = iob;
19 msg.msg_iovlen = niob;
20 /* Flags are cleared just to suppress valgrind warning. */
21 msg.msg_flags = 0;
22
23 if (oob != NULL && oob->size != 0) {
24 msg.msg_control = (void *) oob->buf;
25 msg.msg_controllen = oob->size;
26
27 } else {
28 msg.msg_control = NULL;
29 msg.msg_controllen = 0;
30 }
31
32 return sendmsg(s, &msg, 0);
33 }
34
35
36 ssize_t
nxt_recvmsg(nxt_socket_t s,nxt_iobuf_t * iob,nxt_uint_t niob,nxt_recv_oob_t * oob)37 nxt_recvmsg(nxt_socket_t s, nxt_iobuf_t *iob, nxt_uint_t niob,
38 nxt_recv_oob_t *oob)
39 {
40 ssize_t n;
41 struct msghdr msg;
42
43 msg.msg_name = NULL;
44 msg.msg_namelen = 0;
45 msg.msg_iov = iob;
46 msg.msg_iovlen = niob;
47 msg.msg_control = oob->buf;
48 msg.msg_controllen = sizeof(oob->buf);
49
50 n = recvmsg(s, &msg, 0);
51
52 if (nxt_fast_path(n != -1)) {
53 oob->size = msg.msg_controllen;
54 }
55
56 return n;
57 }
58