tcp_options.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2007 iptelorg GmbH
  5. *
  6. * Permission to use, copy, modify, and distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /*
  19. * tcp options
  20. *
  21. * History:
  22. * --------
  23. * 2007-11-28 created by andrei
  24. */
  25. #ifndef tcp_options_h
  26. #define tcp_options_h
  27. #ifdef USE_TCP
  28. #ifndef NO_TCP_BUF_WRITE
  29. #define TCP_BUF_WRITE /* enabled buffered writing */
  30. #endif
  31. #if !defined(NO_TCP_CONNECT_WAIT) && defined(TCP_BUF_WRITE)
  32. #define TCP_CONNECT_WAIT /* enable pending connects support */
  33. #endif
  34. #if defined(TCP_CONNECT_WAIT) && !defined(TCP_BUF_WRITE)
  35. /* check for impossible configuration: TCP_CONNECT_WAIT w/o TCP_BUF_WRITE */
  36. #warning "disabling TCP_CONNECT_WAIT because TCP_BUF_WRITE is not defined"
  37. #undef TCP_CONNECT_WAIT
  38. #endif
  39. #ifndef NO_TCP_FD_CACHE
  40. #define TCP_FD_CACHE /* enable fd caching */
  41. #endif
  42. /* defer accept */
  43. #ifndef NO_TCP_DEFER_ACCEPT
  44. #ifdef __OS_linux
  45. #define HAVE_TCP_DEFER_ACCEPT
  46. #elif defined __OS_freebsd
  47. #define HAVE_TCP_ACCEPT_FILTER
  48. #endif /* __OS_ */
  49. #endif /* NO_TCP_DEFER_ACCEPT */
  50. /* syn count */
  51. #ifndef NO_TCP_SYNCNT
  52. #ifdef __OS_linux
  53. #define HAVE_TCP_SYNCNT
  54. #endif /* __OS_*/
  55. #endif /* NO_TCP_SYNCNT */
  56. /* tcp linger2 */
  57. #ifndef NO_TCP_LINGER2
  58. #ifdef __OS_linux
  59. #define HAVE_TCP_LINGER2
  60. #endif /* __OS_ */
  61. #endif /* NO_TCP_LINGER2 */
  62. /* keepalive */
  63. #ifndef NO_TCP_KEEPALIVE
  64. #define HAVE_SO_KEEPALIVE
  65. #endif /* NO_TCP_KEEPALIVE */
  66. /* keepintvl */
  67. #ifndef NO_TCP_KEEPINTVL
  68. #ifdef __OS_linux
  69. #define HAVE_TCP_KEEPINTVL
  70. #endif /* __OS_ */
  71. #endif /* NO_TCP_KEEPIDLE */
  72. /* keepidle */
  73. #ifndef NO_TCP_KEEPIDLE
  74. #ifdef __OS_linux
  75. #define HAVE_TCP_KEEPIDLE
  76. #endif /* __OS_*/
  77. #endif /* NO_TCP_KEEPIDLE */
  78. /* keepcnt */
  79. #ifndef NO_TCP_KEEPCNT
  80. #ifdef __OS_linux
  81. #define HAVE_TCP_KEEPCNT
  82. #endif /* __OS_ */
  83. #endif /* NO_TCP_KEEPCNT */
  84. /* delayed ack (quick_ack) */
  85. #ifndef NO_TCP_QUICKACK
  86. #ifdef __OS_linux
  87. #define HAVE_TCP_QUICKACK
  88. #endif /* __OS_ */
  89. #endif /* NO_TCP_QUICKACK */
  90. #endif /* USE_TCP */
  91. struct tcp_cfg_options{
  92. /* ser tcp options */
  93. int fd_cache; /* on /off */
  94. /* tcp buf. write options */
  95. int tcp_buf_write; /* on / off */
  96. int tcp_connect_wait; /* on / off, depends on tcp_buf_write */
  97. unsigned int tcpconn_wq_max; /* maximum queue len per connection */
  98. unsigned int tcp_wq_max; /* maximum overall queued bytes */
  99. unsigned int tcp_wq_timeout; /* timeout for queue writes */
  100. /* tcp socket options */
  101. int defer_accept; /* on / off */
  102. int delayed_ack; /* delay ack on connect */
  103. int syncnt; /* numbers of SYNs retrs. before giving up connecting */
  104. int linger2; /* lifetime of orphaned FIN_WAIT2 state sockets */
  105. int keepalive; /* on /off */
  106. int keepidle; /* idle time (s) before tcp starts sending keepalives */
  107. int keepintvl; /* interval between keep alives */
  108. int keepcnt; /* maximum no. of keepalives before giving up */
  109. int crlf_ping; /* on/off - reply to double CRLF keepalives */
  110. };
  111. extern struct tcp_cfg_options tcp_options;
  112. void init_tcp_options();
  113. void tcp_options_check();
  114. void tcp_options_get(struct tcp_cfg_options* t);
  115. #endif /* tcp_options_h */