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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
//
// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
// file was obtained (LICENSE.txt). A copy of the license may also be
// found online at https://opensource.org/licenses/MIT.
//
#include "compat/nanomsg/nn.h"
#include "convey.h"
#include "nng.h"
#include "trantest.h"
#include "protocol/pubsub0/sub.h"
#include "protocol/pair1/pair.h"
#include "supplemental/util/platform.h"
#include "stubs.h"
#include <string.h>
#define SECONDS(x) ((x) *1000)
TestMain("Buffer Options", {
atexit(nng_fini);
Convey("We are able to open a PAIR socket", {
nng_socket s1;
So(nng_pair_open(&s1) == 0);
Reset({ nng_close(s1); });
Convey("Set/Get Recv Buf Option", {
int cnt;
So(nng_setopt_int(s1, NNG_OPT_RECVBUF, 10) == 0);
So(nng_getopt_int(s1, NNG_OPT_RECVBUF, &cnt) == 0);
So(cnt == 10);
So(nng_setopt_size(s1, NNG_OPT_RECVBUF, 42) ==
NNG_EBADTYPE);
});
Convey("Set/Get Send Buf Option", {
int cnt;
So(nng_setopt_int(s1, NNG_OPT_SENDBUF, 10) == 0);
So(nng_getopt_int(s1, NNG_OPT_SENDBUF, &cnt) == 0);
So(cnt == 10);
So(nng_setopt_size(s1, NNG_OPT_SENDBUF, 42) ==
NNG_EBADTYPE);
});
// NOTE: We are going to use the compat mode, but
// this assumes that the socket is the same between compat
// and current mode. This is true, but normal applications
// MUST NOT assume this. We only do so for testing.
Convey("Legacy Recv Buf Option", {
int cnt;
int os = (int) s1.id;
size_t sz = sizeof(cnt);
So(nng_setopt_int(s1, NNG_OPT_RECVBUF, 10) == 0);
So(nn_getsockopt(
os, NN_SOL_SOCKET, NN_RCVBUF, &cnt, &sz) == 0);
So(cnt == 10240);
cnt = 1;
So(nn_setsockopt(
os, NN_SOL_SOCKET, NN_RCVBUF, &cnt, sz) == 0);
So(nn_getsockopt(
os, NN_SOL_SOCKET, NN_RCVBUF, &cnt, &sz) == 0);
So(cnt == 1024); // round up!
So(nng_getopt_int(s1, NNG_OPT_RECVBUF, &cnt) == 0);
So(cnt == 1);
So(nn_setsockopt(
os, NN_SOL_SOCKET, NN_RCVBUF, &cnt, 100) == -1);
So(nn_errno() == EINVAL);
});
Convey("Legacy Send Buf Option", {
int cnt;
int os = (int) s1.id;
size_t sz = sizeof(cnt);
So(nng_setopt_int(s1, NNG_OPT_SENDBUF, 10) == 0);
So(nn_getsockopt(
os, NN_SOL_SOCKET, NN_SNDBUF, &cnt, &sz) == 0);
So(cnt == 10240);
cnt = 1;
So(nn_setsockopt(
os, NN_SOL_SOCKET, NN_SNDBUF, &cnt, sz) == 0);
So(nn_getsockopt(
os, NN_SOL_SOCKET, NN_SNDBUF, &cnt, &sz) == 0);
So(cnt == 1024); // round up!
So(nng_getopt_int(s1, NNG_OPT_SENDBUF, &cnt) == 0);
So(cnt == 1);
So(nn_setsockopt(
os, NN_SOL_SOCKET, NN_SNDBUF, &cnt, 100) == -1);
So(nn_errno() == EINVAL);
});
});
})
|