async_shutdown.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. Copyright (c) 2012 Martin Sustrik All rights reserved.
  3. Copyright (c) 2015 Jack R. Dunaway. All rights reserved.
  4. Copyright 2016 Franklin "Snaipe" Mathieu <franklinmathieu@gmail.com>
  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 "../src/pubsub.h"
  24. #include "../src/pipeline.h"
  25. #include "../src/tcp.h"
  26. #include "testutil.h"
  27. #include "../src/utils/attr.h"
  28. #include "../src/utils/thread.c"
  29. #include "../src/utils/atomic.c"
  30. /* Test condition of closing sockets that are blocking in another thread. */
  31. #define TEST_LOOPS 10
  32. struct nn_atomic active;
  33. static void routine (NN_UNUSED void *arg)
  34. {
  35. int s;
  36. int rc;
  37. int msg;
  38. nn_assert (arg);
  39. s = *((int *) arg);
  40. /* We don't expect to actually receive a message here;
  41. therefore, the datatype of 'msg' is irrelevant. */
  42. rc = nn_recv (s, &msg, sizeof(msg), 0);
  43. errno_assert (rc == -1 && nn_errno () == EBADF);
  44. }
  45. int main (int argc, const char *argv[])
  46. {
  47. int sb;
  48. int i;
  49. struct nn_thread thread;
  50. char socket_address[128];
  51. test_addr_from(socket_address, "tcp", "127.0.0.1",
  52. get_test_port(argc, argv));
  53. for (i = 0; i != TEST_LOOPS; ++i) {
  54. sb = test_socket (AF_SP, NN_PULL);
  55. test_bind (sb, socket_address);
  56. nn_sleep (100);
  57. nn_thread_init (&thread, routine, &sb);
  58. nn_sleep (100);
  59. test_close (sb);
  60. nn_thread_term (&thread);
  61. }
  62. return 0;
  63. }