1 /*
2     Copyright (c) 2012 Martin Sustrik  All rights reserved.
3     Copyright 2016 Franklin "Snaipe" Mathieu <franklinmathieu@gmail.com>
4     Copyright 2016 Garrett D'Amore <garrett@damore.org>
5 
6     Permission is hereby granted, free of charge, to any person obtaining a copy
7     of this software and associated documentation files (the "Software"),
8     to deal in the Software without restriction, including without limitation
9     the rights to use, copy, modify, merge, publish, distribute, sublicense,
10     and/or sell copies of the Software, and to permit persons to whom
11     the Software is furnished to do so, subject to the following conditions:
12 
13     The above copyright notice and this permission notice shall be included
14     in all copies or substantial portions of the Software.
15 
16     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19     THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22     IN THE SOFTWARE.
23 */
24 
25 #include "../src/nn.h"
26 #include "../src/pair.h"
27 
28 #include "testutil.h"
29 
main(int argc,const char * argv[])30 int main (int argc, const char *argv[])
31 {
32     int sb;
33     int sc;
34     char socket_address[128];
35 
36     test_addr_from(socket_address, "tcp", "127.0.0.1",
37             get_test_port(argc, argv));
38 
39     sb = test_socket (AF_SP, NN_PAIR);
40     test_bind (sb, socket_address);
41     sc = test_socket (AF_SP, NN_PAIR);
42     test_connect (sc, socket_address);
43 
44     nn_sleep(100);
45     test_send (sc, "ABC");
46     test_recv (sb, "ABC");
47     nn_assert (nn_get_statistic (sc, NN_STAT_CURRENT_CONNECTIONS) == 1);
48     test_close (sb);
49     nn_sleep(300);
50     nn_assert (nn_get_statistic (sc, NN_STAT_CURRENT_CONNECTIONS) == 0);
51     test_close (sc);
52 
53     return 0;
54 }
55 
56