1 /*
2     Copyright (c) 2012 250bpm s.r.o.
3     Copyright (c) 2012 Other contributors as noted in the AUTHORS file
4 
5     This file is part of Crossroads I/O project.
6 
7     Crossroads I/O is free software; you can redistribute it and/or modify it
8     under the terms of the GNU Lesser General Public License as published by
9     the Free Software Foundation; either version 3 of the License, or
10     (at your option) any later version.
11 
12     Crossroads is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU Lesser General Public License for more details.
16 
17     You should have received a copy of the GNU Lesser General Public License
18     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include "testutil.hpp"
22 
XS_TEST_MAIN()23 int XS_TEST_MAIN ()
24 {
25     fprintf (stderr, "max_sockets test running...\n");
26 
27     //  Create context and set MAX_SOCKETS to 1.
28     void *ctx = xs_init ();
29     assert (ctx);
30     int max_sockets = 1;
31     int rc = xs_setctxopt (ctx, XS_MAX_SOCKETS, &max_sockets,
32         sizeof (max_sockets));
33     assert (rc == 0);
34 
35     //  First socket should be created OK.
36     void *s1 = xs_socket (ctx, XS_PUSH);
37     assert (s1);
38 
39     //  Creation of second socket should fail.
40     void *s2 = xs_socket (ctx, XS_PUSH);
41     assert (!s2 && errno == EMFILE);
42 
43     //  Clean up.
44     rc = xs_close (s1);
45     assert (rc == 0);
46     rc = xs_term (ctx);
47     assert (rc == 0);
48 
49     return 0;
50 }
51 
52