emfile.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. Copyright (c) 2013 Martin Sustrik All rights reserved.
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"),
  5. to deal in the Software without restriction, including without limitation
  6. the rights to use, copy, modify, merge, publish, distribute, sublicense,
  7. and/or sell copies of the Software, and to permit persons to whom
  8. the Software is furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included
  10. in all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  14. THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  16. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  17. IN THE SOFTWARE.
  18. */
  19. #include "../src/nn.h"
  20. #include "../src/pair.h"
  21. #include "../src/tcp.h"
  22. #include "../src/utils/err.c"
  23. #define MAX_SOCKETS 1000
  24. int main ()
  25. {
  26. int rc;
  27. int i;
  28. int socks [MAX_SOCKETS];
  29. /* First, just create as much SP sockets as possible. */
  30. for (i = 0; i != MAX_SOCKETS; ++i) {
  31. socks [i] = nn_socket (AF_SP, NN_PAIR);
  32. if (socks [i] < 0) {
  33. errno_assert (nn_errno () == EMFILE);
  34. break;
  35. }
  36. }
  37. while (1) {
  38. --i;
  39. if (i == -1)
  40. break;
  41. rc = nn_close (socks [i]);
  42. errno_assert (rc == 0);
  43. }
  44. return 0;
  45. }