Changeset 742 for pjproject/trunk/pjsip/src/pjsip/sip_transport_tcp.c
- Timestamp:
- Sep 26, 2006 1:21:02 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsip/sip_transport_tcp.c
r721 r742 70 70 { 71 71 pjsip_tpfactory factory; 72 char obj_name[PJ_MAX_OBJ_NAME];73 72 pj_bool_t is_registered; 74 73 pjsip_endpoint *endpt; … … 185 184 * TCP listener. 186 185 */ 187 PJ_DEF(pj_status_t) pjsip_tcp_transport_start (pjsip_endpoint *endpt,186 PJ_DEF(pj_status_t) pjsip_tcp_transport_start2(pjsip_endpoint *endpt, 188 187 const pj_sockaddr_in *local, 188 const pjsip_host_port *a_name, 189 189 unsigned async_cnt, 190 190 pjsip_tpfactory **p_factory) … … 201 201 PJ_ASSERT_RETURN(endpt && async_cnt, PJ_EINVAL); 202 202 203 /* Verify that address given in a_name (if any) is valid */ 204 if (a_name && a_name->host.slen) { 205 pj_sockaddr_in tmp; 206 207 status = pj_sockaddr_in_init(&tmp, &a_name->host, 208 (pj_uint16_t)a_name->port); 209 if (status != PJ_SUCCESS || tmp.sin_addr.s_addr == PJ_INADDR_ANY || 210 tmp.sin_addr.s_addr == PJ_INADDR_NONE) 211 { 212 /* Invalid address */ 213 return PJ_EINVAL; 214 } 215 } 203 216 204 217 pool = pjsip_endpt_create_pool(endpt, "tcplis", POOL_LIS_INIT, … … 215 228 listener->sock = PJ_INVALID_SOCKET; 216 229 217 pj_ansi_strcpy(listener-> obj_name, "tcp");230 pj_ansi_strcpy(listener->factory.obj_name, "tcplis"); 218 231 219 232 status = pj_lock_create_recursive_mutex(pool, "tcplis", … … 246 259 goto on_error; 247 260 248 /* If the address returns 0.0.0.0, use the first interface address249 * as the transport'saddress.261 /* If published host/IP is specified, then use that address as the 262 * listener advertised address. 250 263 */ 251 if (listener_addr->sin_addr.s_addr == 0) { 252 pj_in_addr hostip; 253 254 status = pj_gethostip(&hostip); 255 if (status != PJ_SUCCESS) 256 goto on_error; 257 258 listener_addr->sin_addr = hostip; 259 } 260 261 pj_ansi_snprintf(listener->obj_name, sizeof(listener->obj_name), 262 "tcp:%d", (int)pj_ntohs(listener_addr->sin_port)); 263 264 /* Save the address name */ 265 sockaddr_to_host_port(listener->factory.pool, 266 &listener->factory.addr_name, listener_addr); 264 if (a_name && a_name->host.slen) { 265 /* Copy the address */ 266 listener->factory.addr_name = *a_name; 267 pj_strdup(listener->factory.pool, &listener->factory.addr_name.host, 268 &a_name->host); 269 listener->factory.addr_name.port = a_name->port; 270 271 } else { 272 /* No published address is given, use the bound address */ 273 274 /* If the address returns 0.0.0.0, use the default 275 * interface address as the transport's address. 276 */ 277 if (listener_addr->sin_addr.s_addr == 0) { 278 pj_in_addr hostip; 279 280 status = pj_gethostip(&hostip); 281 if (status != PJ_SUCCESS) 282 goto on_error; 283 284 listener_addr->sin_addr = hostip; 285 } 286 287 /* Save the address name */ 288 sockaddr_to_host_port(listener->factory.pool, 289 &listener->factory.addr_name, listener_addr); 290 } 291 292 /* If port is zero, get the bound port */ 293 if (listener->factory.addr_name.port == 0) { 294 listener->factory.addr_name.port = pj_ntohs(listener_addr->sin_port); 295 } 296 297 pj_ansi_snprintf(listener->factory.obj_name, 298 sizeof(listener->factory.obj_name), 299 "tcplis:%d", listener->factory.addr_name.port); 300 267 301 268 302 /* Start listening to the address */ … … 320 354 } 321 355 322 PJ_LOG(4,(listener->obj_name, 323 "SIP TCP listener ready for incoming connections at %s:%d", 324 pj_inet_ntoa(listener_addr->sin_addr), 325 (int)pj_ntohs(listener_addr->sin_port))); 356 PJ_LOG(4,(listener->factory.obj_name, 357 "SIP TCP listener ready for incoming connections at %.*s:%d", 358 (int)listener->factory.addr_name.host.slen, 359 listener->factory.addr_name.host.ptr, 360 listener->factory.addr_name.port)); 326 361 327 362 /* Return the pointer to user */ … … 333 368 lis_destroy(&listener->factory); 334 369 return status; 370 } 371 372 373 /* 374 * This is the public API to create, initialize, register, and start the 375 * TCP listener. 376 */ 377 PJ_DEF(pj_status_t) pjsip_tcp_transport_start( pjsip_endpoint *endpt, 378 const pj_sockaddr_in *local, 379 unsigned async_cnt, 380 pjsip_tpfactory **p_factory) 381 { 382 return pjsip_tcp_transport_start2(endpt, local, NULL, async_cnt, p_factory); 335 383 } 336 384 … … 374 422 pj_pool_t *pool = listener->factory.pool; 375 423 376 PJ_LOG(4,(listener-> obj_name, "SIP TCP listener destroyed"));424 PJ_LOG(4,(listener->factory.obj_name, "SIP TCP listener destroyed")); 377 425 378 426 listener->factory.pool = NULL; … … 856 904 * Error in accept(). 857 905 */ 858 tcp_perror(listener->obj_name, "Error in accept()", status); 906 tcp_perror(listener->factory.obj_name, "Error in accept()", 907 status); 859 908 860 909 /* … … 866 915 ++err_cnt; 867 916 if (err_cnt >= 10) { 868 PJ_LOG(1, (listener-> obj_name,917 PJ_LOG(1, (listener->factory.obj_name, 869 918 "Too many errors, listener stopping")); 870 919 } … … 883 932 } 884 933 885 PJ_LOG(4,(listener-> obj_name,934 PJ_LOG(4,(listener->factory.obj_name, 886 935 "TCP listener %.*s:%d: got incoming TCP connection " 887 936 "from %s:%d, sock=%d",
Note: See TracChangeset
for help on using the changeset viewer.