tcputil.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (C) 2001-2004 by egnite Software GmbH
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. *
  34. */
  35. /*!
  36. * \file net/tcputil.c
  37. * \brief TCP utility functions.
  38. *
  39. * \verbatim
  40. * $Id: tcputil.c 3686 2011-12-04 14:20:38Z haraldkipp $
  41. * \endverbatim
  42. */
  43. #include <cfg/tcp.h>
  44. #include <netinet/tcputil.h>
  45. #include <sys/timer.h>
  46. #include <stdio.h>
  47. /*!
  48. * \addtogroup xgTCP
  49. */
  50. /*@{*/
  51. /* Limit retransmission timeout to 200ms as lower and 20secs as upper boundary */
  52. #ifndef TCP_RTTO_MIN
  53. #define TCP_RTTO_MIN 200
  54. #endif
  55. #ifndef TCP_RTTO_MAX
  56. #define TCP_RTTO_MAX 20000
  57. #endif
  58. #define min(a,b) ((a>b)?b:a)
  59. #define max(a,b) ((a>b)?a:b)
  60. /*
  61. * Calculate round trip time.
  62. */
  63. void NutTcpCalcRtt(TCPSOCKET * sock)
  64. {
  65. uint16_t delta;
  66. if (sock->so_retran_time == 0)
  67. return;
  68. delta = (uint16_t) NutGetMillis() - (sock->so_retran_time & ~1);
  69. /* According to RFC793 (or STD007), page 41, we use 0.8 for ALPHA and 2.0 for BETA. */
  70. sock->so_rtto = min (TCP_RTTO_MAX, max(TCP_RTTO_MIN, (delta * 4 + sock->so_rtto * 8) / 10));
  71. //@@@printf ("[%04X] new retran timeout: %u, delta: %u\n", (u_short) sock, sock->so_rtto, delta);
  72. }
  73. /*@}*/