1 /*
2     Copyright (c) 2012 Martin Sustrik  All rights reserved.
3 
4     Permission is hereby granted, free of charge, to any person obtaining a copy
5     of this software and associated documentation files (the "Software"),
6     to deal in the Software without restriction, including without limitation
7     the rights to use, copy, modify, merge, publish, distribute, sublicense,
8     and/or sell copies of the Software, and to permit persons to whom
9     the Software is furnished to do so, subject to the following conditions:
10 
11     The above copyright notice and this permission notice shall be included
12     in all copies or substantial portions of the Software.
13 
14     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17     THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20     IN THE SOFTWARE.
21 */
22 
23 #include "../src/nn.h"
24 #include "../src/pair.h"
25 
26 #include "testutil.h"
27 #include "../src/utils/attr.h"
28 #include "../src/utils/thread.c"
29 
30 /*  This test checks whether blocking on send/recv works as expected. */
31 
32 #define SOCKET_ADDRESS "inproc://a"
33 
34 int sc;
35 int sb;
36 
worker(NN_UNUSED void * arg)37 void worker (NN_UNUSED void *arg)
38 {
39     /*  Wait 0.1 sec for the main thread to block. */
40     nn_sleep (100);
41 
42     test_send (sc, "ABC");
43 
44     /*  Wait 0.1 sec for the main thread to process the previous message
45         and block once again. */
46     nn_sleep (100);
47 
48     test_send (sc, "ABC");
49 }
50 
main()51 int main ()
52 {
53     struct nn_thread thread;
54 
55     sb = test_socket (AF_SP, NN_PAIR);
56     test_bind (sb, SOCKET_ADDRESS);
57     sc = test_socket (AF_SP, NN_PAIR);
58     test_connect (sc, SOCKET_ADDRESS);
59 
60     nn_thread_init (&thread, worker, NULL);
61 
62     test_recv (sb, "ABC");
63     test_recv (sb, "ABC");
64 
65     nn_thread_term (&thread);
66 
67     test_close (sc);
68     test_close (sb);
69 
70     return 0;
71 }
72 
73