0001-test-ptts-Set-recv-buffer-size-too-max-to-receive-as.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. From 4e4c8c7a1cca2125e2bf2a67cbab0bdbd78fdb86 Mon Sep 17 00:00:00 2001
  2. From: He Zhe <zhe.he@windriver.com>
  3. Date: Tue, 30 Jul 2019 13:24:22 +0800
  4. Subject: [PATCH] ptts: Set recv buffer size too max to receive as many
  5. packets as possible
  6. Flooding multicast may make the rcv buffer overrun and is considered
  7. premature messages later and thus cause the following error.
  8. "Ignoring premature msg 16, currently handling 12"
  9. This patch sets SO_RCVBUF the of socket to max int value to receive as many
  10. packets as possible, and give a hint to user when possible overrun occurs. Note
  11. that the value of SO_RCVBUF will be limited up to min(INT_MAX/2,
  12. sysctl_rmem_max) in kernel.
  13. Signed-off-by: He Zhe <zhe.he@windriver.com>
  14. Upstream-Status: Backport
  15. Signed-off-by: Li Zhou <li.zhou@windriver.com>
  16. ---
  17. ptts/tipc_ts_server.c | 18 ++++++++++++++++--
  18. 1 file changed, 16 insertions(+), 2 deletions(-)
  19. diff --git a/ptts/tipc_ts_server.c b/ptts/tipc_ts_server.c
  20. index a286daa..3a2f96f 100644
  21. --- a/ptts/tipc_ts_server.c
  22. +++ b/ptts/tipc_ts_server.c
  23. @@ -641,8 +641,9 @@ void server_mcast
  24. if (rc < 0)
  25. err("multicast message not received");
  26. if (msgno != *(int*) buf) {
  27. - dbg1("Ignoring premature msg %u, currently handling %u\n",
  28. - *(int*)buf, msgno);
  29. + dbg1("Ignoring premature msg %u, currently handling %u\n"
  30. + "You can enlarge /proc/sys/net/core/rmem_max and try again\n",
  31. + *(int*)buf, msgno);
  32. continue;
  33. }
  34. rc = recvfrom(sd[i], buf, expected_szs[numSubTest],
  35. @@ -687,8 +688,21 @@ void server_test_multicast(void)
  36. FD_ZERO(&readfds);
  37. for (i = 0; i < TIPC_MCAST_SOCKETS; i++) {
  38. + int optval = (int)(~0U >> 1);
  39. + socklen_t optlen = sizeof(optval);
  40. + int rc = 0;
  41. +
  42. sd[i] = createSocketTIPC (SOCK_RDM);
  43. FD_SET(sd[i], &readfds);
  44. +
  45. + /*
  46. + * Flooding multicast may make the rcv buffer overrun and considered premature msg later.
  47. + * Set SO_RCVBUF to max int value to receive as many packets as possible.
  48. + * Note that it will be limited up to min(INT_MAX/2, sysctl_rmem_max) in kernel.
  49. + */
  50. + rc = setsockopt(sd[i], SOL_SOCKET, SO_RCVBUF, (const char*)&optval, optlen);
  51. + if(rc != 0)
  52. + printf("Failed to set SO_RCVBUF of %d: %s\n", sd[i], strerror(errno));
  53. }
  54. server_bindMulticast( 0, 99, sd[0]);
  55. --
  56. 2.17.1