tcp_options.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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_ASYNC
  29. #define TCP_ASYNC /* enabled async mode */
  30. #endif
  31. #if !defined(NO_TCP_CONNECT_WAIT) && defined(TCP_ASYNC)
  32. #define TCP_CONNECT_WAIT /* enable pending connects support */
  33. #endif
  34. #if defined(TCP_CONNECT_WAIT) && !defined(TCP_ASYNC)
  35. /* check for impossible configuration: TCP_CONNECT_WAIT w/o TCP_ASYNC */
  36. #warning "disabling TCP_CONNECT_WAIT because TCP_ASYNC 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 cfg_group_tcp{
  92. /* ser tcp options, low level */
  93. int connect_timeout_s; /* in s */
  94. int send_timeout; /* in ticks (s fixed to ticks) */
  95. int con_lifetime; /* in ticks (s fixed to ticks) */
  96. int max_connections; /* max tcp connections (includes tls connections) */
  97. int max_tls_connections; /* max tls connections */
  98. int no_connect; /* do not open any new tcp connection (but accept them) */
  99. int fd_cache; /* on /off */
  100. /* tcp async options */
  101. int async; /* on / off */
  102. int tcp_connect_wait; /* on / off, depends on async */
  103. unsigned int tcpconn_wq_max; /* maximum queue len per connection */
  104. unsigned int tcp_wq_max; /* maximum overall queued bytes */
  105. /* tcp socket options */
  106. int defer_accept; /* on / off */
  107. int delayed_ack; /* delay ack on connect */
  108. int syncnt; /* numbers of SYNs retrs. before giving up connecting */
  109. int linger2; /* lifetime of orphaned FIN_WAIT2 state sockets */
  110. int keepalive; /* on /off */
  111. int keepidle; /* idle time (s) before tcp starts sending keepalives */
  112. int keepintvl; /* interval between keep alives */
  113. int keepcnt; /* maximum no. of keepalives before giving up */
  114. /* other options */
  115. int crlf_ping; /* on/off - reply to double CRLF keepalives */
  116. int accept_aliases;
  117. int alias_flags;
  118. int new_conn_alias_flags;
  119. int accept_no_cl; /* on/off - accept messages without content-length */
  120. /* internal, "fixed" vars */
  121. unsigned int rd_buf_size; /* read buffer size (should be > max. datagram)*/
  122. unsigned int wq_blk_size; /* async write block size (debugging use) */
  123. };
  124. extern struct cfg_group_tcp tcp_default_cfg;
  125. /* tcp config handle*/
  126. extern void* tcp_cfg;
  127. void init_tcp_options(void);
  128. void tcp_options_check(void);
  129. int tcp_register_cfg(void);
  130. void tcp_options_get(struct cfg_group_tcp* t);
  131. #ifdef USE_TCP
  132. int tcp_set_clone_rcvbuf(int v);
  133. #endif /* USE_TCP */
  134. #endif /* tcp_options_h */