pipeline.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Copyright (c) 2012 Martin Sustrik All rights reserved.
  3. Copyright (c) 2013 GoPivotal, Inc. All rights reserved.
  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. The above copyright notice and this permission notice shall be included
  11. in all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  15. THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  17. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  18. IN THE SOFTWARE.
  19. */
  20. #include "../src/nn.h"
  21. #include "../src/pipeline.h"
  22. #include "testutil.h"
  23. #define SOCKET_ADDRESS "inproc://a"
  24. int main ()
  25. {
  26. int push1;
  27. int push2;
  28. int pull1;
  29. int pull2;
  30. /* Test fan-out. */
  31. push1 = test_socket (AF_SP, NN_PUSH);
  32. test_bind (push1, SOCKET_ADDRESS);
  33. pull1 = test_socket (AF_SP, NN_PULL);
  34. test_connect (pull1, SOCKET_ADDRESS);
  35. pull2 = test_socket (AF_SP, NN_PULL);
  36. test_connect (pull2, SOCKET_ADDRESS);
  37. /* Wait till both connections are established to get messages spread
  38. evenly between the two pull sockets. */
  39. nn_sleep (10);
  40. test_send (push1, "ABC");
  41. test_send (push1, "DEF");
  42. test_recv (pull1, "ABC");
  43. test_recv (pull2, "DEF");
  44. test_close (push1);
  45. test_close (pull1);
  46. test_close (pull2);
  47. /* Test fan-in. */
  48. pull1 = test_socket (AF_SP, NN_PULL);
  49. test_bind (pull1, SOCKET_ADDRESS);
  50. push1 = test_socket (AF_SP, NN_PUSH);
  51. test_connect (push1, SOCKET_ADDRESS);
  52. push2 = test_socket (AF_SP, NN_PUSH);
  53. test_connect (push2, SOCKET_ADDRESS);
  54. test_send (push1, "ABC");
  55. test_send (push2, "DEF");
  56. test_recv (pull1, "ABC");
  57. test_recv (pull1, "DEF");
  58. test_close (pull1);
  59. test_close (push1);
  60. test_close (push2);
  61. return 0;
  62. }