Tristan Matthews | 0a329cc | 2013-07-17 13:20:14 -0400 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
| 3 | * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) |
| 4 | * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | #ifndef __PJSIP_TRANSPORT_TCP_H__ |
| 21 | #define __PJSIP_TRANSPORT_TCP_H__ |
| 22 | |
| 23 | /** |
| 24 | * @file sip_transport_tcp.h |
| 25 | * @brief SIP TCP Transport. |
| 26 | */ |
| 27 | |
| 28 | #include <pjsip/sip_transport.h> |
| 29 | #include <pj/sock_qos.h> |
| 30 | |
| 31 | |
| 32 | /* Only declare the API if PJ_HAS_TCP is true */ |
| 33 | #if defined(PJ_HAS_TCP) && PJ_HAS_TCP!=0 |
| 34 | |
| 35 | |
| 36 | PJ_BEGIN_DECL |
| 37 | |
| 38 | /** |
| 39 | * @defgroup PJSIP_TRANSPORT_TCP TCP Transport |
| 40 | * @ingroup PJSIP_TRANSPORT |
| 41 | * @brief API to create and register TCP transport. |
| 42 | * @{ |
| 43 | * The functions below are used to create TCP transport and register |
| 44 | * the transport to the framework. |
| 45 | */ |
| 46 | |
| 47 | /** |
| 48 | * Settings to be specified when creating the TCP transport. Application |
| 49 | * should initialize this structure with its default values by calling |
| 50 | * pjsip_tcp_transport_cfg_default(). |
| 51 | */ |
| 52 | typedef struct pjsip_tcp_transport_cfg |
| 53 | { |
| 54 | /** |
| 55 | * Address family to use. Valid values are pj_AF_INET() and |
| 56 | * pj_AF_INET6(). Default is pj_AF_INET(). |
| 57 | */ |
| 58 | int af; |
| 59 | |
| 60 | /** |
| 61 | * Optional address to bind the socket to. Default is to bind to |
| 62 | * PJ_INADDR_ANY and to any available port. |
| 63 | */ |
| 64 | pj_sockaddr bind_addr; |
| 65 | |
| 66 | /** |
| 67 | * Should SO_REUSEADDR be used for the listener socket. |
| 68 | * Default value is PJSIP_TCP_TRANSPORT_REUSEADDR. |
| 69 | */ |
| 70 | pj_bool_t reuse_addr; |
| 71 | |
| 72 | /** |
| 73 | * Optional published address, which is the address to be |
| 74 | * advertised as the address of this SIP transport. |
| 75 | * By default the bound address will be used as the published address. |
| 76 | */ |
| 77 | pjsip_host_port addr_name; |
| 78 | |
| 79 | /** |
| 80 | * Number of simultaneous asynchronous accept() operations to be |
| 81 | * supported. It is recommended that the number here corresponds to |
| 82 | * the number of processors in the system (or the number of SIP |
| 83 | * worker threads). |
| 84 | * |
| 85 | * Default: 1 |
| 86 | */ |
| 87 | unsigned async_cnt; |
| 88 | |
| 89 | /** |
| 90 | * QoS traffic type to be set on this transport. When application wants |
| 91 | * to apply QoS tagging to the transport, it's preferable to set this |
| 92 | * field rather than \a qos_param fields since this is more portable. |
| 93 | * |
| 94 | * Default is QoS not set. |
| 95 | */ |
| 96 | pj_qos_type qos_type; |
| 97 | |
| 98 | /** |
| 99 | * Set the low level QoS parameters to the transport. This is a lower |
| 100 | * level operation than setting the \a qos_type field and may not be |
| 101 | * supported on all platforms. |
| 102 | * |
| 103 | * Default is QoS not set. |
| 104 | */ |
| 105 | pj_qos_params qos_params; |
| 106 | |
| 107 | } pjsip_tcp_transport_cfg; |
| 108 | |
| 109 | |
| 110 | /** |
| 111 | * Initialize pjsip_tcp_transport_cfg structure with default values for |
| 112 | * the specifed address family. |
| 113 | * |
| 114 | * @param cfg The structure to initialize. |
| 115 | * @param af Address family to be used. |
| 116 | */ |
| 117 | PJ_DECL(void) pjsip_tcp_transport_cfg_default(pjsip_tcp_transport_cfg *cfg, |
| 118 | int af); |
| 119 | |
| 120 | |
| 121 | /** |
| 122 | * Register support for SIP TCP transport by creating TCP listener on |
| 123 | * the specified address and port. This function will create an |
| 124 | * instance of SIP TCP transport factory and register it to the |
| 125 | * transport manager. |
| 126 | * |
| 127 | * @param endpt The SIP endpoint. |
| 128 | * @param local Optional local address to bind, or specify the |
| 129 | * address to bind the server socket to. Both IP |
| 130 | * interface address and port fields are optional. |
| 131 | * If IP interface address is not specified, socket |
| 132 | * will be bound to PJ_INADDR_ANY. If port is not |
| 133 | * specified, socket will be bound to any port |
| 134 | * selected by the operating system. |
| 135 | * @param async_cnt Number of simultaneous asynchronous accept() |
| 136 | * operations to be supported. It is recommended that |
| 137 | * the number here corresponds to the number of |
| 138 | * processors in the system (or the number of SIP |
| 139 | * worker threads). |
| 140 | * @param p_factory Optional pointer to receive the instance of the |
| 141 | * SIP TCP transport factory just created. |
| 142 | * |
| 143 | * @return PJ_SUCCESS when the transport has been successfully |
| 144 | * started and registered to transport manager, or |
| 145 | * the appropriate error code. |
| 146 | */ |
| 147 | PJ_DECL(pj_status_t) pjsip_tcp_transport_start(pjsip_endpoint *endpt, |
| 148 | const pj_sockaddr_in *local, |
| 149 | unsigned async_cnt, |
| 150 | pjsip_tpfactory **p_factory); |
| 151 | |
| 152 | |
| 153 | |
| 154 | /** |
| 155 | * A newer variant of #pjsip_tcp_transport_start(), which allows specifying |
| 156 | * the published/public address of the TCP transport. |
| 157 | * |
| 158 | * @param endpt The SIP endpoint. |
| 159 | * @param local Optional local address to bind, or specify the |
| 160 | * address to bind the server socket to. Both IP |
| 161 | * interface address and port fields are optional. |
| 162 | * If IP interface address is not specified, socket |
| 163 | * will be bound to PJ_INADDR_ANY. If port is not |
| 164 | * specified, socket will be bound to any port |
| 165 | * selected by the operating system. |
| 166 | * @param a_name Optional published address, which is the address to be |
| 167 | * advertised as the address of this SIP transport. |
| 168 | * If this argument is NULL, then the bound address |
| 169 | * will be used as the published address. |
| 170 | * @param async_cnt Number of simultaneous asynchronous accept() |
| 171 | * operations to be supported. It is recommended that |
| 172 | * the number here corresponds to the number of |
| 173 | * processors in the system (or the number of SIP |
| 174 | * worker threads). |
| 175 | * @param p_factory Optional pointer to receive the instance of the |
| 176 | * SIP TCP transport factory just created. |
| 177 | * |
| 178 | * @return PJ_SUCCESS when the transport has been successfully |
| 179 | * started and registered to transport manager, or |
| 180 | * the appropriate error code. |
| 181 | */ |
| 182 | PJ_DECL(pj_status_t) pjsip_tcp_transport_start2(pjsip_endpoint *endpt, |
| 183 | const pj_sockaddr_in *local, |
| 184 | const pjsip_host_port *a_name, |
| 185 | unsigned async_cnt, |
| 186 | pjsip_tpfactory **p_factory); |
| 187 | |
| 188 | /** |
| 189 | * Another variant of #pjsip_tcp_transport_start(). |
| 190 | * |
| 191 | * @param endpt The SIP endpoint. |
| 192 | * @param cfg TCP transport settings. Application should initialize |
| 193 | * this setting with #pjsip_tcp_transport_cfg_default(). |
| 194 | * @param p_factory Optional pointer to receive the instance of the |
| 195 | * SIP TCP transport factory just created. |
| 196 | * |
| 197 | * @return PJ_SUCCESS when the transport has been successfully |
| 198 | * started and registered to transport manager, or |
| 199 | * the appropriate error code. |
| 200 | */ |
| 201 | PJ_DECL(pj_status_t) pjsip_tcp_transport_start3( |
| 202 | pjsip_endpoint *endpt, |
| 203 | const pjsip_tcp_transport_cfg *cfg, |
| 204 | pjsip_tpfactory **p_factory |
| 205 | ); |
| 206 | |
| 207 | |
| 208 | PJ_END_DECL |
| 209 | |
| 210 | /** |
| 211 | * @} |
| 212 | */ |
| 213 | |
| 214 | #endif /* PJ_HAS_TCP */ |
| 215 | |
| 216 | #endif /* __PJSIP_TRANSPORT_TCP_H__ */ |