bug328.c 2.0 KB

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