blob: 3b35ab2923b88fc1f9de84a54b1141725a7ac6fd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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;
}
|